Package com.guinetik.rr.auth
Interface AuthStrategy
-
- All Known Implementing Classes:
AbstractOAuth2Strategy,BasicAuthStrategy,BearerTokenStrategy,NoAuthStrategy,OAuth2AssertionStrategy,OAuth2ClientCredentialsStrategy,OAuth2PasswordStrategy
public interface AuthStrategyInterface for authentication strategies used by RocketRest.Authentication strategies encapsulate the logic for different authentication methods, from simple bearer tokens to complex OAuth 2.0 flows. Implementations are pluggable and can be configured via
RocketRestConfig.Available Implementations
NoAuthStrategy- No authenticationBasicAuthStrategy- HTTP Basic authenticationBearerTokenStrategy- Bearer token authenticationOAuth2ClientCredentialsStrategy- OAuth 2.0 client credentials flowOAuth2PasswordStrategy- OAuth 2.0 password grant flowOAuth2AssertionStrategy- OAuth 2.0 assertion/SAML flow
Using Strategies
// Via factory (recommended) AuthStrategy bearer = AuthStrategyFactory.createBearerToken("my-token"); AuthStrategy basic = AuthStrategyFactory.createBasicAuth("user", "pass"); AuthStrategy oauth = AuthStrategyFactory.createOAuth2ClientCredentials( "client-id", "client-secret", "https://auth.example.com/token" ); // Configure in RocketRestConfig RocketRestConfig config = RocketRestConfig.builder("https://api.example.com") .authStrategy(bearer) .build();Custom Strategy Implementation
public class CustomAuthStrategy implements AuthStrategy { @Override public AuthType getType() { return AuthType.BEARER_TOKEN; } @Override public RocketHeaders applyAuthHeaders(RocketHeaders headers) { headers.set("X-Custom-Auth", computeAuthValue()); return headers; } @Override public boolean needsTokenRefresh() { return isTokenExpired(); } @Override public boolean refreshCredentials() { return fetchNewToken(); } }- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
AuthStrategyFactory,RocketRestConfig
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAuthStrategy.AuthTypeEnum representing different authentication types.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description RocketHeadersapplyAuthHeaders(RocketHeaders headers)Applies authentication headers to an existing HttpHeader object.AuthStrategy.AuthTypegetType()Returns the auth type of this strategy.booleanneedsTokenRefresh()Indicates whether this strategy needs a token refresh.booleanrefreshCredentials()Handles refreshing the authentication credentials for strategies that support it.
-
-
-
Method Detail
-
getType
AuthStrategy.AuthType getType()
Returns the auth type of this strategy.- Returns:
- the authentication type
-
applyAuthHeaders
RocketHeaders applyAuthHeaders(RocketHeaders headers)
Applies authentication headers to an existing HttpHeader object.- Parameters:
headers- the current HttpHeader to update- Returns:
- the updated HttpHeader
-
needsTokenRefresh
boolean needsTokenRefresh()
Indicates whether this strategy needs a token refresh.- Returns:
- true if token refresh is required
-
refreshCredentials
boolean refreshCredentials()
Handles refreshing the authentication credentials for strategies that support it.- Returns:
- true if the credentials were successfully refreshed
- Throws:
TokenRefreshException- if the refresh operation fails
-
-