public static boolean allowRoleInSecurityContext ( final String role ) { boolean result = false ; final SecurityContext context = SecurityContextHolder . getContext ( ) ; if ( context != null && context . getAuthentication ( ) != null ) { final Collection < ? extends GrantedAuthority > authorities = context . getAuthentication ( ) . getAuthorities ( ) ; for ( final GrantedAuthority grantedAuthority : authorities ) { if ( role . equalsIgnoreCase ( grantedAuthority . getAuthority ( ) ) ) { result = true ; } } } return result ; }
Allow role in security context .