I want to change username while this user logged in system. I implemented my own crypt algorithm and cannot get real password to make a new authentication and put it in
Authentication authentication = new UsernamePasswordAuthenticationToken(principal, credentials);
Why does the session Id change when I authenticate through Spring Security? With the default configuration, Spring Security invalidates the existing session when the user authenticates and creates a new one, transferring the session data to it.
After Logging in, you can change your username and password with this code:
Collection<SimpleGrantedAuthority> nowAuthorities =
(Collection<SimpleGrantedAuthority>)SecurityContextHolder.getContext()
.getAuthentication()
.getAuthorities();
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken(username, password, nowAuthorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With