2 Replies Latest reply on Aug 26, 2008 4:58 PM by georges.goebel

    rules in login.page.xml

    1womps1

      Hi ,Currently i have a rule te direct users successfull logged in to a file




      <rule if="#{identity.loggedIn}">
               <redirect view-id="/request.xhtml"/>
      </rule>



      And i'm trying to add a new rule that redirect the administrator to the file admin.xhtml


      i have tried to add the following rule



      <rule if="#{authenticator.isadmin}">
               <redirect view-id="/admin.xhtml"/>
       </rule>



      here is my method isadmin



      public boolean isadmin(String usernam,String pass)
         { 
                 if((usernam=="rajae")||(pass=="rajae"))      
                         return true;
                 else return false;
                 
         }


      But it doesn't work all the users are redirected the request.xhtml


      Could you please give me an idea of how should i change it,thank you

        • 1. Re: rules in login.page.xml
          sjmenden

          I think you are going about this wrong, you should  be adding the admin role to the identity roles when you authenticate.  Then you can simply do:



          <rule if="#{isUserInRole['admin']}">
                   <redirect view-id="/admin.xhtml"/>
           </rule>


          • 2. Re: rules in login.page.xml
            georges.goebel

            It's better to use the isUserInRole as indicated by the previous post.
            But if you want to implement a custom autenticator you can do it as follows.


            First be sure that your autenticator is executed because I remember that when you use JASS (f.ex with ldap the authenticate-method is ignored). Check this post link to forum


            Next add the corresponding code to pages.xml



             <page view-id="/login.xhtml">
                    <navigation>
                        <rule if="#{authenticator.admin}">
                            <redirect view-id="/cart.xhtml"/>
                        </rule>
            
                        <rule if="#{!authenticator.admin}">
                            <redirect view-id="/main2.xhtml"/>
                        </rule>
                    </navigation>
                </page>



            The code for the autenticator can look like this :


            private boolean admin = false;
            
               public boolean authenticate() {
                  log.info("autenticate ....");
                  try
                  {
                     Identity.instance().authenticate();
            
                     log.info("Login to signalisation of : " + Identity.instance().getUsername());
            
                      if (Identity.instance().getUsername().equals("goebel")) {
                          admin = true;
                      }
            
                     return true;
                  }
                  catch (NoResultException ex)
                  {
                      ex.printStackTrace();
                     return false;
                  } catch (LoginException e) {
                      e.printStackTrace();
                  }
                  return false;
               }
            
                public boolean isAdmin() {
                    return admin;
                }
            
                public void setAdmin(boolean admin) {
                    this.admin = admin;
                }
            




            That should do the trick


            Georges