Results 1 to 2 of 2

Thread: Using spring security classes get User ID from DB and use it in application.

  1. #1
    Join Date
    Feb 2009
    Posts
    3

    Default 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. #2
    Join Date
    Feb 2009
    Posts
    3

    Default

    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
  •