I would like to change the role of the user. Changing role of the user in the database. Everything is based on Spring Security.
My code:
UserDetails user = userDetailsManager.loadUserByUsername(userData.getUser().getUsername());
user.getAuthorities().add(new SimpleGrantedAuthority(role));
userDetailsManager.updateUser(user);
Error:
Error:(99, 30) java: method add in interface java.util.Collection<E> cannot be applied to
given types;
required: capture#1 of ? extends org.springframework.security.core.GrantedAuthority
found: org.springframework.security.core.authority.SimpleGrantedAuthority
reason: actual argument
org.springframework.security.core.authority.SimpleGrantedAuthority cannot be converted to
capture#1 of ? extends org.springframework.security.core.GrantedAuthority by method
invocation conversion
I don't know why is this error. How can otherwise change the role for the user?