How to check user authority or permission in Java Code ? For example - I want to show or hide button for user depending on role. There are annotations like:
Instead of using a loop to find the authority from UserDetails you can do:
Collection extends GrantedAuthority> authorities = authentication.getAuthorities(); boolean authorized = authorities.contains(new SimpleGrantedAuthority("ROLE_ADMIN"));