在我的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);
}
如何使用类似的方法实现注销?
最佳答案
根据SecurityContextHolder API,您应该能够调用SecurityContextHolder.clearContext()