I’m trying to get a list of the current roles of the logged in user that I can use to fill in a table. However I cannot seem to get them as a list. I can get other user details such as logged in username.
Hi,
You can get a current user using the CurrentAuthentication. Then you can do the following to get the roles list:
User user = (User) currentAuthentication.getUser();
Set<String> roleCodes = user.getAuthorities().stream()
.filter(authority -> authority instanceof RoleGrantedAuthority)
.map(authority -> ((RoleGrantedAuthority) authority).getAuthority())
.collect(Collectors.toSet());