Class ClientCredentialsAccessTokenProvider
- java.lang.Object
-
- de.aristaflow.adept2.core.eventmanager.mailevents.ClientCredentialsAccessTokenProvider
-
- All Implemented Interfaces:
OAuth2AccessTokenProvider
@ConfigurationDescription(properties={@Property(name="TokenEndpoint",isRequired=true,description="The HTTP-based endpoint used to acquire the OAuth 2.0 token."),,,,,}) public class ClientCredentialsAccessTokenProvider extends Object implements OAuth2AccessTokenProvider
An implementation ofOAuth2AccessTokenProviderthat acquires an access token via the OAuth 2.0 client credentials grant.
-
-
Field Summary
Fields Modifier and Type Field Description protected HttpClientclientThe currently usedclientornullif no client has been created or the last request failed.protected HttpClient.BuilderclientBuilderThe builder for a newclient.protected longclientTimeoutDeprecated, for removal: This API element is subject to removal in a future version.UseclientandclientBuilderinstead.static StringCONF_CLIENT_IDConfiguration key for the client ID.static StringCONF_CLIENT_SECRETConfiguration key for the client secret.static StringCONF_REQUEST_TIMEOUTConfiguration key for the HttpRequest timeout.static StringCONF_SCOPEConfiguration key for the scope.static StringCONF_TIMEOUTConfiguration key for the HttpClient timeout.static StringCONF_TOKEN_ENDPOINTConfiguration key for the token endpoint.protected HttpRequest.BodyPublisherpostRequestDataDeprecated, for removal: This API element is subject to removal in a future version.UserequestandrequestBuilderinstead.protected HttpRequestrequestThe currently usedrequestornullif no request has been created or the last request failed.protected HttpRequest.BuilderrequestBuilderThe builder for a newrequest.protected longrequestTimeoutDeprecated, for removal: This API element is subject to removal in a future version.UserequestandrequestBuilderinstead.protected URItokenEndpointDeprecated, for removal: This API element is subject to removal in a future version.UserequestandrequestBuilderinstead.
-
Constructor Summary
Constructors Constructor Description ClientCredentialsAccessTokenProvider(org.apache.commons.configuration2.Configuration conf, EventManager em, Registry registry)Creates a new provider for an OAuth 2.0 token from a specific endpoint.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected HttpRequest.BodyPublishercreateRequestData(org.apache.commons.configuration2.Configuration conf)Creates aHttpRequest.BodyPublisherthat turns the values from the designated configuration into appropriate URL-encoded form data.StringgetAccessToken()Gets an OAuth2 access token for accessing the mailbox.
-
-
-
Field Detail
-
CONF_TIMEOUT
public static final String CONF_TIMEOUT
Configuration key for the HttpClient timeout.- See Also:
- Constant Field Values
-
CONF_REQUEST_TIMEOUT
public static final String CONF_REQUEST_TIMEOUT
Configuration key for the HttpRequest timeout.- See Also:
- Constant Field Values
-
CONF_TOKEN_ENDPOINT
public static final String CONF_TOKEN_ENDPOINT
Configuration key for the token endpoint.- See Also:
- Constant Field Values
-
CONF_CLIENT_ID
public static final String CONF_CLIENT_ID
Configuration key for the client ID.- See Also:
- Constant Field Values
-
CONF_CLIENT_SECRET
public static final String CONF_CLIENT_SECRET
Configuration key for the client secret.- See Also:
- Constant Field Values
-
CONF_SCOPE
public static final String CONF_SCOPE
Configuration key for the scope.- See Also:
- Constant Field Values
-
tokenEndpoint
@Deprecated(since="15.3.0", forRemoval=true) protected final URI tokenEndpoint
Deprecated, for removal: This API element is subject to removal in a future version.UserequestandrequestBuilderinstead.The token endpoint.
-
postRequestData
@Deprecated(since="15.3.0", forRemoval=true) protected final HttpRequest.BodyPublisher postRequestData
Deprecated, for removal: This API element is subject to removal in a future version.UserequestandrequestBuilderinstead.The data to send as post request to get an OAuth 2.0 access token.
-
clientTimeout
@Deprecated(since="15.3.0", forRemoval=true) protected final long clientTimeout
Deprecated, for removal: This API element is subject to removal in a future version.UseclientandclientBuilderinstead.The HttpClient timeout.
-
requestTimeout
@Deprecated(since="15.3.0", forRemoval=true) protected final long requestTimeout
Deprecated, for removal: This API element is subject to removal in a future version.UserequestandrequestBuilderinstead.The HttpRequest timeout.
-
clientBuilder
protected final HttpClient.Builder clientBuilder
The builder for a newclient.
-
requestBuilder
protected final HttpRequest.Builder requestBuilder
The builder for a newrequest.
-
client
protected volatile HttpClient client
The currently usedclientornullif no client has been created or the last request failed.
-
request
protected volatile HttpRequest request
The currently usedrequestornullif no request has been created or the last request failed.
-
-
Constructor Detail
-
ClientCredentialsAccessTokenProvider
public ClientCredentialsAccessTokenProvider(org.apache.commons.configuration2.Configuration conf, EventManager em, Registry registry) throws AbortServiceExceptionCreates a new provider for an OAuth 2.0 token from a specific endpoint.- Parameters:
conf- The configuration of this OAuth 2.0 token provider.em- The event manager this provider is a plugin of.registry- The registry starting this plugin.- Throws:
AbortServiceException- If there are problems creating aURIfor the configured endpoint, anAbortServiceExceptionwrapping the correspondingURISyntaxExceptionwill be thrown.
-
-
Method Detail
-
createRequestData
protected HttpRequest.BodyPublisher createRequestData(org.apache.commons.configuration2.Configuration conf)
Creates aHttpRequest.BodyPublisherthat turns the values from the designated configuration into appropriate URL-encoded form data.- Parameters:
conf- The configuration to get the request data from.- Returns:
- The designated data as URL-encoded form data.
-
getAccessToken
public String getAccessToken() throws javax.mail.MessagingException
Description copied from interface:OAuth2AccessTokenProviderGets an OAuth2 access token for accessing the mailbox.- Specified by:
getAccessTokenin interfaceOAuth2AccessTokenProvider- Returns:
- An OAuth2 access token for accessing the mailbox
- Throws:
javax.mail.MessagingException- If there are problems retrieving the access token, aMessagingExceptionwill be thrown.
-
-