KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > internal > DefaultLoginHandler


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.internal;
19
20 import org.apache.beehive.netui.pageflow.handler.LoginHandler;
21 import org.apache.beehive.netui.pageflow.handler.BaseHandler;
22 import org.apache.beehive.netui.pageflow.handler.FlowControllerHandlerContext;
23
24 import javax.servlet.ServletContext JavaDoc;
25 import javax.servlet.ServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28 import javax.security.auth.login.LoginException JavaDoc;
29 import java.io.Serializable JavaDoc;
30 import java.security.Principal JavaDoc;
31
32
33 /**
34  * Implements default J2EE web-tier login handling.
35  */

36 public class DefaultLoginHandler
37         extends DefaultHandler
38         implements LoginHandler
39 {
40     public DefaultLoginHandler( ServletContext JavaDoc servletContext )
41     {
42         init( null, null, servletContext );
43     }
44
45     public void login( FlowControllerHandlerContext context, String JavaDoc username, String JavaDoc password )
46         throws LoginException JavaDoc
47     {
48         assert context.getRequest() instanceof HttpServletRequest JavaDoc : "don't support ServletRequest currently.";
49         assert context.getResponse() instanceof HttpServletResponse JavaDoc : "don't support ServletResponse currently.";
50         HttpServletRequest JavaDoc request = ( HttpServletRequest JavaDoc ) context.getRequest();
51         HttpServletResponse JavaDoc response = ( HttpServletResponse JavaDoc ) context.getResponse();
52         AdapterManager.getServletContainerAdapter( getServletContext() ).login( username, password, request, response );
53     }
54
55     public void logout( FlowControllerHandlerContext context, boolean invalidateSessions )
56     {
57         assert context.getRequest() instanceof HttpServletRequest JavaDoc : "don't support ServletRequest currently.";
58         assert context.getResponse() instanceof HttpServletResponse JavaDoc : "don't support ServletResponse currently.";
59         HttpServletRequest JavaDoc request = ( HttpServletRequest JavaDoc ) context.getRequest();
60         HttpServletResponse JavaDoc response = ( HttpServletResponse JavaDoc ) context.getResponse();
61         AdapterManager.getServletContainerAdapter( getServletContext() ).logout( invalidateSessions, request, response );
62     }
63
64     public boolean isUserInRole( FlowControllerHandlerContext context, String JavaDoc roleName )
65     {
66         assert context.getRequest() instanceof HttpServletRequest JavaDoc : "don't support ServletRequest currently.";
67         HttpServletRequest JavaDoc request = ( HttpServletRequest JavaDoc ) context.getRequest();
68         return request.isUserInRole( roleName );
69     }
70
71     public Principal JavaDoc getUserPrincipal( FlowControllerHandlerContext context )
72     {
73         assert context.getRequest() instanceof HttpServletRequest JavaDoc : "don't support ServletRequest currently.";
74         HttpServletRequest JavaDoc request = ( HttpServletRequest JavaDoc ) context.getRequest();
75         return request.getUserPrincipal();
76     }
77 }
78
Popular Tags