1 Reply Latest reply on Mar 2, 2007 2:45 PM by tonylmai

    How to dynamically navigate after identity.login()

    johnechesher

      After successfully logging into my app using identity.login(), I want to dynamically direct the user to one of two pages, depending upon the permissions level of the user. I have tried several options, none of which worked, and I'm about ready to implement the solution that I know to work - use a JPDL pageflow - but before I do, I was wondering if someone had an easier, more elegant way of implementing this common scenario. Here are the attempts I have made thus far:

      1) This does not produce an exception, but it always navigates back to the login page, so I assume Seam cannot handle nested navigation rules:

      <page view-id="/login.xhtml">
       <navigation from-action="#{identity.login}">
       <rule if-outcome="loggedIn">
       <rule if="#{s:hasPermission('userAndInstitution','add', null)}">
       <redirect view-id="/AdminHome.xhtml"/>
       </rule>
       <rule if="#{not s:hasPermission('userAndInstitution','add', null)}">
       <redirect view-id="/UserHome.xhtml"/>
       </rule>
       </rule>
       </navigation>
      </page>


      2) The idea here was that I didn't need to check for outcome of "loggedIn", since the only other outcome is null, which would go immediately back to the previous page. However, the expression parser fails once it hits "s:":
      <page view-id="/login.xhtml">
       <navigation from-action="#{identity.login}">
       <rule if="#{s:hasPermission('userAndInstitution','add', null)}">
       <redirect view-id="/AdminHome.xhtml"/>
       </rule>
       <rule if="#{not s:hasPermission('userAndInstitution','add', null)}">
       <redirect view-id="/UserHome.xhtml"/>
       </rule>
       </navigation>
      </page>


      3) This was an attempt to access the identity permission method directly. The expression parser throws an exception when it hits the "(":
      <page view-id="/login.xhtml">
       <navigation from-action="#{identity.login}">
       <rule if="#{identity.checkPermission('userAndInstitution','add', null)}">
       <redirect view-id="/AdminHome.xhtml"/>
       </rule>
       <rule if="#{not identity.checkPermission('userAndInstitution','add', null)}">
       <redirect view-id="/UserHome.xhtml"/>
       </rule>
       </navigation>
      </page>


      Any other ideas or commentary on what I have tried?

        • 1. Re: How to dynamically navigate after identity.login()

          You can override the RuleBasedIdentity.login to redirect the user to the correct page.

          @Name("org.jboss.seam.security.identity")
          @Scope(ScopeType.SESSION)
          @Intercept(InterceptionType.AFTER_RESTORE_VIEW)
          public class YourNewIdentity extends RuleBasedIdentity {
          ...
           @Override
           public String login() {
           super.login(); /* Ignore outcome from super */
          
           // check user role and return the correct view
           if (user has role x) {
           return "goto x page";
           } else {
           return "goto y page";
           }
           }
          


          Don't forget to take out the navigation rule in the page.xml.

          Hope it helps.