Mar 15th, 2012, 12:43 PM
Using spring security classes get User ID from DB and use it in application.
I am new to spring security; I am trying to apply security to my application. I want to get User id from the database and make it available in the application.
1. I tried extending User class. When tried Retrieving my custom user class thru spring context Principal object I am getting Type cast exception.
UserDetails userDetails =
2. I tried implementing UserDetailsManager interface and getting the values from database. I could not get this class over the application.
I finally used the below code in my main controller and accessing the id in application.
AbstractAuthenticationToken authToken = (AbstractAuthenticationToken)SecurityContextHolder .getContext().getAuthentication();
Please help me how can i get user id over the application.
Mar 16th, 2012, 08:24 AM
I have resolved the above issue by Implementing custom UserDetailsManager.
Returning custom User object from custom UserDetailsManager.
If there is any other way please post.