Thymeleaf:通过注册页面而不是/ login登录用户

时间:2016-02-08 09:08:04

标签: spring-boot thymeleaf

到目前为止,我知道它可以自动运行, 但如果我通过某个标志页面创建了新用户,则不知道如何使用它。现在,而不是让用户再次登录页面。 有没有办法在注册时自动登录用户。

1 个答案:

答案 0 :(得分:1)

作为注册用户的一部分,您可以手动将新的身份验证对象填充到SecurityContextHolder中。这将使用户不​​必手动登录。

// build authentication token based on the username and password provided Collection authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("user")); Authentication auth = new UsernamePasswordAuthenticationToken(email, password, authorities); // set authentication in context SecurityContextHolder.getContext().setAuthentication(auth);

相关问题