Class OAuth2Authenticator
- java.lang.Object
-
- org.vx68k.bitbucket.api.client.internal.OAuth2Authenticator
-
- All Implemented Interfaces:
ClientRequestFilter
public final class OAuth2Authenticator extends Object implements ClientRequestFilter
OAuth 2.0 authentication filter for the JAX-RS Client API. This class should support any grant types which uses a token endpoint.- Since:
- 5.0
- Author:
- Kaz Nishimura
- See Also:
- RFC 6749
-
-
Constructor Summary
Constructors Constructor Description OAuth2Authenticator(URI baseUri, URI tokenEndpointUri)Initializes the object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTokenRefreshListener(TokenRefreshListener listener)Adds a token refresh listener.voidfilter(ClientRequestContext requestContext)Adds anAuthorizationHTTP header to a request when authentication is required.protected voidfireTokenRefreshed()Fires a token refreshed event.protected voidfireTokenRefreshed(TokenRefreshEvent event)Fires a token refreshed event.StringgetAccessToken()Returns the access token.InstantgetAccessTokenExpiry()Returns the time when the access token expires.StringgetClientId()Returns the client identifier.StringgetRefreshToken()Returns the refresh token.protected voidrefreshAccessToken()Refreshes the access token.voidremoveTokenRefreshListener(TokenRefreshListener listener)Removes a token refresh listener.voidrequestAccessToken(Entity formEntity)Requests an access token by posting a form entity.voidsetAccessToken(String newValue)Sets the access token.voidsetAccessTokenExpiry(Instant newValue)Sets the time when the access token expires.voidsetClientId(String newValue)Sets the client identifier.voidsetClientSecret(String newValue)Sets the client secret.voidsetRefreshToken(String newValue)Sets the refresh token.
-
-
-
Method Detail
-
getClientId
public String getClientId()
Returns the client identifier.- Returns:
- the client identifier
-
setClientId
public void setClientId(String newValue)
Sets the client identifier.- Parameters:
newValue- a new value of the client identifier
-
setClientSecret
public void setClientSecret(String newValue)
Sets the client secret.- Parameters:
newValue- a new value of the client secret.
-
getAccessToken
public String getAccessToken()
Returns the access token.- Returns:
- the access token
-
setAccessToken
public void setAccessToken(String newValue)
Sets the access token.- Parameters:
newValue- a new value of the access token
-
getRefreshToken
public String getRefreshToken()
Returns the refresh token.- Returns:
- the refresh token
-
setRefreshToken
public void setRefreshToken(String newValue)
Sets the refresh token.- Parameters:
newValue- a new value of the refresh token
-
getAccessTokenExpiry
public Instant getAccessTokenExpiry()
Returns the time when the access token expires.- Returns:
- the time when the access token expires
-
setAccessTokenExpiry
public void setAccessTokenExpiry(Instant newValue)
Sets the time when the access token expires.- Parameters:
newValue- new value of the time when the access token expires
-
fireTokenRefreshed
protected void fireTokenRefreshed()
Fires a token refreshed event.
-
fireTokenRefreshed
protected void fireTokenRefreshed(TokenRefreshEvent event)
Fires a token refreshed event.- Parameters:
event- a token refreshed event.
-
addTokenRefreshListener
public void addTokenRefreshListener(TokenRefreshListener listener)
Adds a token refresh listener.- Parameters:
listener- a token refresh listener
-
removeTokenRefreshListener
public void removeTokenRefreshListener(TokenRefreshListener listener)
Removes a token refresh listener.- Parameters:
listener- a token refresh listener
-
requestAccessToken
public void requestAccessToken(Entity formEntity)
Requests an access token by posting a form entity.- Parameters:
formEntity- a form entity
-
refreshAccessToken
protected void refreshAccessToken()
Refreshes the access token.
-
filter
public void filter(ClientRequestContext requestContext)
Adds anAuthorizationHTTP header to a request when authentication is required. The header shall be added only if the request URI is below the base URI.- Specified by:
filterin interfaceClientRequestFilter- Parameters:
requestContext- a request context
-
-