我想在该用户登录系统时更改用户名。我实现了自己的 crypt 算法,无法获得真实密码来进行新的身份验证并将其放入
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, credentials);
最佳答案
登录后,您可以使用以下代码更改您的用户名和密码:
Collection<SimpleGrantedAuthority> nowAuthorities =
(Collection<SimpleGrantedAuthority>)SecurityContextHolder.getContext()
.getAuthentication()
.getAuthorities();
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken(username, password, nowAuthorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
关于java - 登录时在 spring security 中更改用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29434209/