3 Replies Latest reply on May 19, 2013 9:35 AM by itays100

    Elegant solution for "already logged in" user

    itays100 Newbie

      Hi All,

       

      I'm using seam 2.1.2 and currently have an issue with linking from excel (link) to my application.

       

       

      <page view-id="/mypage.xhtml" login-required="true">
      
      
      
      
      
              <restrict>#{s:hasRole('myRole')}</restrict>         
              <param name="myid" value="#{request.getParameter('myid')}"/>
              <action execute="#{sampleComponent.linkToObjectPage(myid)}" if="#{myid != null}"/> 
              <rewrite pattern="/mypage"/>  
          </page>
      

       

      I have a link in excel:

       

      http://localhost:8888/jboss-seam-jpa/mypage?id=1234
      

       

      Now I have 2 different scenarios (in both cases the user is logged in):

      1. login-required="false": When clicking on the link I am being forwad to the seam action and this get the object from database by the ID and show

          the data on the page. Works fine!

      2. login-required="true": When clicking on the link I am being forwad to the login page which is incorreect (I'm already logged in) and even once login

          been forward to other page. If I copy the link from the excel directly to the browser all works fine!

       

      More code from component.xml

       

      <event type="org.jboss.seam.security.notLoggedIn">
                          <action execute="#{redirect.captureCurrentView}"/>
      </event>
      <event type="org.jboss.seam.security.postAuthenticate">
                          <action execute="#{redirect.returnToCapturedView}"/>
      </event>
      
      

       

      I googled and couldn't find a good (elegant) solution for this probelm. Any ideas?

        • 1. Re: Elegant solution for "already logged in" user
          Luca Cavagnoli Newbie

          2. login-required="true": When clicking on the link I am being forwad to the login page which is incorreect (I'm already logged in)

           

          Maybe you are logged in in a browser window and when you click in the Excel link, another browser window is opened?

          • 2. Re: Elegant solution for "already logged in" user
            itay sahar Newbie

            of course. new window is normal. (new tab, to be precise) . When you are logged in, you have a session so each window (tab) is using the same session.

            The new window is opened with the same session (I can see the user details in the header) but the login page is shown anyway.

            This is happened only when you link from anywhere which is not a browser. (Excel is my private case) I thought I made myself clear in my first post though. ;-)

             

            That's a realy generic scenario that you expect seam will have a good solution/design for this.

            • 3. Re: Elegant solution for "already logged in" user
              itays100 Newbie

              Just for everyone with the same problem here is the solution that worked for me:

               

              My pages.xml looks like this now:

               

              <page view-id="/mypage.xhtml" login-required="true">

                        <begin-conversation join="true" />
                         
                      <param name="myid" value="#{sampleComponent.myid)}"/>
                      <action execute="#{sampleComponent.linkToObjectPage(myid)}" if="#{myid != null}"/>
                      <rewrite pattern="/mypage"/>

              </page>

               

              I uses request parameter annotation inside the seam component:

               

              @Name("sampleComponent")

              @Scope(ScopeType.CONVERSATION)

              public class SampleComponent

              {

               

              @RequestParameter("myId")

              public String myId;

               

              public String getMyId() {

                        return myId;

              }

               

              public void setMyId(String myId) {

                        this.myId = myId;

              }

               

              Added specific rule to the login page:

               

              <rule if="#{identity.loggedIn and identity.hasRole('someRole') and myId != null}">

                         <redirect view-id="/myPage.xhtml"/>

              </rule>

               

              Hope this help for anyone with the same issue.