01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.pageflow.internal;
20:
21: import org.apache.beehive.netui.pageflow.handler.LoginHandler;
22: import org.apache.beehive.netui.pageflow.handler.BaseHandler;
23: import org.apache.beehive.netui.pageflow.handler.FlowControllerHandlerContext;
24:
25: import javax.servlet.ServletContext;
26: import javax.servlet.ServletRequest;
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29: import javax.security.auth.login.LoginException;
30: import java.io.Serializable;
31: import java.security.Principal;
32:
33: /**
34: * Implements default J2EE web-tier login handling.
35: */
36: public class DefaultLoginHandler extends DefaultHandler implements
37: LoginHandler {
38: public DefaultLoginHandler(ServletContext servletContext) {
39: init(null, null, servletContext);
40: }
41:
42: public void login(FlowControllerHandlerContext context,
43: String username, String password) throws LoginException {
44: assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently.";
45: assert context.getResponse() instanceof HttpServletResponse : "don't support ServletResponse currently.";
46: HttpServletRequest request = (HttpServletRequest) context
47: .getRequest();
48: HttpServletResponse response = (HttpServletResponse) context
49: .getResponse();
50: AdapterManager.getServletContainerAdapter(getServletContext())
51: .login(username, password, request, response);
52: }
53:
54: public void logout(FlowControllerHandlerContext context,
55: boolean invalidateSessions) {
56: assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently.";
57: assert context.getResponse() instanceof HttpServletResponse : "don't support ServletResponse currently.";
58: HttpServletRequest request = (HttpServletRequest) context
59: .getRequest();
60: HttpServletResponse response = (HttpServletResponse) context
61: .getResponse();
62: AdapterManager.getServletContainerAdapter(getServletContext())
63: .logout(invalidateSessions, request, response);
64: }
65:
66: public boolean isUserInRole(FlowControllerHandlerContext context,
67: String roleName) {
68: assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently.";
69: HttpServletRequest request = (HttpServletRequest) context
70: .getRequest();
71: return request.isUserInRole(roleName);
72: }
73:
74: public Principal getUserPrincipal(
75: FlowControllerHandlerContext context) {
76: assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently.";
77: HttpServletRequest request = (HttpServletRequest) context
78: .getRequest();
79: return request.getUserPrincipal();
80: }
81: }
|