在我的junit中,我希望能够注销用户。
这是我的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);
}
如何使用类似的方法实现注销?
答案 0 :(得分:1)
根据SecurityContextHolder API你应该可以调用SecurityContextHolder.clearContext()
答案 1 :(得分:0)
SecurityContextHolder.getContext().setAuthentication(null);