Class OAuthClientUtils
- java.lang.Object
-
- org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils
-
public final class OAuthClientUtils extends Object
The utility class for simplifying working with OAuth servers
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcreateAuthorizationHeader(ClientAccessToken accessToken)Creates OAuth Authorization header with Bearer schemestatic StringcreateAuthorizationHeader(ClientAccessToken accessToken, HttpRequestProperties httpProps)Creates OAuth Authorization header with the scheme that may require an access to the current HTTP request propertiesstatic ClientAccessTokenfromMapToClientToken(Map<String,String> map)static ClientAccessTokenfromMapToClientToken(Map<String,String> map, String defaultTokenType)static ClientAccessTokengetAccessToken(String accessTokenServiceUri, Consumer consumer, AccessTokenGrant grant, boolean setAuthorizationHeader)Obtains the access token from OAuth AccessToken Servicestatic ClientAccessTokengetAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant)Obtains the access token from OAuth AccessToken Service using the initialized web clientstatic ClientAccessTokengetAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant, boolean setAuthorizationHeader)Obtains the access token from OAuth AccessToken Service using the initialized web clientstatic ClientAccessTokengetAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant, Map<String,String> extraParams, boolean setAuthorizationHeader)Obtains the access token from OAuth AccessToken Service using the initialized web clientstatic ClientAccessTokengetAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant, Map<String,String> extraParams, String defaultTokenType, boolean setAuthorizationHeader)Obtains the access token from OAuth AccessToken Service using the initialized web clientstatic ClientAccessTokengetAccessToken(WebClient accessTokenService, AccessTokenGrant grant)Obtains the access token from OAuth AccessToken Service using the initialized web clientstatic ClientAccessTokengetAccessToken(WebClient accessTokenService, AccessTokenGrant grant, Map<String,String> extraParams)Obtains the access token from OAuth AccessToken Service using the initialized web clientstatic AuthorizationMetadatagetAuthorizationMetadata(String issuerURL)static URIgetAuthorizationURI(String authorizationServiceURI, String clientId, String redirectUri, String state, String scope)Builds a complete URI for redirecting to OAuth Authorization Servicestatic javax.ws.rs.core.UriBuildergetAuthorizationURIBuilder(String authorizationServiceURI, String clientId, String scope)Creates the builder for building OAuth AuthorizationService URIsstatic javax.ws.rs.core.UriBuildergetAuthorizationURIBuilder(String authorizationServiceURI, String clientId, String redirectUri, String state, String scope)static ClientAccessTokenrefreshAccessToken(WebClient accessTokenService, Consumer consumer, ClientAccessToken at)static ClientAccessTokenrefreshAccessToken(WebClient accessTokenService, Consumer consumer, ClientAccessToken at, String scope, boolean setAuthorizationHeader)static ClientAccessTokenrefreshAccessToken(WebClient accessTokenService, ClientAccessToken at)static voidsetAuthorizationHeader(WebClient wc, ClientAccessToken accessToken)static voidsetAuthorizationHeader(WebClient wc, ClientAccessToken accessToken, String httpVerb)
-
-
-
Method Detail
-
getAuthorizationURI
public static URI getAuthorizationURI(String authorizationServiceURI, String clientId, String redirectUri, String state, String scope)
Builds a complete URI for redirecting to OAuth Authorization Service- Parameters:
authorizationServiceURI- the service endpoint addressclientId- client registration idredirectUri- the uri the authorization code will be posted tostate- the client state, example the key or the encrypted token representing the info about the current end user's request- Returns:
- authorization service URI
-
getAuthorizationURIBuilder
public static javax.ws.rs.core.UriBuilder getAuthorizationURIBuilder(String authorizationServiceURI, String clientId, String redirectUri, String state, String scope)
-
getAuthorizationURIBuilder
public static javax.ws.rs.core.UriBuilder getAuthorizationURIBuilder(String authorizationServiceURI, String clientId, String scope)
Creates the builder for building OAuth AuthorizationService URIs- Parameters:
authorizationServiceURI- the service endpoint addressclientId- client registration idscope- the optional scope; if not specified then the authorization service will allocate the default scope- Returns:
- the builder
-
getAccessToken
public static ClientAccessToken getAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant) throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service using the initialized web client- Parameters:
accessTokenService- the AccessToken clientconsumer-Consumerrepresenting the registered clientgrant-AccessTokenGrantgrant- Returns:
ClientAccessTokenaccess token- Throws:
OAuthServiceException
-
getAccessToken
public static ClientAccessToken getAccessToken(String accessTokenServiceUri, Consumer consumer, AccessTokenGrant grant, boolean setAuthorizationHeader) throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service- Parameters:
accessTokenServiceUri- the AccessToken endpoint addressconsumer-Consumerrepresenting the registered clientgrant-AccessTokenGrantgrantsetAuthorizationHeader- if set to true then HTTP Basic scheme will be used to pass client id and secret, otherwise they will be passed in the form payload- Returns:
ClientAccessTokenaccess token- Throws:
OAuthServiceException
-
getAccessToken
public static ClientAccessToken getAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant, boolean setAuthorizationHeader)
Obtains the access token from OAuth AccessToken Service using the initialized web client- Parameters:
accessTokenService- the AccessToken clientconsumer-Consumerrepresenting the registered client.grant-AccessTokenGrantgrantsetAuthorizationHeader- if set to true then HTTP Basic scheme will be used to pass client id and secret, otherwise they will be passed in the form payload- Returns:
ClientAccessTokenaccess token- Throws:
OAuthServiceException
-
getAccessToken
public static ClientAccessToken getAccessToken(WebClient accessTokenService, AccessTokenGrant grant) throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service using the initialized web client- Parameters:
accessTokenService- the AccessToken clientgrant-AccessTokenGrantgrant- Returns:
ClientAccessTokenaccess token- Throws:
OAuthServiceException
-
getAccessToken
public static ClientAccessToken getAccessToken(WebClient accessTokenService, AccessTokenGrant grant, Map<String,String> extraParams) throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service using the initialized web client- Parameters:
accessTokenService- the AccessToken clientgrant-AccessTokenGrantgrantextraParams- extra parameters- Returns:
ClientAccessTokenaccess token- Throws:
OAuthServiceException
-
getAccessToken
public static ClientAccessToken getAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant, Map<String,String> extraParams, boolean setAuthorizationHeader) throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service using the initialized web client- Parameters:
accessTokenService- the AccessToken clientconsumer-Consumerrepresenting the registered client.grant-AccessTokenGrantgrantextraParams- extra parameterssetAuthorizationHeader- if set to true then HTTP Basic scheme will be used to pass client id and secret, otherwise they will be passed in the form payload- Returns:
ClientAccessTokenaccess token- Throws:
OAuthServiceException
-
refreshAccessToken
public static ClientAccessToken refreshAccessToken(WebClient accessTokenService, ClientAccessToken at)
-
refreshAccessToken
public static ClientAccessToken refreshAccessToken(WebClient accessTokenService, Consumer consumer, ClientAccessToken at)
-
refreshAccessToken
public static ClientAccessToken refreshAccessToken(WebClient accessTokenService, Consumer consumer, ClientAccessToken at, String scope, boolean setAuthorizationHeader) throws OAuthServiceException
- Throws:
OAuthServiceException
-
getAccessToken
public static ClientAccessToken getAccessToken(WebClient accessTokenService, Consumer consumer, AccessTokenGrant grant, Map<String,String> extraParams, String defaultTokenType, boolean setAuthorizationHeader) throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service using the initialized web client- Parameters:
accessTokenService- the AccessToken clientconsumer-Consumerrepresenting the registered client.grant-AccessTokenGrantgrantextraParams- extra parametersdefaultTokenType- default expected token type - some early well-known OAuth2 services do not return a required token_type parametersetAuthorizationHeader- if set to true then HTTP Basic scheme will be used to pass client id and secret, otherwise they will be passed in the form payload- Returns:
ClientAccessTokenaccess token- Throws:
OAuthServiceException
-
fromMapToClientToken
public static ClientAccessToken fromMapToClientToken(Map<String,String> map)
-
fromMapToClientToken
public static ClientAccessToken fromMapToClientToken(Map<String,String> map, String defaultTokenType)
-
createAuthorizationHeader
public static String createAuthorizationHeader(ClientAccessToken accessToken) throws OAuthServiceException
Creates OAuth Authorization header with Bearer scheme- Parameters:
accessToken- the access token- Returns:
- the header value
- Throws:
OAuthServiceException
-
createAuthorizationHeader
public static String createAuthorizationHeader(ClientAccessToken accessToken, HttpRequestProperties httpProps) throws OAuthServiceException
Creates OAuth Authorization header with the scheme that may require an access to the current HTTP request properties- Parameters:
accessToken- the access tokenhttpProps- http request properties, can be null for Bearer tokens- Returns:
- the header value
- Throws:
OAuthServiceException
-
setAuthorizationHeader
public static void setAuthorizationHeader(WebClient wc, ClientAccessToken accessToken)
-
setAuthorizationHeader
public static void setAuthorizationHeader(WebClient wc, ClientAccessToken accessToken, String httpVerb)
-
getAuthorizationMetadata
public static AuthorizationMetadata getAuthorizationMetadata(String issuerURL)
-
-