i select WebWork as my web framework, i want to know if i can get user detail info from session. I woder where can i process in this situation.thanks
i select WebWork as my web framework, i want to know if i can get user detail info from session. I woder where can i process in this situation.thanks
SecureContext.getAuthentication().getPrincipal().g etUserName()
Don't forget to cast:
Code:((UserDetails) ((SecureContext) ContextHolder.getContext()).getAuthentication().getPrincipal()).getUsername();
Originally Posted by Ben Alex
Generally people use DaoAuthenticationProvider with Acegi Security, which puts the UserDetails returned by the AuthenticationDao into the Authentication object. If you have a look at the JavaDocs for the DaoAuthenticationProvider and AuthenticationDao, where the UserDetails comes from will make a lot more sense.
Hi All,
Ok, it's really easy to retrieve the UserDetails. But I want to write an app that isn't too much coupled with Spring.
Is there another way to retrieve the UserDetail from the session ? Maybe with something like
I have seen that the session has an attribute "SPRING_SECURITY_CONTEXT" of type org.springframework.security.context.SecurityConte xtImpl, is it bad to retrieve the context from the session ?Code:HttpSession session = request.getSession(); session.getAttribute("SPRING_USER_DETAILS");
If it is, why is it ? If it isn't is there a way to externalize that key ?
Edit : Actually I have written a static method into a personnal AuthorizationManager
, so if later my boss tell me to remove Spring from the project I have juste to rewrite this method. But I don't really like that.Code:public static User getPrincipal(HttpSession session) { // Do nothing with the session because Spring give us a better way to retrieve the principal return (User) ((SecurityContext) SecurityContextHolder.getContext()).getAuthentication().getPrincipal(); }
Last edited by blaiseg; Oct 24th, 2008 at 10:02 AM. Reason: What I do actually
thanks blaiseg. It works fine. you rescued mepublic static User getPrincipal(HttpSession session) {
// Do nothing with the session because Spring give us a better way to retrieve the principal
return (User) ((SecurityContext)
SecurityContextHolder.getContext()).getAuthenticat ion().getPrincipal();
}![]()