Announcement Announcement Module
Collapse
No announcement yet.
Preferred way to access Request,Response and Session Object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Preferred way to access Request,Response and Session Object

    Hi All,

    We are using Spring security for our application to handle user Authentication.I am working on some other stuff where i need to access HTTP Session object to perform some operations.
    I need this Session object in my service layer and i have the following way to access this
    1. Pass HTTP Session from Controller
    2. Use Spring Security to access those Objects

    What can be the beat way to achieve this? Should i reply on passing Session object from my Controller to Service layer or is there a thread safe way to access it in my Service Layer with the help of Spring Security?

    I read something about
    Code:
    SecurityContextHolder
    , but not sure how applicable it is for my case.

  • #2
    You can receive an Authentication object in your controller method (just declare it as an argument). This authentication object will provide you with a getPrincipal() method (I think it returns an UserDetails) containing all the relevant information spring security keeps inside the session (username, authorities and so on). Of course, if you write your own UserDetailsService, more information could be saved into the session after the user gets authenticated.

    I think you should avoid passing HttpSession objects to the service layer.

    Comment

    Working...
    X