2 Replies Latest reply on Nov 18, 2011 1:09 PM by Jason Porter

    Seam 3 - Redirect user to a new page

    Peter Penzov Newbie
      Hi,
        I have a question about Seam 3. I have this simple example of login beam:

      package org.jboss.seam.security.examples.simple;

      import javax.inject.Inject;

      import org.jboss.seam.security.Authenticator;
      import org.jboss.seam.security.BaseAuthenticator;
      import org.jboss.seam.security.Credentials;
      import org.picketlink.idm.impl.api.PasswordCredential;
      import org.picketlink.idm.impl.api.model.SimpleUser;

      /**
      * This is the simplest possible example of a custom authenticator.
      *
      * @author Shane Bryzak
      *
      */
      public class SimpleAuthenticator extends BaseAuthenticator implements Authenticator
      {
         @Inject Credentials credentials;
        
         @Override
         public void authenticate()
         {
            if ("demo".equals(credentials.getUsername()) &&
                  credentials.getCredential() instanceof PasswordCredential &&
                  "demo".equals(((PasswordCredential) credentials.getCredential()).getValue()))
                 
            {
               setStatus(AuthenticationStatus.SUCCESS);
               setUser(new SimpleUser("demo"));
            }
            else
            {
               setStatus(AuthenticationStatus.FAILURE);
            }
         }

      }


      My question is how to redirect the user to a different JSF page when he is successfully logged in?
      I know the classic way with faces-config.xml. But here I don't have an idea how to do it.

      Regards
        • 1. Re: Seam 3 - Redirect user to a new page
          Peter Penzov Newbie
          I tried with this faces-config.xml file

          <?xml version="1.0"?>
          <faces-config xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
             version="2.0">
             <navigation-rule>
                <from-view-id>/home.jsf</from-view-id>
                <navigation-case>
                   <from-action>#{identity.login}</from-action>
                   <from-outcome>success</from-outcome>
                   <to-view-id>/main.xhtml</to-view-id>
                </navigation-case>
             </navigation-rule>
             <navigation-rule>
                <navigation-case>
                   <from-action>#{identity.login}</from-action>
                   <from-outcome>failure</from-outcome>
                   <to-view-id>/home.xhtml</to-view-id>
                </navigation-case>
             </navigation-rule>
          </faces-config>

          I have a error somewhere because it does not work.
          • 2. Re: Seam 3 - Redirect user to a new page
            Jason Porter Master

            Take a look at ViewConfig in Seam Faces, there's an example that should demonstrate this.