Package com.nimbusds.oauth2.sdk.util
Class URIUtils
java.lang.Object
com.nimbusds.oauth2.sdk.util.URIUtils
URI operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidensureQueryIsNotProhibited(URI uri, Set<String> prohibitedQueryParamNames) Ensures the query of the specified URI is not prohibited.static voidensureSchemeIsHTTPS(URI uri) Ensures the scheme of the specified URI is https.static voidEnsures the scheme of the specified URI is https or http.static voidensureSchemeIsNotProhibited(URI uri, Set<String> prohibitedURISchemes) Ensures the scheme of the specified URI is not prohibited.static URIgetBaseURI(URI uri) Gets the base part (schema, host, port and path) of the specified URI.static booleanisLocalHost(URI uri) Returnstrueif the specified URI is for a localhost,127.0.0.1IPv4 or::1/0:0:0:0:0:0:0:1address.static StringjoinPathComponents(String c1, String c2) Joins two path components.static StringPrepends a leading slash `/` if missing to the specified string.static URIprependPath(URI uri, String pathComponent) Prepends the specified path component to a URI.static URIremoveTrailingSlash(URI uri) Removes the trailing slash ("/") from the specified URI, if present.static StringStrips any leading slashes '/' if present from the specified string.static URIstripQueryString(URI uri) Strips the query string from the specified URI.toStringList(Collection<URI> uriList) Returns a string list representation of the specified URI collection.toStringList(Collection<URI> uriList, boolean ignoreNulls) Returns a string list representation of the specified URI collection.
-
Method Details
-
getBaseURI
Gets the base part (schema, host, port and path) of the specified URI.- Parameters:
uri- The URI. May benull.- Returns:
- The base part of the URI,
nullif the original URI isnullor doesn't specify a protocol.
-
prependPath
Prepends the specified path component to a URI. The prepended and any existing path component are always joined with a single slash ('/') between them- Parameters:
uri- The URI,nullif not specified.pathComponent- The path component to prepend,nullif not specified.- Returns:
- The URI with prepended path component,
nullif the original URI wasn't specified.
-
prependLeadingSlashIfMissing
Prepends a leading slash `/` if missing to the specified string.- Parameters:
s- The string,nullif not specified.- Returns:
- The string with leading slash,
nullif not originally specified.
-
stripLeadingSlashIfPresent
Strips any leading slashes '/' if present from the specified string.- Parameters:
s- The string,nullif not specified.- Returns:
- The string with no leading slash,
nullif not originally specified.
-
joinPathComponents
Joins two path components. If the two path components are notnullor empty they are joined so that there is only a single slash ('/') between them.- Parameters:
c1- The first path component,nullif not specified.c2- The second path component,nullif not specified.- Returns:
- The joined path components,
nullif both are not specified, or if one isnullthe other unmodified.
-
stripQueryString
Strips the query string from the specified URI.- Parameters:
uri- The URI. May benull.'- Returns:
- The URI with stripped query string,
nullif the original URI isnullor doesn't specify a protocol.
-
removeTrailingSlash
Removes the trailing slash ("/") from the specified URI, if present.- Parameters:
uri- The URI. May benull.- Returns:
- The URI with no trailing slash,
nullif the original URI isnull.
-
ensureSchemeIsHTTPS
Ensures the scheme of the specified URI is https.- Parameters:
uri- The URI to check,nullif not specified.- Throws:
IllegalArgumentException- If the URI is specified and the scheme is not https.
-
ensureSchemeIsHTTPSorHTTP
Ensures the scheme of the specified URI is https or http.- Parameters:
uri- The URI to check,nullif not specified.- Throws:
IllegalArgumentException- If the URI is specified and the scheme is not https or http.
-
ensureSchemeIsNotProhibited
Ensures the scheme of the specified URI is not prohibited.- Parameters:
uri- The URI to check,nullif not specified.prohibitedURISchemes- The prohibited URI schemes (should be in lower case), empty ornullif not specified.- Throws:
IllegalArgumentException- If the URI is specified and its scheme is prohibited.
-
ensureQueryIsNotProhibited
Ensures the query of the specified URI is not prohibited.- Parameters:
uri- The URI to check,nullif not specified.prohibitedQueryParamNames- The prohibited query parameter names, empty ornullif not specified.- Throws:
IllegalArgumentException- If the URI is specified and includes prohibited query parameter names.
-
toStringList
Returns a string list representation of the specified URI collection. Collection items that arenullare not returned.- Parameters:
uriList- The URI collection,nullif not specified.- Returns:
- The string list,
nullif not specified.
-
toStringList
Returns a string list representation of the specified URI collection.- Parameters:
uriList- The URI collection,nullif not specified.ignoreNulls-trueto not includenullvalues.- Returns:
- The string list,
nullif not specified.
-
isLocalHost
Returnstrueif the specified URI is for a localhost,127.0.0.1IPv4 or::1/0:0:0:0:0:0:0:1address.- Parameters:
uri- The URI. Must not benull.- Returns:
trueif the URI is for a localhost, elsefalse.
-