2 Replies Latest reply on Aug 26, 2008 4:58 PM by Georges Goebel

    rules in login.page.xml

    moumen rajae Newbie

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

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

      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"/>

      here is my method isadmin

      public boolean isadmin(String usernam,String pass)
                         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
          Samuel Mendenhall Apprentice

          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"/>

          • 2. Re: rules in login.page.xml
            Georges Goebel Newbie

            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">
                        <rule if="#{authenticator.admin}">
                            <redirect view-id="/cart.xhtml"/>
                        <rule if="#{!authenticator.admin}">
                            <redirect view-id="/main2.xhtml"/>

            The code for the autenticator can look like this :

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

            That should do the trick