4 Replies Latest reply on Aug 16, 2005 11:01 AM by Tremal Naik

    Retrieving user name

    Tremal Naik Newbie

      Hi, I'm trying to retrieve the name of the user who is currently logged, but I can't get it from the request.

      I read a lot of documentation, I swear, but I was not able to figure it out, maybe it's really simple.

      How can I access this information?

      Thanks

        • 1. Re: Retrieving user name
          Ashwin Kumar Karkala Newbie

          My guess is that in your JSP/servlet, the call to request.getUserPrincipal() is returning null.
          If you are using a custom login module then you need to define a group named "CallerPrincipal" to which you can add your Principal impl class. If you do this then the request.getUserPrincipal() returns your custom Principal impl (of course you will need to cast it to your impl class).

          HTH
          Ashwin Karkala

          • 2. Re: Retrieving user name
            Tremal Naik Newbie

            No, I'm able to fetch the user name from request, if I am in a JSP or whetever I can have access to the http request. I need to fetch user name if I don't have access to the request, i.e., from an helper class.

            Is it possible doing it calling methods on mbean server service or security manager? I wasn't able to figure it out

            thanks

            • 3. Re: Retrieving user name
              Soheil Hassas Yeganeh Newbie

              May be this works for you!
              SecurityAssociation.getPrincipal().getName()

              • 4. Re: Retrieving user name
                Tremal Naik Newbie

                your method is simpler then what I figured out, certailnly:

                Context securityCtx = null;
                AuthenticationManager securityMgr = null;
                InitialContext iniCtx = new InitialContext();
                securityCtx = (Context) iniCtx.lookup("java:comp/env/security");
                securityMgr = (AuthenticationManager) securityCtx.lookup("securityMgr");
                Subject subject = securityMgr.getActiveSubject();
                return subject.getPrincipals();


                I'll try it, thanks