Class Utils


  • public final class Utils
    extends Object
    Utility class containing common utility functions.
    Since:
    12.0.0
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(String s)
        Determines whether the specified String is null or empty.
        Parameters:
        s - The String to check.
        Returns:
        true if the String is null or empty.
      • isEmpty

        public static boolean isEmpty​(Collection<?> c)
        Determines whether the specified Collection is null or empty.
        Parameters:
        c - The Collection to check.
        Returns:
        true if the Collection is null or empty.
      • isEmpty

        public static boolean isEmpty​(Map<?,​?> m)
        Determines whether the specified Map is null or empty.
        Parameters:
        m - The Map to check.
        Returns:
        true if the Map is null or empty.
      • splitResponseType

        public static Set<String> splitResponseType​(String responseType)
        Splits the specified String of response types into a Set of response types.
        If the String of response types is null an empty Set is returned.
        Parameters:
        responseType - The String of response types.
        Returns:
        A Set of response types.
      • splitScope

        public static Set<String> splitScope​(String scope)
        Splits the specified String of scopes into a Set of scopes.
        If the String of scopes is null an empty Set is returned.
        Parameters:
        scope - The String of scopes.
        Returns:
        A Set of scopes.
      • joinScope

        public static String joinScope​(Set<String> scope)
        Joins the specified Set of scopes into a space delimited String.
        If the specified Set of scopes is null, an empty String is returned.
        Parameters:
        scope - The scopes to join.
        Returns:
        A String of the joined scopes.
      • stringToSet

        public static Set<String> stringToSet​(String string)
        Splits the string on ' ' character and returns a Set<String> of the contents.
        Parameters:
        string - The string.
        Returns:
        A Set<String>.
      • isOpenIdConnectFragmentErrorType

        public static boolean isOpenIdConnectFragmentErrorType​(Set<String> requestedResponseTypes)
        When using the OpenId Connect authorization Implicit Flow the response_type value is "id_token token" or "id_token". When using the Hybrid Flow, this value is "code id_token", "code token", or "code id_token" token.
        Returns:
        True if the request is part of an OpenId Connect authorization Implicit Flow or Hybrid Flow.
        See Also:
        3.2.2.1. Authentication Request, 3.3.2.1. Authentication Request
      • isOAuth2FragmentErrorType

        public static boolean isOAuth2FragmentErrorType​(Set<String> requestedResponseTypes)
        When using the OAuth2 Implicit Grant the response_type value is "token".
        Returns:
        True if the request is part of an OAuth2 Implicit Grant.
        See Also:
        4.2.2.1. Error Response
      • isOpenIdConnectClient

        public static boolean isOpenIdConnectClient​(ClientRegistration clientRegistration)
        Check if the OAuth2 Client is configured to be an OpenId Connect Client.
        Parameters:
        clientRegistration - The registered client.
        Returns:
        True if the client is configured as an OpenId Connect client.
      • getRequiredUrlLocation

        public static OAuth2Constants.UrlLocation getRequiredUrlLocation​(OAuth2Request request,
                                                                         ClientRegistration clientRegistration)
        Determines if the UrlLocation is fragment or query based on the response types read from the request and the type of client.
        Parameters:
        request - The OAuth2 request.
        clientRegistration - The ClientRegistration.
        Returns:
        UrlLocation.FRAGMENT or UrlLocation.QUERY
      • getRequiredUrlLocation

        public static OAuth2Constants.UrlLocation getRequiredUrlLocation​(Set<String> responseTypes,
                                                                         ClientRegistration clientRegistration)
        Determines if the UrlLocation is fragment or query based on the given response types and the type of client.
        Parameters:
        responseTypes - The requested response types.
        clientRegistration - The registered client.
        Returns:
        UrlLocation.FRAGMENT or UrlLocation.QUERY
      • asSortedList

        public static <T extends Comparable<? super T>> List<T> asSortedList​(Collection<T> collection,
                                                                             Comparator<? super T> comp)
        Converts a collection of comparable items into a list, using the given comparator to order the items.
        Type Parameters:
        T - The type of the collection.
        Parameters:
        collection - The collection to sort
        comp - The comparator to use
        Returns:
        A sorted list including all elements from the collection.