6 Replies Latest reply on Sep 22, 2010 9:42 AM by kamiq

    Redirecting page after authentication

    kamiq

      hi,
      I want to achieve that after authentication method application always redirect me to home page. For now, if session expire, after login process, application will redirect request to last page instead of home page. Does anybody know how can I change this behaviour to redirecting always to home page?

        • 1. Re: Redirecting page after authentication
          lvdberg

          Hi,


          Try this:




          <page view-id="login.xhtml">
               <navigation from-action="#{identity.login}">
                    <rule if-outcome="loggedIn">
                         <redirect view-id="home.xhtml" />
                    </rule>
               </navigation>
          ....
          </page>
          
          



          You call the action from your log-in page and the authenticator should be configured as usual in components.xml


          Leo


          • 2. Re: Redirecting page after authentication
            marcelkolsteren

            Leo already described how to redirect to your home page after successful login. Then there still is the part of redirecting to the home page after session expiration. You could do that by adding this to your pages.xml file:


            <exception class="javax.faces.application.ViewExpiredException" log="false">
               <redirect view-id="/home.xhtml">
                  <message severity="warn">#{messages['warn.viewExpired']}</message>
               </redirect>
            </exception>
            

            • 3. Re: Redirecting page after authentication
              marcelkolsteren

              Sorry, forget my remark :-). After session expiration you'd probably want to redirect to the login page, instead of the home page. You probably already have that fragment for handling the ViewExpiredException in pages.xml, but with a redirect to login.xhtml instead of home.xhtml.

              • 4. Re: Redirecting page after authentication
                kamiq

                Thanks for your interest.
                Unfortunately it doesn't work as I expect. I have been using this configuration from the beginning. maybe I described wrong my problem, and following example wiil be more precise


                For example, if I click something on page when the session is expired, application redirects me to login...it's correct. But after authentication I'm redirected to previous page (where I clicked something) instead of home page (I expect always ). I don't undarstand where this old url is cached. Any ideas?


                I use seam 2.2 version.

                • 5. Re: Redirecting page after authentication
                  marcelkolsteren

                  Redirecting back to the requested page after a login interruption is normally done by adding these event actions to the components.xml:


                  <event type="org.jboss.seam.security.notLoggedIn">
                     <action execute="#{redirect.captureCurrentView}"/>
                  </event>
                  
                  <event type="org.jboss.seam.security.postAuthenticate">
                     <action execute="#{redirect.returnToCapturedView}"/>
                  </event>



                  Do you have those in components.xml? Then you need to remove them.

                  • 6. Re: Redirecting page after authentication
                    kamiq

                    Thanks Marcel,
                    This is exactly what I was looking for. Propably JBoss Tools generated this code snippet and I didn't see it.