SecurityUtil

public final class SecurityUtil

The SecurityUtil class provides helper methods to retrieve logged user details, such as username, roles or permissions

Methods

getUserPermissions

public static Set<String> getUserPermissions()

Returns authenticated user’s permissions. It will return empty set, in case there’s no active authentication or if the current user does not have any permissions assigned.

Returns:set of permissions assigned to the current user

getUserRoles

public static List<String> getUserRoles()

Returns authenticated user’s roles. It will return empty list, in case there’s no active authentication or if the current user does not have any roles assigned.

Returns:list of roles assigned to the current user

getUsername

public static String getUsername()

Retrieves current username from the Spring security context. Returns null, if there’s no active authentication object.

Returns:username or null, if no user is authenticated