1 2 Previous Next 25 Replies Latest reply on Aug 10, 2007 2:55 PM by kpalania Go to original post
      • 15. Re: Cannot retrieve user: Unable to locate current JTA trans
        soshah

        Indy-

        Here is some information related Portal Login Modules

        http://docs.jboss.com/jbportal/v2.6/referenceGuide/html/authentication.html

        Thanks

        • 16. Re: Cannot retrieve user: Unable to locate current JTA trans
          soshah

          krish-


          I have a servlet implemented that uses the LoginContext and invokes my security realm. It passes through the various login modules and authentication succeeds. However, JBoss Portal throws an authorization exception as the principals were never set.


          Again, whats the reason for creating your own security realm being invoked by a servlet instead of using JBoss Portal's built-in security realm and just integrating your LoginModules into this realm instead of the out-of-the-box JBoss Portal Login Modules?

          Reason I ask is Portal depends on the entire JAAS integration with Tomcat that populates all the Subjects etc on authentication. This integration AFAIK cannot be done inside the Servlet Environment. You will have to get to a lower level inside of Tomcat which would be using a Valve/Authenticator approach.

          This approach is not a hack, but its definitely not trivial, so unless there is a really good reason to inject your own security realm, I would recommend integrating with JBoss Portal's security realm with your custom LoginModules.

          Thanks

          • 17. Re: Cannot retrieve user: Unable to locate current JTA trans
            kpalania

            Sohil,
            The reason I need to use my own security realm is because this realm is shared by more than one application and JBoss Portal is just one of the applications deployed in JBoss that uses this shared realm.

            The way I've implemented this -
            * There is a shared security realm (and possibly, more than 1 at some point) used by multiple applications.
            * I also have a use case for bypassing security (trusted application scenario, etc.), so I can't rely on container managed security and j_security_check as it would ALWAYS challenge the user and I don't want that in certain cases.
            * So, I moved to using my own Servlet and have that do something like this:

            UsernamePasswordHandler handler = new UsernamePasswordHandler(username,
             password);
             LoginContext context = new LoginContext("SecurityRealmName", handler);
             context.login();


            * This works for my application but it doesn't for JBoss Portal though the authentication succeeds.
            * Enabling trace logging, I can tell that the principals are not being set and hence, the JBoss Portal authorization fails.

            • 18. Re: Cannot retrieve user: Unable to locate current JTA trans
              kpalania

              "I would recommend integrating with JBoss Portal's security realm with your custom LoginModules. "

              What do you exactly mean by this? JBoss Portal uses a "portal" security realm that uses the JBoss OOTB login modules. I've used my own security realm and that works just fine if I use container managed security (a.k.a j_security_check). So, the issue is not with the use of a new,custom security realm but rather the lack of using container managed security and using my servlet.

              So, if there is an issue, it is not with using a custom security realm but with using a Servlet and invoking the LoginModule explicitly? Correct? Want to ensure that both of us are on the same page.

              • 19. Re: Cannot retrieve user: Unable to locate current JTA trans
                soshah

                Yes you are correct. New security realm is not the issue. Its inability of the Servlet Environment to properly populate the security information needed by JBoss Portal.

                In fact why dont you try swicthing the portal security realm to your custom/shared security realm and its LoginModules. You will still need to use the deep JAAS/container managed approach, but you will be using the security realm which is shared by all your applications.

                You should be able to do this by:

                1/ Modify <application-policy name="portal"> inside jboss-portal.sar/conf/login-config.xml to
                <application-policy name="{your security realm here}">

                2/ Inside jboss-portal.sar/portal-server.war/WEB-INF/jboss-web.xml make <security-domain>java:jaas/portal</security-domain> to <security-domain>java:jaas/{your security realm here}</security-domain>

                Note: even with this approach you will still need to use the container based/j_security approach for Portal to be properly populated with the security information.

                btw- I have never tried swapping the realm this way for Portal. This is in theory, so let us know if this actually works ;)

                Thanks

                • 20. Re: Cannot retrieve user: Unable to locate current JTA trans
                  kpalania

                   

                  "sohil.shah@jboss.com" wrote:
                  Yes you are correct. New security realm is not the issue. Its inability of the Servlet Environment to properly populate the security information needed by JBoss Portal.

                  In fact why dont you try swicthing the portal security realm to your custom/shared security realm and its LoginModules. You will still need to use the deep JAAS/container managed approach, but you will be using the security realm which is shared by all your applications.

                  You should be able to do this by:

                  1/ Modify <application-policy name="portal"> inside jboss-portal.sar/conf/login-config.xml to
                  <application-policy name="{your security realm here}">

                  2/ Inside jboss-portal.sar/portal-server.war/WEB-INF/jboss-web.xml make <security-domain>java:jaas/portal</security-domain> to <security-domain>java:jaas/{your security realm here}</security-domain>

                  Note: even with this approach you will still need to use the container based/j_security approach for Portal to be properly populated with the security information.

                  btw- I have never tried swapping the realm this way for Portal. This is in theory, so let us know if this actually works ;)

                  Thanks


                  Sohil,
                  This is exactly how I have it now. It is working as I expected it to. And I've had this working this way for a while.

                  However, as I mentioned earlier, the requirements changed and for some other reasons, I can't do that anymore and I need to be able to explicitly invoke the login module. This is where the problem creeps up.

                  I disabled container managed security for app #1 that is also deployed in JBoss and uses the shared security realm. All works well because that is our app and we control the authorization.

                  It doesn't work for app#2 (using JBoss Portal) as the authorization is beyond my control. Actually, I even ran into a NPE from the JBoss Portal code (a Portal bug that I need to file a jira issue for) but I managed to get past it by doing some hacks. However, I am now at the point where the subject doesn't contain any principals.

                  The only, last thing I need is a way to add the principals to the subject. How do I get a handle to the subject so that I can add the principals, is the million dollar question at this point....

                  Have spent hours on this (identify the NPE, finding a hack for it, etc.) so any solutions to this would be immensely helpful and truly appreciated!!

                  • 21. Re: Cannot retrieve user: Unable to locate current JTA trans
                    kpalania

                    Okay, one step further. This is what I need:

                    public boolean checkPermission(PortalPermission permission) throws IllegalArgumentException, PortalSecurityException
                     {
                     try
                     {
                     // Get the current authenticated subject through the JACC contract
                     Subject subject = (Subject)PolicyContext.getContext("javax.security.auth.Subject.container");
                    
                     //
                     return checkPermission(subject, permission);
                     }
                     catch (PolicyContextException e)
                     {
                     throw new PortalSecurityException(e);
                     }
                     }


                    This is the API in org.jboss.portal.security.impl.jacc.JACCPortalAuthorizationManager. If I can get this subject to be populated in my servlet, I am COOL!

                    Essentially, I need to be able to set the subject to this "javax.security.auth.Subject.container" context. I could even create a new instance of the Subject and add the necessary principals manually, so long as there is a way to actually make the container use that subject by setting this context variable.

                    • 22. Re: Cannot retrieve user: Unable to locate current JTA trans
                      soshah

                      ah ok-

                      I understand your situation now.

                      Ok in this case you have no choice but to go the Tomcat Valve/Custom Authenticator route.

                      This is the only place you can actually grab hold of the Tomcat Session and populate it with the Subject/Principals that will be propagated through to Portal.

                      Basically you have to simulate what the container managed security is doing inside of your own code, and not use container managed security.

                      The sample interaction would be something like:

                      1/ You have a Tomcat Valve that post-processes the request on your Authentication Servlet

                      2/ In this Post Processing, it will grab information populated by the Servlet and populate the Principal/Subject just the way the container does for Portal when using standard JAAS mechanism

                      For a look at how this is done, look at the Authenticator source code of Tomcat and you will be very much enlightened ;)

                      Thanks

                      • 23. Re: Cannot retrieve user: Unable to locate current JTA trans
                        kpalania

                        ..and my guess is that after the authentication happens, the PolicyContext is set for "javax.security.auth.Subject.container" but this happens in a different thread. Therefore, when I do a servlet forward, this subject is not found as this is a new/different thread..

                        • 24. Re: Cannot retrieve user: Unable to locate current JTA trans
                          kpalania

                           

                          "sohil.shah@jboss.com" wrote:
                          ah ok-

                          I understand your situation now.

                          Ok in this case you have no choice but to go the Tomcat Valve/Custom Authenticator route.

                          This is the only place you can actually grab hold of the Tomcat Session and populate it with the Subject/Principals that will be propagated through to Portal.

                          Basically you have to simulate what the container managed security is doing inside of your own code, and not use container managed security.

                          The sample interaction would be something like:

                          1/ You have a Tomcat Valve that post-processes the request on your Authentication Servlet

                          2/ In this Post Processing, it will grab information populated by the Servlet and populate the Principal/Subject just the way the container does for Portal when using standard JAAS mechanism

                          For a look at how this is done, look at the Authenticator source code of Tomcat and you will be very much enlightened ;)

                          Thanks


                          Thanks Sohil. Let me look into the Tomcat source code and see if I can do something similar to get this working. Will let you know how goes by COB and hopefully, it goes well....

                          • 25. Re: Cannot retrieve user: Unable to locate current JTA trans
                            kpalania

                            "Ok in this case you have no choice but to go the Tomcat Valve/Custom Authenticator route. "

                            Sohil - thanks very much for suggesting this! I've successfully implemented a custom Tomcat Authenticator/Value, and that solves the problem, and I've been able to achieve exactly what I wanted.

                            Needless to mention, some hacks were required but it ultimately works!!

                            Cool, thanks again!

                            1 2 Previous Next