Package com.guinetik.rr.auth
Class AbstractOAuth2Strategy
- java.lang.Object
-
- com.guinetik.rr.auth.AbstractOAuth2Strategy
-
- All Implemented Interfaces:
AuthStrategy,RocketSSL.SSLAware
- Direct Known Subclasses:
OAuth2AssertionStrategy,OAuth2ClientCredentialsStrategy,OAuth2PasswordStrategy
public abstract class AbstractOAuth2Strategy extends Object implements AuthStrategy, RocketSSL.SSLAware
Abstract base class for OAuth 2.0 authentication strategies. Provides common functionality for different OAuth2 flows.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.guinetik.rr.auth.AuthStrategy
AuthStrategy.AuthType
-
-
Field Summary
Fields Modifier and Type Field Description protected StringaccessTokenprotected Map<String,String>additionalParamsprotected DefaultHttpClienthttpClientprotected booleanisRefreshingprotected org.slf4j.Loggerloggerprotected StringoauthTokenUrlOAuth 2.0 token endpoint URL to be used when refreshing credentials.protected DatetokenExpiryTime
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractOAuth2Strategy(String tokenUrl, Map<String,String> additionalParams)Creates a new OAuth 2.0 strategy with additional parameters.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description RocketHeadersapplyAuthHeaders(RocketHeaders headers)Applies authentication headers to an existing HttpHeader object.voidconfigureSsl(SSLContext sslContext)Sets the SSL context for secure token requests.StringgetAccessToken()Gets the current access token.DategetTokenExpiryTime()Gets the token expiry time.booleanneedsTokenRefresh()Indicates whether this strategy needs a token refresh.protected Stringpost(String url, Map<String,String> formParams)Helper method to perform POST requests.protected abstract Map<String,String>prepareTokenRequestParams()Prepares the parameters for the token request.protected booleanprocessTokenResponse(Map<String,Object> tokenResponse)Processes the token response and extracts relevant information.booleanrefreshCredentials()Handles refreshing the authentication credentials for strategies that support it.protected abstract voidvalidateCredentials()Validates that all required credentials are present.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.guinetik.rr.auth.AuthStrategy
getType
-
-
-
-
Field Detail
-
logger
protected final org.slf4j.Logger logger
-
oauthTokenUrl
protected final String oauthTokenUrl
OAuth 2.0 token endpoint URL to be used when refreshing credentials.
-
accessToken
protected String accessToken
-
tokenExpiryTime
protected Date tokenExpiryTime
-
isRefreshing
protected boolean isRefreshing
-
httpClient
protected DefaultHttpClient httpClient
-
-
Constructor Detail
-
AbstractOAuth2Strategy
protected AbstractOAuth2Strategy(String tokenUrl, Map<String,String> additionalParams)
Creates a new OAuth 2.0 strategy with additional parameters.- Parameters:
tokenUrl- the OAuth 2.0 token endpoint URLadditionalParams- additional parameters to include in the token request
-
-
Method Detail
-
applyAuthHeaders
public RocketHeaders applyAuthHeaders(RocketHeaders headers)
Description copied from interface:AuthStrategyApplies authentication headers to an existing HttpHeader object.- Specified by:
applyAuthHeadersin interfaceAuthStrategy- Parameters:
headers- the current HttpHeader to update- Returns:
- the updated HttpHeader
-
needsTokenRefresh
public boolean needsTokenRefresh()
Description copied from interface:AuthStrategyIndicates whether this strategy needs a token refresh.- Specified by:
needsTokenRefreshin interfaceAuthStrategy- Returns:
- true if token refresh is required
-
post
protected String post(String url, Map<String,String> formParams) throws IOException
Helper method to perform POST requests.- Parameters:
url- the URL to send the request toformParams- the form parameters to include in the request- Returns:
- the response body as a string
- Throws:
IOException- if an I/O error occurs
-
refreshCredentials
public boolean refreshCredentials()
Description copied from interface:AuthStrategyHandles refreshing the authentication credentials for strategies that support it.- Specified by:
refreshCredentialsin interfaceAuthStrategy- Returns:
- true if the credentials were successfully refreshed
-
validateCredentials
protected abstract void validateCredentials()
Validates that all required credentials are present.- Throws:
TokenRefreshException- if any required credentials are missing
-
prepareTokenRequestParams
protected abstract Map<String,String> prepareTokenRequestParams()
Prepares the parameters for the token request.- Returns:
- map of parameters to include in the token request
-
processTokenResponse
protected boolean processTokenResponse(Map<String,Object> tokenResponse)
Processes the token response and extracts relevant information.- Parameters:
tokenResponse- the parsed token response- Returns:
- true if the token was successfully refreshed, false otherwise
- Throws:
TokenRefreshException- if there was an error processing the token response
-
getAccessToken
public String getAccessToken()
Gets the current access token.- Returns:
- the current access token, or null if not yet obtained
-
getTokenExpiryTime
public Date getTokenExpiryTime()
Gets the token expiry time.- Returns:
- the token expiry time, or null if not yet obtained
-
configureSsl
public void configureSsl(SSLContext sslContext)
Sets the SSL context for secure token requests.- Specified by:
configureSslin interfaceRocketSSL.SSLAware- Parameters:
sslContext- the SSL context to use
-
-