Apache CXF API

org.apache.cxf.rs.security.oauth2.client
Class OAuthClientUtils

java.lang.Object
  extended by org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils

public final class OAuthClientUtils
extends Object

The utility class for simplifying working with OAuth servers


Nested Class Summary
static class OAuthClientUtils.Consumer
          Simple consumer representation
 
Method Summary
static String createAuthorizationHeader(OAuthClientUtils.Consumer consumer, ClientAccessToken accessToken)
          Creates OAuth Authorization header with Bearer scheme
static String createAuthorizationHeader(OAuthClientUtils.Consumer consumer, ClientAccessToken accessToken, HttpRequestProperties httpProps)
          Creates OAuth Authorization header with the scheme that may require an access to the current HTTP request properties
static ClientAccessToken fromMapToClientToken(Map<String,String> map)
           
static ClientAccessToken getAccessToken(String accessTokenServiceUri, OAuthClientUtils.Consumer consumer, AccessTokenGrant grant, boolean setAuthorizationHeader)
          Obtains the access token from OAuth AccessToken Service
static ClientAccessToken getAccessToken(WebClient accessTokenService, OAuthClientUtils.Consumer consumer, AccessTokenGrant grant)
          Obtains the access token from OAuth AccessToken Service using the initialized web client
static ClientAccessToken getAccessToken(WebClient accessTokenService, OAuthClientUtils.Consumer consumer, AccessTokenGrant grant, boolean setAuthorizationHeader)
          Obtains the access token from OAuth AccessToken Service using the initialized web client
static URI getAuthorizationURI(String authorizationServiceURI, String clientId, String redirectUri, String state, String scope)
          Builds a complete URI for redirecting to OAuth Authorization Service
static javax.ws.rs.core.UriBuilder getAuthorizationURIBuilder(String authorizationServiceURI, String clientId, String scope)
          Creates the builder for building OAuth AuthorizationService URIs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 address
clientId - client registration id
redirectUri - the uri the authorization code will be posted to
state - 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 scope)
Creates the builder for building OAuth AuthorizationService URIs

Parameters:
authorizationServiceURI - the service endpoint address
clientId - client registration id
scope - 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,
                                               OAuthClientUtils.Consumer consumer,
                                               AccessTokenGrant grant)
                                        throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service using the initialized web client

Parameters:
accessTokenService - the AccessToken client
consumer - OAuthClientUtils.Consumer representing the registered client
grant - AccessTokenGrant grant
Returns:
ClientAccessToken access token
Throws:
OAuthServiceException

getAccessToken

public static ClientAccessToken getAccessToken(String accessTokenServiceUri,
                                               OAuthClientUtils.Consumer consumer,
                                               AccessTokenGrant grant,
                                               boolean setAuthorizationHeader)
                                        throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service

Parameters:
accessTokenServiceUri - the AccessToken endpoint address
consumer - OAuthClientUtils.Consumer representing the registered client
grant - AccessTokenGrant grant
setAuthorizationHeader - 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:
ClientAccessToken access token
Throws:
OAuthServiceException

getAccessToken

public static ClientAccessToken getAccessToken(WebClient accessTokenService,
                                               OAuthClientUtils.Consumer consumer,
                                               AccessTokenGrant grant,
                                               boolean setAuthorizationHeader)
                                        throws OAuthServiceException
Obtains the access token from OAuth AccessToken Service using the initialized web client

Parameters:
accessTokenService - the AccessToken client
consumer - OAuthClientUtils.Consumer representing the registered client.
grant - AccessTokenGrant grant
setAuthorizationHeader - 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:
ClientAccessToken access token
Throws:
OAuthServiceException

fromMapToClientToken

public static ClientAccessToken fromMapToClientToken(Map<String,String> map)

createAuthorizationHeader

public static String createAuthorizationHeader(OAuthClientUtils.Consumer consumer,
                                               ClientAccessToken accessToken)
                                        throws OAuthServiceException
Creates OAuth Authorization header with Bearer scheme

Parameters:
consumer - represents the registered client
accessToken - the access token
Returns:
the header value
Throws:
OAuthServiceException

createAuthorizationHeader

public static String createAuthorizationHeader(OAuthClientUtils.Consumer consumer,
                                               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:
consumer - represents the registered client
accessToken - the access token
httpProps - http request properties, can be null for Bearer tokens
Returns:
the header value
Throws:
OAuthServiceException

Apache CXF API

Apache CXF