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 void
addTokenRefreshListener(TokenRefreshListener listener)
Adds a token refresh listener.void
filter(ClientRequestContext requestContext)
Adds anAuthorization
HTTP header to a request when authentication is required.protected void
fireTokenRefreshed()
Fires a token refreshed event.protected void
fireTokenRefreshed(TokenRefreshEvent event)
Fires a token refreshed event.String
getAccessToken()
Returns the access token.Instant
getAccessTokenExpiry()
Returns the time when the access token expires.String
getClientId()
Returns the client identifier.String
getRefreshToken()
Returns the refresh token.protected void
refreshAccessToken()
Refreshes the access token.void
removeTokenRefreshListener(TokenRefreshListener listener)
Removes a token refresh listener.void
requestAccessToken(Entity formEntity)
Requests an access token by posting a form entity.void
setAccessToken(String newValue)
Sets the access token.void
setAccessTokenExpiry(Instant newValue)
Sets the time when the access token expires.void
setClientId(String newValue)
Sets the client identifier.void
setClientSecret(String newValue)
Sets the client secret.void
setRefreshToken(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 anAuthorization
HTTP 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:
filter
in interfaceClientRequestFilter
- Parameters:
requestContext
- a request context
-
-