Package com.guinetik.rr.auth
Class AuthStrategyFactory
- java.lang.Object
-
- com.guinetik.rr.auth.AuthStrategyFactory
-
public class AuthStrategyFactory extends Object
Factory for creatingAuthStrategyinstances.This factory provides static methods to create various authentication strategies without directly instantiating the strategy classes. It's the recommended way to create authentication strategies for use with
RocketRestConfig.No Authentication
AuthStrategy noAuth = AuthStrategyFactory.createNoAuth();Basic Authentication
AuthStrategy basic = AuthStrategyFactory.createBasicAuth("username", "password");Bearer Token
// Simple bearer token AuthStrategy bearer = AuthStrategyFactory.createBearerToken("my-api-token"); // Bearer token with custom refresh logic AuthStrategy refreshable = AuthStrategyFactory.createBearerToken("initial-token", () -> { // Custom refresh logic String newToken = fetchNewTokenFromServer(); return newToken != null; });OAuth 2.0 Client Credentials
AuthStrategy oauth = AuthStrategyFactory.createOAuth2ClientCredentials( "client-id", "client-secret", "https://auth.example.com/oauth/token" ); // With additional parameters (e.g., scope) Map<String, String> params = new HashMap<>(); params.put("scope", "read write"); AuthStrategy oauthWithScope = AuthStrategyFactory.createOAuth2ClientCredentials( "client-id", "client-secret", "https://auth.example.com/oauth/token", params );OAuth 2.0 Password Grant
AuthStrategy password = AuthStrategyFactory.createOAuth2Password( "user@example.com", "userPassword", "https://auth.example.com/oauth/token" );- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
AuthStrategy,RocketRestConfig
-
-
Constructor Summary
Constructors Constructor Description AuthStrategyFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AuthStrategycreateBasicAuth(String username, String password)Creates a strategy that uses HTTP Basic authentication.static AuthStrategycreateBearerToken(String token)Creates a strategy that uses Bearer token authentication.static AuthStrategycreateBearerToken(String token, BooleanSupplier refreshTokenLogic)Creates a strategy that uses Bearer token authentication with custom refresh logic.static AuthStrategycreateNoAuth()Creates a strategy that does not perform authentication.static AuthStrategycreateOAuth2Assertion(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl)Creates a strategy that uses OAuth 2.0 assertion flow.static AuthStrategycreateOAuth2Assertion(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl, Map<String,String> additionalAssertionParams, Map<String,String> additionalTokenParams)Creates a strategy that uses OAuth 2.0 assertion flow with additional parameters.static AuthStrategycreateOAuth2ClientCredentials(String clientId, String clientSecret, String tokenUrl)Creates a strategy that uses OAuth 2.0 client credentials flow.static AuthStrategycreateOAuth2ClientCredentials(String clientId, String clientSecret, String tokenUrl, Map<String,String> additionalParams)Creates a strategy that uses OAuth 2.0 client credentials flow with additional parameters.static AuthStrategycreateOAuth2Password(String username, String password, String tokenUrl)Creates a strategy that uses OAuth 2.0 password flow.static AuthStrategycreateOAuth2Password(String username, String password, String clientId, String clientSecret, String tokenUrl)Creates a strategy that uses OAuth 2.0 password flow with client credentials.static AuthStrategycreateOAuth2Password(String username, String password, String clientId, String clientSecret, String tokenUrl, Map<String,String> additionalParams)Creates a strategy that uses OAuth 2.0 password flow with client credentials and additional parameters.
-
-
-
Method Detail
-
createNoAuth
public static AuthStrategy createNoAuth()
Creates a strategy that does not perform authentication.- Returns:
- a new no-auth strategy
-
createBasicAuth
public static AuthStrategy createBasicAuth(String username, String password)
Creates a strategy that uses HTTP Basic authentication.- Parameters:
username- the usernamepassword- the password- Returns:
- a new basic auth strategy
-
createBearerToken
public static AuthStrategy createBearerToken(String token)
Creates a strategy that uses Bearer token authentication.- Parameters:
token- the bearer token- Returns:
- a new bearer token strategy
-
createBearerToken
public static AuthStrategy createBearerToken(String token, BooleanSupplier refreshTokenLogic)
Creates a strategy that uses Bearer token authentication with custom refresh logic.- Parameters:
token- the bearer tokenrefreshTokenLogic- aBooleanSupplierthat dictates the behavior of token refresh. It should returntrueif the token was successfully refreshed,falseotherwise.- Returns:
- a new bearer token strategy with custom refresh logic
-
createOAuth2ClientCredentials
public static AuthStrategy createOAuth2ClientCredentials(String clientId, String clientSecret, String tokenUrl)
Creates a strategy that uses OAuth 2.0 client credentials flow.- Parameters:
clientId- the OAuth 2.0 client IDclientSecret- the OAuth 2.0 client secret- Returns:
- a new OAuth 2.0 client credentials strategy
-
createOAuth2ClientCredentials
public static AuthStrategy createOAuth2ClientCredentials(String clientId, String clientSecret, String tokenUrl, Map<String,String> additionalParams)
Creates a strategy that uses OAuth 2.0 client credentials flow with additional parameters.- Parameters:
clientId- the OAuth 2.0 client IDclientSecret- the OAuth 2.0 client secrettokenUrl- the token endpoint URLadditionalParams- additional parameters to include in the token request- Returns:
- a new OAuth 2.0 client credentials strategy
-
createOAuth2Password
public static AuthStrategy createOAuth2Password(String username, String password, String tokenUrl)
Creates a strategy that uses OAuth 2.0 password flow.- Parameters:
username- the user's usernamepassword- the user's password- Returns:
- a new OAuth 2.0 password strategy
-
createOAuth2Password
public static AuthStrategy createOAuth2Password(String username, String password, String clientId, String clientSecret, String tokenUrl)
Creates a strategy that uses OAuth 2.0 password flow with client credentials.- Parameters:
username- the user's usernamepassword- the user's passwordclientId- the OAuth 2.0 client IDclientSecret- the OAuth 2.0 client secret- Returns:
- a new OAuth 2.0 password strategy
-
createOAuth2Password
public static AuthStrategy createOAuth2Password(String username, String password, String clientId, String clientSecret, String tokenUrl, Map<String,String> additionalParams)
Creates a strategy that uses OAuth 2.0 password flow with client credentials and additional parameters.- Parameters:
username- the user's usernamepassword- the user's passwordclientId- the OAuth 2.0 client IDclientSecret- the OAuth 2.0 client secrettokenUrl- the token endpoint URLadditionalParams- additional parameters to include in the token request- Returns:
- a new OAuth 2.0 password strategy
-
createOAuth2Assertion
public static AuthStrategy createOAuth2Assertion(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl)
Creates a strategy that uses OAuth 2.0 assertion flow. This can be used with various identity providers like SAP, Azure AD, Okta, etc.- 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- Returns:
- a new OAuth 2.0 assertion strategy
-
createOAuth2Assertion
public static AuthStrategy createOAuth2Assertion(String clientId, String userId, String privateKey, String companyId, String grantType, String assertionUrl, String tokenUrl, Map<String,String> additionalAssertionParams, Map<String,String> additionalTokenParams)
Creates a strategy that uses OAuth 2.0 assertion flow with additional parameters. This can be used with various identity providers like SAP, Azure AD, Okta, etc.- 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- Returns:
- a new OAuth 2.0 assertion strategy
-
-