Class NtsSecurityUtils

  • All Implemented Interfaces:
    org.springframework.beans.factory.InitializingBean

    @Component
    public final class NtsSecurityUtils
    extends Object
    implements org.springframework.beans.factory.InitializingBean
    Utility class for Spring Security.
    • Constructor Detail

      • NtsSecurityUtils

        public NtsSecurityUtils​(@Value("${nts.security.oauth2.client.configuration.roles-claim:roles}")
                                String rolesClaim,
                                @Value("${nts.security.oauth2.client.configuration.role-prefix:ROLE_}")
                                String rolePrefix,
                                @Value("${nts.security.oauth2.client.configuration.reverse-order-of-display-name:true}")
                                boolean reverseOrderOfDisplayName)
    • Method Detail

      • getCurrentUserLogin

        public static Optional<String> getCurrentUserLogin()
        Get the login of the current user.
        Returns:
        the login of the current user.
      • getCurrentUserDisplayName

        public static Optional<String> getCurrentUserDisplayName()
        Get the display name of the current user.
        Returns:
        the display name of the current user.
      • isAuthenticated

        public static boolean isAuthenticated()
        Check if a user is authenticated.
        Returns:
        true if the user is authenticated, false otherwise.
      • hasCurrentUserAnyOfAuthorities

        public static boolean hasCurrentUserAnyOfAuthorities​(String... authorities)
        Checks if the current user has any of the authorities.
        Parameters:
        authorities - the authorities to check.
        Returns:
        true if the current user has any of the authorities, false otherwise.
      • hasCurrentUserNoneOfAuthorities

        public static boolean hasCurrentUserNoneOfAuthorities​(String... authorities)
        Checks if the current user has none of the authorities.
        Parameters:
        authorities - the authorities to check.
        Returns:
        true if the current user has none of the authorities, false otherwise.
      • hasCurrentUserThisAuthority

        public static boolean hasCurrentUserThisAuthority​(String authority)
        Checks if the current user has a specific authority.
        Parameters:
        authority - the authority to check.
        Returns:
        true if the current user has the authority, false otherwise.
      • extractAuthorityFromClaims

        public static List<org.springframework.security.core.GrantedAuthority> extractAuthorityFromClaims​(Map<String,​Object> claims)
      • afterPropertiesSet

        public void afterPropertiesSet()
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean