3 Replies Latest reply on Apr 1, 2012 9:53 AM by Sergio Angelo

    how to auto-login before redirecting to login page?

    Hoang Le Newbie

      Hello,

       

      I'm using Seam 2 for my work and I'm quite new to it. I have a little problem with login in Seam 2.2.

       

      I want to do a auto login (with waffle's single-sign-on) first and only want to redirect to login page if auto-login fails. What should I do?

       

      I've observed that everytime I access a restricted page without authorization, Seam throws an NotLoggedInException and a NotLoggedIn event, and redirect me to login page. I've tried some workarounds but they doesn't really look right. Currently I don't know yet how to catch the NotLoggedInException before the restricted page is redirected by Seam.

       

      Please help me. Thank you very much

       

      Hoang

       

      Edit: Only pages with "login-required" do the login procedure.

        • 1. Re: how to auto-login before redirecting to login page?
          Sergio Angelo Newbie

          -Redirect to your authentication method from your welcome.xhtml (so the first thing that happens is authentication when the app startsup). Anyways, make sure that you're logged in when the app is up and running. You can even try to do this in a bean annotated with @Startup, which also gets executed when Seam starts up.

          -If someone has bookmarked a page and tries to access that page without authentication, then listen to the NotLoggedIn event by making an observer and handle the authentication logic there.

           

          And as always, read the manual for more info check the Security chapter for usefull info on this subject.

          • 2. Re: how to auto-login before redirecting to login page?
            Hoang Le Newbie

            Hi Serkan,

             

            Actually I just want restricted pages require login. So I think doing auto-login at startup for non-restricted pages isn't the right way.

             

            -----------------

             

            Edit:

             

            I think I did it.

             

            in my login.page.xml, I added an action for executing login. The rest was generated by seam-gen

             

            <action execute="#{identity.login}"/>

             

            <navigation from-action="#{identity.login}">

            <rule if="#{identity.loggedIn}">

                      <redirect view-id="/home.xhtml" />

                 </rule>

            </navigation>

             

            Thank you for supporting me

            • 3. Re: how to auto-login before redirecting to login page?
              Sergio Angelo Newbie

              - in your pages.xml set login-page=/autologin.xhtml, note that this page shouldn't exist !!

              - then <page view-id='/autologin.xhtml' action='#{authentication.autoLogin}'/>, in autoLogin make sure you call Identity.quietLogin.