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).
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
May be this works for you!
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