Package org.forgerock.oauth2.core
Class Utils
- java.lang.Object
-
- org.forgerock.oauth2.core.Utils
-
public final class Utils extends Object
Utility class containing common utility functions.- Since:
- 12.0.0
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static OAuth2Constants.UrlLocationgetRequiredUrlLocation(Set<String> responseTypes, ClientRegistration clientRegistration)Determines if the UrlLocation is fragment or query based on the given response types and the type of client.static OAuth2Constants.UrlLocationgetRequiredUrlLocation(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.static booleanisEmpty(String s)Determines whether the specified String isnullor empty.static booleanisEmpty(Collection<?> c)Determines whether the specified Collection isnullor empty.static booleanisEmpty(Map<?,?> m)Determines whether the specified Map isnullor empty.static booleanisOAuth2FragmentErrorType(Set<String> requestedResponseTypes)When using the OAuth2 Implicit Grant the response_type value is "token".static booleanisOpenIdConnectClient(ClientRegistration clientRegistration)Check if the OAuth2 Client is configured to be an OpenId Connect Client.static booleanisOpenIdConnectFragmentErrorType(Set<String> requestedResponseTypes)When using the OpenId Connect authorization Implicit Flow the response_type value is "id_token token" or "id_token".static StringjoinScope(Set<String> scope)Joins the specifiedSetof scopes into a space delimited String.static Set<String>splitResponseType(String responseType)Splits the specified String of response types into aSetof response types.static Set<String>splitScope(String scope)Splits the specified String of scopes into aSetof scopes.static Set<String>stringToSet(String string)Splits the string on ' ' character and returns aSet<String>of the contents.
-
-
-
Method Detail
-
isEmpty
public static boolean isEmpty(String s)
Determines whether the specified String isnullor empty.- Parameters:
s- The String to check.- Returns:
trueif the String isnullor empty.
-
isEmpty
public static boolean isEmpty(Collection<?> c)
Determines whether the specified Collection isnullor empty.- Parameters:
c- The Collection to check.- Returns:
trueif the Collection isnullor empty.
-
isEmpty
public static boolean isEmpty(Map<?,?> m)
Determines whether the specified Map isnullor empty.- Parameters:
m- The Map to check.- Returns:
trueif the Map isnullor empty.
-
splitResponseType
public static Set<String> splitResponseType(String responseType)
Splits the specified String of response types into aSetof response types.
If the String of response types isnullan emptySetis returned.- Parameters:
responseType- The String of response types.- Returns:
- A
Setof response types.
-
splitScope
public static Set<String> splitScope(String scope)
Splits the specified String of scopes into aSetof scopes.
If the String of scopes isnullan emptySetis returned.- Parameters:
scope- The String of scopes.- Returns:
- A
Setof scopes.
-
joinScope
public static String joinScope(Set<String> scope)
Joins the specifiedSetof scopes into a space delimited String.
If the specifiedSetof 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 aSet<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 sortcomp- The comparator to use- Returns:
- A sorted list including all elements from the collection.
-
-