Announcement Announcement Module
No announcement yet.
Failing to redirect to login page with ajax request (Spring security, webflow, jsf) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Failing to redirect to login page with ajax request (Spring security, webflow, jsf)


    there is a problem when the session expired (or browser cache is deleted), if the user clicks on an ajax element, an ajax requests will be sent. It should be redirected to the login.xhtml. If the request is not an ajax one, it works fine the page will be redirected, but if it is an ajax requests it does not work.

    In the firefox webconsole it appears as if the request is sent:

    GET: https://..... /logint.xthml:jsessionid=55B2EF959186CC0DCED7347C8F 95A79F

    but nothing happens.

    I'm guessing it fails to recognize that it is an ajax request and the AuthenticationEntryPoint does not send the expected response.

    Using Spring Security 3.1.0.RELEASE, Spring WebFlow 2.3.1.RELEASE and JSF

    Spring Security config:
     <http use-expressions="true"
            <form-login login-page="/ui/account/login.xhtml"
                        authentication-details-source-ref="authenticationDetailsSource" />
            <access-denied-handler ref="webAuthorizationFailedHandler"/>
            <logout logout-url="/ui/j_spring_security_logout"/>
       			<port-mapping http="${server.port.http}" https="${server.port.https}"/>
            <intercept-url pattern="/ui/javax.faces.resource/**" access="permitAll" requires-channel="any"/>
    	<intercept-url pattern="/ui/account/login.xhtml*" access="hasRole('ROLE_ANONYMOUS')" requires-channel="https"/>
            <intercept-url pattern="/ui/j_spring_security_check" access="permitAll" requires-channel="https"/>
            <intercept-url pattern="/**" access="hasRole('ROLE_AUTHORIZED_WEB_USER')" requires-channel="any"/>
    Spring WebFow config:
             <bean id="securityFlowExecutionListener" class="">
    		<property name="accessDecisionManager" ref="accessDecisionManager"/>
    	<!-- Flow Executor -->
      	<flow:flow-executor id="flowExecutor">
      			<flow:listener ref="securityFlowExecutionListener"/>
      			<flow:listener ref="facesContextListener"/>
        <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"  >
            <property name="flowExecutor" ref="flowExecutor"/>
            <property name="ajaxHandler">
            	<bean class="org.springframework.faces.webflow.JsfAjaxHandler" />
    	<bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>
    Have I made a configuration mistake? Is this a bug??

    As workaround I implemented my own AuthenticationEntryPoint checking if the request is an ajax one and then handling it with the
    org.springframework.faces.webflow.JsfAjaxHandler, otherwise using the default implementation.

    Thanks in advance.

  • #2
    You won't get a redirect if you make an ajax request. You would need to configure your ajax handler to detect the session timeout event and then redirect the browser to the login page (probably by changing the document.url property)


    • #3
      Hi thanks for the reply,

      the problem is if the session timeout occurs, the ajax handler does not get any requests. A redirect will be performed by the security entry point.
      What do you mean with 'detect' session timeout? The timeout tracking will be made with standard http session tracking

      in web.xml



      • #4
        Any more suggestions?