Class SecurityContextUtil


  • public class SecurityContextUtil
    extends Object
    The Class SecurityContextUtil.
    • Field Detail

      • LOG

        public static final org.slf4j.Logger LOG
        The Constant LOG.
    • Constructor Detail

      • SecurityContextUtil

        public SecurityContextUtil()
    • Method Detail

      • getUsername

        public static String getUsername()
        Gets the username.
        Returns:
        the username
      • getMe

        public static <T extends BasicUser<?>> T getMe()
        Gets the me.
        Type Parameters:
        T - the generic type
        Returns:
        current user
      • getCurrentUser

        public static <T extends AclSid> T getCurrentUser()
        Gets the current principal (User or OAuthClient).
        Type Parameters:
        T - the generic type
        Returns:
        the current security principal
      • hasRole

        public static boolean hasRole​(String role)
        Checks for role.
        Parameters:
        role - the role
        Returns:
        true, if successful
      • hasAnyRole

        public static boolean hasAnyRole​(String... roles)
        Checks if any role is granted.
        Parameters:
        roles - the roles
        Returns:
        true, if successful
      • hasAuthority

        public static boolean hasAuthority​(String authorityName)
        Check if authority is granted.
        Parameters:
        authorityName - the authority name
        Returns:
        true, if successful
      • hasPermission

        public static boolean hasPermission​(Object targetDomainObject,
                                            Object permission)
        Checks for permission.
        Parameters:
        targetDomainObject - the target domain object
        permission - the permission
        Returns:
        true, if successful
      • hasPermission

        public static boolean hasPermission​(org.springframework.security.core.Authentication auth,
                                            Object targetDomainObject,
                                            Object permission)
        Checks for permission.
        Parameters:
        auth - authentication object
        targetDomainObject - the target domain object
        permission - the permission
        Returns:
        true, if successful
      • anyoneHasPermission

        public static boolean anyoneHasPermission​(Object targetDomainObject,
                                                  Object permission)
        Check if ROLE_EVERYONE has permission on target object.
        Parameters:
        targetDomainObject - the target domain object
        permission - the permission
        Returns:
        true, if successful
      • getOAuthClientId

        public static String getOAuthClientId()
        Gets the OAuth Client ID of the current authentication object.
        Returns:
        the OAuth client ID