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:
You can get some help from AuthorityUtils class. Checking role as a one-liner:
if (AuthorityUtils.authorityListToSet(SecurityContextHolder.getContext().getAuthentication().getAuthorities()).contains("ROLE_MANAGER")) { /* ... */ }
Caveat: This does not check role hierarchy, if such exists.