1 2 Previous Next 17 Replies Latest reply on Nov 16, 2008 11:09 PM by Dmitry Shultz

    User specific redirect on login

    Uros Majeric Newbie

      Hi,


      Does anyone knows how to redirect user to a user specific page. For example I have an entity User witch has a property homePage, where is stored on witch page redirect user (RoleList.xhtml,home.xhtml, ...) after login. In previous version of Seam this worked like so:


      <page view-id="/login.xhtml">
           <navigation from-action="#{identity.login}">
                <rule if="#{identity.loggedIn and !empty(currentUser.homePage)}">
                     <redirect view-id="#{currentUser.homePage}"/>
                </rule>
                <rule if="#{identity.loggedIn and empty(currentUser.homePage)}">
                     <redirect view-id="/home.xhtml"/>
                </rule>
           </navigation>
      </page>



      Thaks for help.

        • 1. Re: User specific redirect on login
          Shane Bryzak Master

          Why wouldn't this still work?

          • 2. Re: User specific redirect on login
            Rene Felgenträger Newbie

            same problem with me. the redirect does not work properly anymore in seam 2.1.

            • 3. Re: User specific redirect on login
              Uros Majeric Newbie

              I think this is because currentUser is set at wrong time, at:


              @Observer(JpaIdentityStore.EVENT_USER_AUTHENTICATED)
              public void loginSuccessful(User user) {
                   Contexts.getSessionContext().set("currentUser", user);
              }



              Because redirect was already sent at that time. Correct me if am I wrong?

              • 5. Re: User specific redirect on login
                Shane Bryzak Master

                That event is raised during the authentication process, before the redirect occurs.

                • 6. Re: User specific redirect on login
                  Shane Bryzak Master

                  I just tested the seamspace example in latest SVN trunk and redirect works fine.  I added the following rule:



                      <page view-id="/home.xhtml">
                          <navigation from-action="#{identity.login}">
                              <!--rule if-outcome="loggedIn">
                                  <redirect view-id="/profile.xhtml"/>
                              </rule-->
                              <rule if="#{identity.loggedIn and authenticatedMember ne null}">
                                <redirect view-id="/profile.xhtml"/>
                              </rule>
                          </navigation>
                          <navigation from-action="#{register.start}">
                            <redirect view-id="/register.xhtml"/>
                          </navigation>
                      </page>




                  This caused the user to be redirected to the profile page after login, as expected.  If you're having trouble with redirect after login, can you please try the seamspace example also to see if it has the same problem.

                  • 7. Re: User specific redirect on login
                    Uros Majeric Newbie

                    I just tried the seamspace example with your settings


                        <page view-id="/home.xhtml">
                            <navigation from-action="#{identity.login}">
                                <!--rule if-outcome="loggedIn">
                                    <redirect view-id="/profile.xhtml"/>
                                </rule-->
                                <rule if="#{identity.loggedIn and authenticatedMember ne null}">
                                  <redirect view-id="/profile.xhtml"/>
                                </rule>
                            </navigation>
                            <navigation from-action="#{register.start}">
                              <redirect view-id="/register.xhtml"/>
                            </navigation>
                        </page>



                    but after login I am not redirected to register.seam, but to home.seam (same page on witch I was logging in).

                    • 8. Re: User specific redirect on login
                      Shane Bryzak Master

                      You should actually be redirected to the profile page.  Can you try with the latest SVN version?

                      • 9. Re: User specific redirect on login
                        Dmitry Shultz Newbie

                        I tried the version from trunk, but unfortunately It can't be deployed on Glassfish (9.1), fails on the first attempt to load the page.xml:



                        ...
                        [#|2008-11-11T14:10:40.894-0800|INFO|sun-appserver9.1|org.jboss.seam.Component|_ThreadID=33;_ThreadName=httpWorkerThread
                        -4949-4;|Component: org.jboss.seam.core.init, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.Init|#]
                        
                        [#|2008-11-11T14:10:41.167-0800|SEVERE|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=33;_ThreadName=h
                        ttpWorkerThread-4949-4;_RequestID=4e02004a-c0ef-4909-a7e6-da9ab365673c;|WebModule[/list]PWC1275: Exception sendi
                        ng context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
                        java.lang.NullPointerException: Cannot find URL from classLoader for news/dig.page.xml, loading from WebappClassLoader
                          delegate: true
                          repositories:
                            /WEB-INF/classes/
                        ----------> Parent Classloader:
                        EJBClassLoader : 
                        urlSet = []
                        doneCalled = false 
                         Parent -> java.net.URLClassLoader@349f8a
                        
                        
                                at org.jboss.seam.deployment.FileDescriptor.<init>(FileDescriptor.java:27)
                                at org.jboss.seam.deployment.AbstractScanner$Handler.getFileDescriptor(AbstractScanner.java:108)
                                at org.jboss.seam.deployment.AbstractScanner$Handler.handle(AbstractScanner.java:65)
                                at org.jboss.seam.deployment.AbstractScanner$Handler.handle(AbstractScanner.java:75)
                                at org.jboss.seam.deployment.AbstractScanner.handleItem(AbstractScanner.java:182)
                                at org.jboss.seam.deployment.URLScanner.handleDirectory(URLScanner.java:145)
                                at org.jboss.seam.deployment.URLScanner.handleDirectory(URLScanner.java:140)
                                at org.jboss.seam.deployment.URLScanner.scanDirectories(URLScanner.java:42)
                                at org.jboss.seam.deployment.WarRootDeploymentStrategy.scan(WarRootDeploymentStrategy.java:63)
                                at org.jboss.seam.init.Initialization.init(Initialization.java:705)
                                at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
                                at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4632)
                                at org.apache.catalina.core.StandardContext.start(StandardContext.java:5311)
                                at com.sun.enterprise.web.WebModule.start(WebModule.java:353)
                                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:989)
                                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:973)
                                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:704)
                                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1633)
                                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1239)
                                at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:182)
                                at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:278)
                                at com.sun.enterprise.admin.event.AdminEventMulticaster.invokeModuleDeployEventListener(AdminEventMulticaster.ja
                        va:1004)
                                at com.sun.enterprise.admin.event.AdminEventMulticaster.handleModuleDeployEvent(AdminEventMulticaster.java:991)
                                at com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:470)
                                at com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:182)
                                at com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastEvent(DeploymentNotificationHelper
                        .java:308)
                                at com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(DeploymentServiceUtils.java:230)...

                        • 10. Re: User specific redirect on login
                          Shane Bryzak Master

                          Does the jee5/booking example work in Glassfish, following the steps in the Seam on Glassfish chapter of the docs?

                          • 11. Re: User specific redirect on login
                            Stuart Douglas Master

                            Try the following:


                            
                            <page view-id="/login.xhtml" action="''.toString()" >
                            
                                 <navigation from-action="#{''.toString()}">
                                      <rule if="#{identity.loggedIn and !empty(currentUser.homePage)}">
                                           <redirect view-id="#{currentUser.homePage}"/>
                                      </rule>
                                      <rule if="#{identity.loggedIn and empty(currentUser.homePage)}">
                                           <redirect view-id="/home.xhtml"/>
                                      </rule>
                                 </navigation>
                            </page>
                            
                            



                            This should also have the effect of not allowing you to get to the login page if you are already logged in.

                            • 12. Re: User specific redirect on login
                              Stuart Douglas Master

                              slight typo



                              action="''.toString()"



                              should have been



                              action="#{''.toString()}"

                              • 13. Re: User specific redirect on login
                                Dmitry Shultz Newbie

                                The ear can be deployed, once deployed it fails when i try to select hotel from the list:


                                Caused by javax.ejb.EJBTransactionRolledbackException with message: ""
                                com.sun.ejb.containers.BaseContainer.mapBusinessInterfaceException(BaseContainer.java:1482)
                                com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1396)
                                com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
                                com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:205)
                                com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:83)
                                $Proxy256.selectHotel(Unknown Source)
                                sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                java.lang.reflect.Method.invoke(Method.java:585)
                                org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                                org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                                org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                                org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                                org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:43)
                                org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                                org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                                org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                                org.javassist.tmp.java.lang.Object_$$_javassist_6.selectHotel(Object_$$_javassist_6.java)
                                sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                java.lang.reflect.Method.invoke(Method.java:585)
                                org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
                                org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:274)
                                org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
                                org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)
                                org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                                org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                                org.jboss.seam.core.Expressions$2.invoke(Expressions.java:174)
                                org.jboss.seam.navigation.Pages.callAction(Pages.java:708)
                                org.jboss.seam.navigation.Pages.preRender(Pages.java:346)
                                org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:562)
                                org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:473)
                                org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:146)
                                org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:116)
                                com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
                                com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                                javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)




                                I'm not sure, but may be the fact that in my case there is war deployed (not ear as in the booking example) is a somehow affects the result?

                                • 14. Re: User specific redirect on login
                                  Uros Majeric Newbie

                                  I just tried this but it seems it doesn't work. I am still geting the login page even if I'm logged in.

                                  1 2 Previous Next