Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your friend here is <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/context/request/RequestContextHolder.html" rel="noreferrer"><code>org.springframework.web.context.request.RequestContextHolder</code></a></p> <pre><code>// example usage public static HttpSession session() { ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); return attr.getRequest().getSession(true); // true == allow create } </code></pre> <p>This will be populated by the standard spring mvc dispatch servlet, but if you are using a different web framework you have add <code>org.springframework.web.filter.RequestContextFilter</code> as a filter in your <code>web.xml</code> to manage the holder.</p> <p><strong>EDIT</strong>: just as a side issue what are you actually trying to do, I'm not sure you should need access to the <code>HttpSession</code> in the <code>retieveUser</code> method of a <code>UserDetailsService</code>. Spring security will put the UserDetails object in the session for you any how. It can be retrieved by accessing the <code>SecurityContextHolder</code>:</p> <pre><code>public static UserDetails currentUserDetails(){ SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); if (authentication != null) { Object principal = authentication.getPrincipal(); return principal instanceof UserDetails ? (UserDetails) principal : null; } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload