Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Multiple Authentication Entry Points

  1. #11
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    You don't need two SecurityEnforcementFilters and you don't need two AuthenticationFilterEntryPoints.

    The AuthenticationFilterEntryPoint is used by SecurityEnforcementFilter whenever an AuthenticationException is detected. In other words, when SecurityEnforcementFilter decides the user needs to logon, it launches AuthenticationFilterEntryPoint. You can only have one such filter per webapp. If you really need more customised handling, such as the intended login form is based on the request that was made which failed, you'll need to write your own AuthenticationEntryPoint.

    It should also be noted the AuthenticationProcessingFilter.defaultTargetUrl is only called when the login was not as a result of the AuthenticationFilterEntryPoint. If it was the result of the AuthenticationFilterEntryPoint, the SecurityEnforcementFilter will have told the AuthenticationProcessingFilter (via the HttpSession) the URL that should be displayed post-authentication. That URL should be the secured page the user requested but was denied. The defaultTargetUrl only applies if the user logged in of their own accord - not as a result of the application prompting them to. If you want to always ignore the AuthenticationFilterEntryPoint target URL, your best course of action is to write a custom AuthenticationEntryPoint which changes the HttpSession parameter.

    Hope this explains a bit more clearly what is going on.

  2. #12

    Default

    Thank you for your explain about the filters.

    I have realized that the filters in web.xml are redundant after I posted the last post. Then I removed them. But the result still was not what I want.

    I have ever thought to write a MutliAuthenticationEntryPoint class to accomplish this task, but I didn't understant fully the internal relationships.

    Now I used a trick to fulfill this task: write a jsp file for home page login form and a servlet, and in the servlet, get the authenticationManager to authenticate and put the authentication object into session, and this does works well.

    Maybe I will rethink to implement my AuthenticationEntryPoint later.

    Anyway, many thanks for your help.

  3. #13
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Quote Originally Posted by simontang_tang
    Now I used a trick to fulfill this task: write a jsp file for home page login form and a servlet, and in the servlet, get the authenticationManager to authenticate and put the authentication object into session, and this does works well.
    Just double-check it really does work as you intend. A lot of people write directly to the HttpSession and then get surprised when strange things happen. Your AbstractIntegrationFilter does this:

    1. Retrieve from the well-known location (typically HttpSession) the Authentication
    2. Populate ContextHolder with Authentication
    3. Proceed with request (ie your web controller/servlet etc runs now)
    4. Retrieve from the ContextHolder the Authentication
    5. Write the retrieved Authentication back to the well-known location

    So your HttpSession may get overwritten with null if you just set it via your servlet.

    I'd encourage instead to customise an AuthenticationEntryPoint. It's really easy to do. This is the entire interface:

    Code:
        public void commence(ServletRequest request, ServletResponse response)
            throws IOException, ServletException;
    So your implementation just looks at the request URL, and decides the correct URL to put into HttpSession parameter defined by AbstractProcessingFilter.ACEGI_SECURITY_TARGET_URL _KEY (which would have earlier been set by the SecurityEnforcementFilter).

    If a login form is presented because of a user wish to login - as opposed to your SecurityEnforcementFilter detecting a problem and delegating to AuthenticationEntryPoint - the defaultTargetUrl defined against the responding AuthenticationProcessingFilter will be used.

  4. #14

    Default

    Yesterday my trick has encountered a problem: the login process on the home page is correct; but when I entered into user's personal home page, it's correct in the first time, and after I logged out from personal home page, then redirect to home page, the process was also correct. But when I logged in again and entered into personal home page, the login form page showed while personal information showed on the page is correct. Could you give me some hints about this problem?

    Today I implemented a AuthenticationEntryPoint as you stated, the code like such:
    Code:
    public class EdusuppAuthenticationEntryPoint extends
            AuthenticationProcessingFilterEntryPoint {
        private static final Log logger = LogFactory.getLog(EdusuppAuthenticationEntryPoint.class);
        
        private PortResolver portResolver = new PortResolverImpl();
        
        public void setPortResolver(PortResolver portResolver) {
            this.portResolver = portResolver;
        }
    
        public PortResolver getPortResolver() {
            return portResolver;
        }
        
        /* (non-Javadoc)
         * @see net.sf.acegisecurity.intercept.web.AuthenticationEntryPoint#commence(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
         */
        public void commence(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
            HttpServletRequest req = (HttpServletRequest) request;
            String scheme = request.getScheme();
            String serverName = request.getServerName();
            int serverPort = portResolver.getServerPort(request);
            String contextPath = req.getContextPath();
    
            boolean includePort = true;
    
            if ("http".equals(scheme.toLowerCase()) && (serverPort == 80)) {
                includePort = false;
            }
    
            String redirectUrl = scheme + "://" + serverName
                + ((includePort) ? (":" + serverPort) : "") + contextPath;
    
            if(req.getRequestURL().indexOf("userWelcome") != -1) {
                redirectUrl += "/loginMain.jsp";
                
                req.getSession().setAttribute(AbstractProcessingFilter.ACEGI_SECURITY_TARGET_URL_KEY, redirectUrl);
                
                if (logger.isDebugEnabled()) {
                    logger.debug("Redirecting to: " + redirectUrl);
                }
    
                ((HttpServletResponse) response).sendRedirect(((HttpServletResponse) response)
                    .encodeRedirectURL(redirectUrl));
            } else {
                 super.commence(request, response);
            }
        }
    }
    loginMain.jsp is the login form page will be show in the home page using IFrame, and the iframe will linked userWelcome.jsp, this page required the user to be authorized. The problem is when I access the home page, the login form showed but after authorized, the login form still shows. When I access the personal home page, it shows the user's personal information.

    Would you like to check the problem? Many thanks.

  5. #15
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Let's try and simplify things a bit.

    I presume you're still using this config:

    Code:
    <bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
          <property name="authenticationManager"><ref bean="authenticationManager"/></property>
          <property name="authenticationFailureUrl"><value>/loginError.jsp</value></property>
          <property name="defaultTargetUrl"><value>/mainMenu.html</value></property>
          <property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
    </bean> 
    
    <bean id="authenticationProcessingFilter2" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
          <property name="authenticationManager"><ref bean="authenticationManager"/></property>
          <property name="authenticationFailureUrl"><value>/loginMainError.jsp</value></property>
          <property name="defaultTargetUrl"><value>/userWelcome.jsp</value></property>
          <property name="filterProcessesUrl"><value>/j_acegi_security_check_home</value></property>
    </bean>
    I also presume your /loginMain.jsp login form redirects to /j_acegi_security_check. I presume your home page login form POSTs to /j_acegi_security_check_home.

    Next up disable any IFRAMEs and start your web container from scratch. If you visit /loginMain.jsp, login as a user, does it post to /j_acegi_security_check and then redirect to /mainMenu.html?

    Next shutdown your web container and start it again without any IFRAMEs. If you visit your home page login form, does it POST to /j_acegi_security_check_home and then redirect to /userWelcome.jsp?

    This basic initial behaviour does not in any way involve an AuthenticationEntryPoint. It's solely as a result of user login requests.

    Ensure your "logout" operation is actually a HttpSession invalidation, rather than any overwriting an HttpSession attribute or ContextHolder value.

    Once you've proven your basic configuration works, next try accessing a secure page when you're not logged in. Look at the debug logs and ensure the entry point redirects to the correct login page. Then check that login page, subsequent to successful login, redirects to the AbstractProcessingFilter.ACEGI_SECURITY_TARGET_URL _KEY (which your entry point will have overwritten if required).

  6. #16

    Default

    The page flow likes such:
    1. loginMain.jsp ----> loginMainServlet ----> j_acegi_security_check_home ----> userWelcome.jsp

    2. login.jsp ----> loginServlet ----> j_acegi_security_check ----> mainMenu.html

    3. userWelcome.jsp -----> logoutMain.jsp ----> loginFilter (invalidate the session and ContextHolder.setContext(null)

    4. mainMenu.html ----> logout.jsp ---> loginFilter(invalidate the session and ContextHolder.setContext(null)

  7. #17
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    What's the problem with that? AFAICS it's behaving as configured.

  8. #18

    Default

    The page flow I posted is the result I want. But actually not.

    I have tried two filters in applicationContext.xml file, page flow 1 is correct, but page flow 2 is not, the error info is : j_acegi_security_check can't be found.

    Then I returned to the previous trick: using servlet and jsp to authenticate user and populate session. The first time I logged in on the home page(loginMain.jsp), and showed userWelcome.jsp, this is correct. After logged out through logout.jsp, I returned to the loginMain.jsp. But when I logged in through loginMain.jsp again, I got the login.jsp. This is the problem: for it should display mainMenu.html.

  9. #19

    Default

    The following information is copied from tomcat console. From the second login to showing login.jsp:
    Code:
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; LoginMainServlet.execute&#40;93&#41; | Encrypting password f
    or user 'student_1'
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; ProviderManager.doAuthentication&#40;125&#41; | Authenticati
    on attempt using net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; EhCacheBasedUserCache.getUserFromCache&#40;86&#41; | Cache h
    it&#58; false; username&#58; student_1
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; EhCacheBasedUserCache.putUserInCache&#40;119&#41; | Cache pu
    t&#58; student_1
    &#91;edusupp&#93; INFO &#91;Thread-13&#93; UserCounterListenerSpring.onApplicationEvent&#40;55&#41; | Au
    thentication success for user&#58; student_1; details&#58; 127.0.0.1
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; SecurityEnforcementFilter.doFilter&#40;168&#41; | Chain proc
    essed normally
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;176&#41; | Updating c
    ontainer with new Authentication object, and then removing Authentication from C
    ontextHolder
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;164&#41; | Authentica
    tion not added to ContextHolder &#40;could not extract an authentication object from
     the container which is an instance of Authentication&#41;
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractSecurityInterceptor.interceptor&#40;346&#41; | Publi
    c object - authentication not attempted
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; SecurityEnforcementFilter.doFilter&#40;168&#41; | Chain proc
    essed normally
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;176&#41; | Updating c
    ontainer with new Authentication object, and then removing Authentication from C
    ontextHolder
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;164&#41; | Authentica
    tion not added to ContextHolder &#40;could not extract an authentication object from
     the container which is an instance of Authentication&#41;
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractSecurityInterceptor.interceptor&#40;346&#41; | Publi
    c object - authentication not attempted
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; SecurityEnforcementFilter.doFilter&#40;168&#41; | Chain proc
    essed normally
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;176&#41; | Updating c
    ontainer with new Authentication object, and then removing Authentication from C
    ontextHolder
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;164&#41; | Authentica
    tion not added to ContextHolder &#40;could not extract an authentication object from
     the container which is an instance of Authentication&#41;
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractSecurityInterceptor.interceptor&#40;273&#41; | Secur
    e object&#58; FilterInvocation&#58; URL&#58; /mainMenu.html; ConfigAttributes&#58; &#91;ROLE_SUPERVI
    SOR, ROLE_STUDENT, ROLE_TEACHER, ROLE_PARENT, ROLE_EXPERT, ROLE_CA&#93;
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; SecurityEnforcementFilter.doFilter&#40;191&#41; | Authentica
    tion failed - adding target URL to Session&#58; http&#58;//localhost&#58;8080/edusupp/mainMe
    nu.html
    net.sf.acegisecurity.AuthenticationCredentialsNotFoundException&#58; Authentication
    credentials were not found in the SecureContext
            at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.intercepto
    r&#40;AbstractSecurityInterceptor.java&#58;289&#41;
            at net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke&#40;F
    ilterSecurityInterceptor.java&#58;78&#41;
            at net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter
    &#40;SecurityEnforcementFilter.java&#58;165&#41;
            at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter&#40;FilterToBeanProx
    y.java&#58;88&#41;
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;Appl
    icationFilterChain.java&#58;213&#41;
            at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationF
    ilterChain.java&#58;193&#41;
            at net.sf.acegisecurity.ui.AbstractIntegrationFilter.doFilter&#40;AbstractIn
    tegrationFilter.java&#58;170&#41;
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;Appl
    icationFilterChain.java&#58;213&#41;
            at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationF
    ilterChain.java&#58;193&#41;
            at net.sf.acegisecurity.ui.AbstractProcessingFilter.doFilter&#40;AbstractPro
    cessingFilter.java&#58;368&#41;
            at net.sf.acegisecurity.util.FilterToBeanProxy.doFilter&#40;FilterToBeanProx
    y.java&#58;88&#41;
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;Appl
    icationFilterChain.java&#58;213&#41;
            at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationF
    ilterChain.java&#58;193&#41;
            at org.displaytag.filter.ResponseOverrideFilter.doFilter&#40;ResponseOverrid
    eFilter.java&#58;88&#41;
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;Appl
    icationFilterChain.java&#58;213&#41;
            at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationF
    ilterChain.java&#58;193&#41;
            at org.appfuse.webapp.filter.GZIPFilter.doFilter&#40;GZIPFilter.java&#58;51&#41;
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;Appl
    icationFilterChain.java&#58;213&#41;
            at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationF
    ilterChain.java&#58;193&#41;
            at org.apache.catalina.core.StandardWrapperValve.invoke&#40;StandardWrapperV
    alve.java&#58;256&#41;
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext&#40;StandardPipeline.java&#58;643&#41;
            at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.jav
    a&#58;480&#41;
            at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
    
            at org.apache.catalina.core.StandardContextValve.invoke&#40;StandardContextV
    alve.java&#58;191&#41;
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext&#40;StandardPipeline.java&#58;643&#41;
            at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.jav
    a&#58;480&#41;
            at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
    
            at org.apache.catalina.core.StandardContext.invoke&#40;StandardContext.java&#58;
    2415&#41;
            at org.apache.catalina.core.StandardHostValve.invoke&#40;StandardHostValve.j
    ava&#58;180&#41;
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext&#40;StandardPipeline.java&#58;643&#41;
            at org.apache.catalina.valves.ErrorDispatcherValve.invoke&#40;ErrorDispatche
    rValve.java&#58;171&#41;
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext&#40;StandardPipeline.java&#58;641&#41;
            at org.apache.catalina.valves.ErrorReportValve.invoke&#40;ErrorReportValve.j
    ava&#58;172&#41;
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext&#40;StandardPipeline.java&#58;641&#41;
            at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.jav
    a&#58;480&#41;
            at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
    
            at org.apache.catalina.core.StandardEngineValve.invoke&#40;StandardEngineVal
    ve.java&#58;174&#41;
            at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
    t.invokeNext&#40;StandardPipeline.java&#58;643&#41;
            at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.jav
    a&#58;480&#41;
            at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
    
            at org.apache.coyote.tomcat4.CoyoteAdapter.service&#40;CoyoteAdapter.java&#58;22
    3&#41;
            at org.apache.coyote.http11.Http11Processor.process&#40;Http11Processor.java
    &#58;594&#41;
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
    ssConnection&#40;Http11Protocol.java&#58;392&#41;
            at org.apache.tomcat.util.net.TcpWorkerThread.runIt&#40;PoolTcpEndpoint.java
    &#58;565&#41;
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadP
    ool.java&#58;619&#41;
            at java.lang.Thread.run&#40;Thread.java&#58;534&#41;
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AuthenticationProcessingFilterEntryPoint.commence&#40;17
    6&#41; | Redirecting to&#58; http&#58;//localhost&#58;8080/edusupp/login.jsp
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;176&#41; | Updating c
    ontainer with new Authentication object, and then removing Authentication from C
    ontextHolder
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;164&#41; | Authentica
    tion not added to ContextHolder &#40;could not extract an authentication object from
     the container which is an instance of Authentication&#41;
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractSecurityInterceptor.interceptor&#40;346&#41; | Publi
    c object - authentication not attempted
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; SecurityEnforcementFilter.doFilter&#40;168&#41; | Chain proc
    essed normally
    &#91;edusupp&#93; DEBUG &#91;Thread-13&#93; AbstractIntegrationFilter.doFilter&#40;176&#41; | Updating c
    ontainer with new Authentication object, and then removing Authentication from C
    ontextHolder
    login user name : student_1, and his password is encrypted using sha. His role is ROLE_STUDENT.

Similar Threads

  1. Multiple Authentication problem
    By dhainlin in forum Security
    Replies: 5
    Last Post: May 27th, 2006, 10:21 AM
  2. Replies: 2
    Last Post: Oct 13th, 2005, 02:47 PM
  3. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  4. Replies: 8
    Last Post: Dec 7th, 2004, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •