6 Replies Latest reply on Oct 1, 2008 8:20 PM by Francisco Jose Peredo Noguez

    How to hide the login.xhtml page

    Thiagu Mariappan Novice

      Hi every one


      i need to hide the login.xhtml page accessed through non faces request (like http://localhost:7000/login.seam) after successfully logged in.


      By
      Thiagu.m

        • 1. Re: How to hide the login.xhtml page
          Francisco Jose Peredo Noguez Master

          What exactly do you mean by hide? what exactly do you want to happen?


          Disable any link you may have pointing to http://localhost:7000/yourappname/login.seam after you logged in successfully?


          or


          that if you visit http://localhost:7000/yourappname/login.seam after you logged in successfully you are automatically redirected somewhere else? you want some kind of trick to simulate a hypotetical (currently not available) no-login-required="true" in your login.page.xml? Do you think is likely that you users will accidentally visit the longin page after they logged in? if so... what would be bad with that?

          • 2. Re: How to hide the login.xhtml page
            Francisco Jose Peredo Noguez Master

            Maybe my workaround for another problem may serve you as a basis to prevent access to your login.xhtml after you are logged in, just adapt it to redirect you somewhere else by modifying login.page.xml so that it redirects you to home if you try to reach login.seam after you successfully logged in:


            
            public String checkSomeCondition(){
              if(Identity.instance().isLoggedIn())
                 return "forbidden";
               return "ok";
            }
            
            



            That way you can create you own no-login-required="true" configuration! :-)

            • 3. Re: How to hide the login.xhtml page
              Stuart Douglas Master

              I also have a dodgy workaround for this problem, but it does not require any code:



              <page action='#{"".toString()}'>
                  <navigation from-action='#{"".toString()}'>
                      <rule if="#{identity.loggedIn}">
                          <redirect view-id="/some_other_page.xhtml" />
                      </rule>
                  </navigation>
              </page>



              the "".toString() is just a nothing action, but the navigation rules only get run if some kind of page action is present.

              • 4. Re: How to hide the login.xhtml page
                Thiagu Mariappan Novice
                thank u for reply

                my question is i am logged in already .
                as the navigation rule from login.page.xml it redirect me to the home page.

                even i specify the render condition for login form like (rendered="#{not identity.loggedIn}") if i use this url http://localhost:7000/myapp/login.seam
                i can see the empty page .

                that is why i am asking is there any predefine rule like (no-login-required="true") to prevent the login page after successfully logged in.

                the rule like to redirect me to home page with warning message like "You are already logged in!"

                now i am clear how to do this one.

                By
                Thiagu.m

                • 5. Re: How to hide the login.xhtml page
                  Thiagu Mariappan Novice
                  this my navigation rule from pages.xml

                  <page view-id="*">
                          <navigation from-action="#{register.loginCheck}">
                              <rule if-outcome="login">
                                  <redirect view-id="/login.xhtml"/>
                              </rule>
                          </navigation>
                  </page>  
                     
                  <page view-id="/login.xhtml" action="#{register.loginCheck}"/>

                  so whenever i click the login link (s:link) it redirect me to login.xhtml page.
                  at the time of render the login.xhtml page i invoke loginCheck method from register component.
                  this is my loginCheck method code from register component.

                  public String loginCheck()
                      {
                           
                            if(identity.isLoggedIn())
                            {
                                facesMessages.addToControl("regConPassword", "You are already logged in!");
                                return "home";
                            }
                            else
                              return "login";
                      }

                  here i face the new problem is seam link recurcevely invoke the loginCheck method.
                  it does not redirect me to login.xhtml page.
                  is there any mistake in my code.
                  i am using seam 2.1.0.A1.

                  By
                  Thiagu.m

                  • 6. Re: How to hide the login.xhtml page
                    Francisco Jose Peredo Noguez Master

                    I think you should implement this in login.page.xml not in pages.xml.


                    Here is how I did it (the navigationVerifier is a component I created specifically for this, but you could use Stuart Douglas trick and avoid that if you like, just do not forget to add the <action execute="#{"".toString()}" /> mmm, I wonder if Stuart's nothing action really works and it is safe... well that is your choice... ):


                    
                    <?xml version="1.0" encoding="UTF-8"?>
                    <page xmlns="http://jboss.com/products/seam/pages"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
                    
                         <action execute="#{navigationVerifier.isUserLoggedIn}" />
                    
                    
                         <navigation from-action="#{identity.login}">
                              <rule if="#{identity.loggedIn}">
                                   <redirect view-id="/entrada.xhtml" />
                              </rule>
                         </navigation>
                    
                         <navigation from-action="#{navigationVerifier.isUserLoggedIn}">
                              <rule if-outcome="logged in">
                                   <redirect view-id="/home.xhtml"></redirect>
                              </rule>
                         </navigation>
                    
                    </page>