Announcement Announcement Module
Collapse
No announcement yet.
Using spring security classes get User ID from DB and use it in application. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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

    Comment

    Working...
    X