2017-03-07 2 views
1

저는 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; 
} 

답변

0

그래서 대답은 다음과 같습니다과 보안 조건 기본적으로 Spring은 세션 ID를 변경합니다. 이러한 동작을 방지하려면 Spring Security 구성에서 세션 고정 보호를 비활성화해야합니다. 더 많은 정보 by link

관련 문제