저는 Spring Security를 사용하며 로그인하는 동안 프레임 워크의 이상한 동작을 발견했습니다. Spring Security WebAuthenticationDetails
은 HTTP 요청으로부터 얻은 sessionId
파라미터를 가지고 있으며, 모두 좋다. 그러나 사실 REST 요청은 나에게 또 다른 세션 id를 준다. HttpSession
을 autowire하고 세션 ID를 얻으면 Spring과 같은 ID를 얻습니다. 그래서 한 명의 사용자에 대해 두 개의 ID가있는 것으로 보입니다. 맞습니까? 또는 나는 무엇인가 놓쳤다?Autowiring HttpSession은 HttpServletRequest와 다른 객체를 제공합니다.
편집 :이 클래스의 뜻이이 방법을 줄 것이다
public class AuthenticationEventListener implements ApplicationListener<AbstractAuthenticationEvent> {
@Autowired
HttpSession httpSession;
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
if (event instanceof AuthenticationSuccessEvent) {
LoggedUser loggedUser = (LoggedUser) event.getAuthentication().getPrincipal();
loggedUser.initSessionParams(event.getAuthentication());
String sessionId = httpSession.getId();
}
}
}
일부 세션 ID를 준 예를 들어
다른 하나
@RequestMapping(value = "/chart")
public Map getTestStatusesChart(HttpServletRequest request) {
String sessionId= request.getSession(false).getId();
return null;
}