-
Mar 15th, 2012, 12:43 PM
#1
Using spring security classes get User ID from DB and use it in application.
Hi All,
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 =
(UserDetails)SecurityContextHolder.getContext().ge tAuthentication().getPrincipal();
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();
authToken.setDetails(userDAO.getId());
Please help me how can i get user id over the application.
Thanks,
Learner
-
Mar 16th, 2012, 08:24 AM
#2
Hi All,
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.
Thanks,
Learner
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules