2013-12-11 2 views
0

내 junit에서 나는 사용자를 로그 아웃하고 싶습니다.봄 보안 코드를 통한 로그 아웃

protected void loginPlayer(String loginName) { 

System.out.println("Logging in player: " + loginName); 
Player player = this.playerRepository.findPlayerByLoginName(loginName); 
UserDetails playerSession = new PlayerSession(player.getId(), loginName, player.getPassword()); 
Authentication auth = new UsernamePasswordAuthenticationToken(playerSession, null, playerSession.getAuthorities()); 
SecurityContextHolder.getContext().setAuthentication(auth); 
} 

내가 어떻게 유사한 방법을 사용하여 로그 아웃을 달성 할 : 여기

내 JUnit을 로그인 기능입니까?

답변

1

당신이 SecurityContextHolder.clearContext를 호출 할 수 있어야 SecurityContextHolder API에 따르면() 모든 세션을 지 웁니다

+0

? 특정 사용자 세션 만 지우고 싶습니다. – Urbanleg

+0

그러면 현재 스레드의 보안 컨텍스트가 지워집니다. 스프링 보안 인증은 스레드 바운드이므로이 예제에서 보여준 사용자 인증은 무효화됩니다. 모든 세션을 지우는 –

0
SecurityContextHolder.getContext().setAuthentication(null); 
+0

? 특정 사용자 세션 만 지우고 싶습니다. – Urbanleg

관련 문제