1 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 ; 25 import javax.servlet.ServletRequest ; 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 28 import javax.security.auth.login.LoginException ; 29 import java.io.Serializable ; 30 import java.security.Principal ; 31 32 33 36 public class DefaultLoginHandler 37 extends DefaultHandler 38 implements LoginHandler 39 { 40 public DefaultLoginHandler( ServletContext servletContext ) 41 { 42 init( null, null, servletContext ); 43 } 44 45 public void login( FlowControllerHandlerContext context, String username, String password ) 46 throws LoginException 47 { 48 assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently."; 49 assert context.getResponse() instanceof HttpServletResponse : "don't support ServletResponse currently."; 50 HttpServletRequest request = ( HttpServletRequest ) context.getRequest(); 51 HttpServletResponse response = ( HttpServletResponse ) 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 : "don't support ServletRequest currently."; 58 assert context.getResponse() instanceof HttpServletResponse : "don't support ServletResponse currently."; 59 HttpServletRequest request = ( HttpServletRequest ) context.getRequest(); 60 HttpServletResponse response = ( HttpServletResponse ) context.getResponse(); 61 AdapterManager.getServletContainerAdapter( getServletContext() ).logout( invalidateSessions, request, response ); 62 } 63 64 public boolean isUserInRole( FlowControllerHandlerContext context, String roleName ) 65 { 66 assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently."; 67 HttpServletRequest request = ( HttpServletRequest ) context.getRequest(); 68 return request.isUserInRole( roleName ); 69 } 70 71 public Principal getUserPrincipal( FlowControllerHandlerContext context ) 72 { 73 assert context.getRequest() instanceof HttpServletRequest : "don't support ServletRequest currently."; 74 HttpServletRequest request = ( HttpServletRequest ) context.getRequest(); 75 return request.getUserPrincipal(); 76 } 77 } 78 | Popular Tags |