0
当用户正在注册时,我正尝试在同一步骤对其进行身份验证。我在网上看了看四周,这似乎是这样做的方式:Spring Security未设置JSESSIONID Cookie
UserDetails userDetails userDetailsService.loadUserByUsername(username);
// Set authenticated
Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities());
authenticationManager.authenticate(auth);
if (auth.isAuthenticated()){
// This is hit every time, seemingly signaling
// that authentication is happening
SecurityContextHolder.getContext().setAuthentication(auth);
}
然而,这不设置JSESSIONID的cookie,因此用户试图第一次访问受保护的资源,他们必须再次登录。有关如何解决这个问题的任何想法?我正在使用Spring Security的4.0.1.RELEASE版本。
我也设置在我的配置下,但我不知道这是否可能与:
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
http.sessionManagement().maximumSessions(1);
http.sessionManagement().sessionFixation().migrateSession();