Package com.guinetik.rr.auth
Class OAuth2AssertionStrategy
- java.lang.Object
-
- com.guinetik.rr.auth.AbstractOAuth2Strategy
-
- com.guinetik.rr.auth.OAuth2AssertionStrategy
-
- All Implemented Interfaces:
AuthStrategy,RocketSSL.SSLAware
public class OAuth2AssertionStrategy extends AbstractOAuth2Strategy
Authentication strategy that implements OAuth 2.0 assertion flow. This strategy implements a two-step OAuth flow: 1. Get an assertion from the Identity Provider endpoint by providing a private key; 2. Use the assertion to get the actual OAuth token from the token endpoint. This can be used with various identity providers like SAP, Azure AD, Okta, etc.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.guinetik.rr.auth.AuthStrategy
AuthStrategy.AuthType
-
-
Field Summary
-
Fields inherited from class com.guinetik.rr.auth.AbstractOAuth2Strategy
accessToken, additionalParams, httpClient, isRefreshing, oauthTokenUrl, tokenExpiryTime
-
-
Constructor Summary
Constructors Constructor Description OAuth2AssertionStrategy(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl)Creates a new OAuth 2.0 assertion strategy.OAuth2AssertionStrategy(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl, Map<String,String> additionalAssertionParams, Map<String,String> additionalTokenParams)Creates a new OAuth 2.0 assertion strategy with additional parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthStrategy.AuthTypegetType()Returns the auth type of this strategy.protected Map<String,String>prepareTokenRequestParams()Prepares the parameters for the token request.booleanrefreshCredentials()Handles refreshing the authentication credentials for strategies that support it.protected voidvalidateCredentials()Validates that all required credentials are present.-
Methods inherited from class com.guinetik.rr.auth.AbstractOAuth2Strategy
applyAuthHeaders, configureSsl, getAccessToken, getTokenExpiryTime, needsTokenRefresh, post, processTokenResponse
-
-
-
-
Constructor Detail
-
OAuth2AssertionStrategy
public OAuth2AssertionStrategy(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl)
Creates a new OAuth 2.0 assertion strategy.- Parameters:
clientId- the OAuth client IDuserId- the user IDprivateKey- the private key for assertioncompanyId- the company ID (optional, can be null)grantType- the OAuth grant typeassertionUrl- the assertion endpoint URLtokenUrl- the token endpoint URL
-
OAuth2AssertionStrategy
public OAuth2AssertionStrategy(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl, Map<String,String> additionalAssertionParams, Map<String,String> additionalTokenParams)
Creates a new OAuth 2.0 assertion strategy with additional parameters.- Parameters:
clientId- the OAuth client IDuserId- the user IDprivateKey- the private key for assertioncompanyId- the company ID (optional, can be null)grantType- the OAuth grant typeassertionUrl- the assertion endpoint URLtokenUrl- the token endpoint URLadditionalAssertionParams- additional parameters for assertion requestadditionalTokenParams- additional parameters for token request
-
-
Method Detail
-
getType
public AuthStrategy.AuthType getType()
Description copied from interface:AuthStrategyReturns the auth type of this strategy.- Returns:
- the authentication type
-
validateCredentials
protected void validateCredentials()
Validates that all required credentials are present.- Specified by:
validateCredentialsin classAbstractOAuth2Strategy- Throws:
TokenRefreshException- if any of the required parameters (clientId, userId, privateKey, grantType, assertionUrl, or tokenUrl) are missing.
-
refreshCredentials
public boolean refreshCredentials()
Handles refreshing the authentication credentials for strategies that support it.This implementation handles the two-step OAuth 2.0 assertion flow:
- It first calls
getAssertion()to obtain an assertion from the configured assertion URL. - Then, it uses this assertion along with other parameters (clientId, userId, grantType, companyId if present)
to call the
super.refreshCredentials()method, which performs the actual token request to the configured token URL.
- Specified by:
refreshCredentialsin interfaceAuthStrategy- Overrides:
refreshCredentialsin classAbstractOAuth2Strategy- Returns:
trueif the token was successfully refreshed,falseotherwise.- Throws:
TokenRefreshException- if token refresh fails at any step.
- It first calls
-
prepareTokenRequestParams
protected Map<String,String> prepareTokenRequestParams()
Prepares the parameters for the token request.Prepares parameters for the token request part of the assertion flow. This method is typically called by the parent class's
refreshTokenmethod. It includes clientId, userId, grantType, and companyId (if available). The assertion itself is expected to have been added toadditionalParamsby the overriddenrefreshCredentials()method before this is called.- Specified by:
prepareTokenRequestParamsin classAbstractOAuth2Strategy- Returns:
- map of parameters to include in the token request
-
-