简体   繁体   English

Spring Security通过会话ID获取登录用户

[英]Spring Security Get logged user by session id

Recently I am trying to get existing logged user by JSESSIONID with Spring Security. 最近,我试图通过Spring Security通过JSESSIONID获取现有的登录用户。 After tracing the source code I still cannot find the way to do this. 跟踪源代码后,我仍然找不到执行此操作的方法。 Is it possible? 可能吗? Where Spring Security store the mapping between JSESSIONID and AuthUser? Spring Security在哪里存储JSESSIONID和AuthUser之间的映射?

Any help will be very appreciated. 任何帮助将不胜感激。

Something like this: 像这样:

@RequestMapping(value = "/userAndSession/{providedSessionId}", method = RequestMethod.GET)
public String getUserAndSessionId(UsernamePasswordAuthenticationToken principal,
            HttpServletRequest httpServletRequest, @PathVariable("providedSessionId") String sessionID) {
    // Session ID
    String sessionId = httpServletRequest.getRequestedSessionId();

    if(sessionId.equals(providedSessionId)) {
        // Username 
        String name = principal.getName();
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM