white knight

导航

 
参考https://stackoverflow.com/questions/36937414/auto-login-spring-security

UserDetails userDetails = userDetailsService.loadUserByUsername(username);
Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
posted on 2018-03-14 14:44  white knight  阅读(369)  评论(0编辑  收藏  举报