Package com.guinetik.rr.auth
Class BasicAuthStrategy
- java.lang.Object
-
- com.guinetik.rr.auth.BasicAuthStrategy
-
- All Implemented Interfaces:
AuthStrategy
public class BasicAuthStrategy extends Object implements AuthStrategy
Authentication strategy that uses HTTP Basic authentication.This strategy adds an
Authorization: Basic <base64>header to all requests, where the base64 value is the encodedusername:passwordstring.Usage
// Create via factory (recommended) AuthStrategy auth = AuthStrategyFactory.createBasicAuth("username", "password"); // Configure client RocketRestConfig config = RocketRestConfig.builder("https://api.example.com") .authStrategy(auth) .build(); RocketRest client = new RocketRest(config);Security Note: Basic authentication transmits credentials in base64 encoding (not encryption). Always use HTTPS when using basic authentication.
- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
AuthStrategy,AuthStrategyFactory.createBasicAuth(String, String)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.guinetik.rr.auth.AuthStrategy
AuthStrategy.AuthType
-
-
Constructor Summary
Constructors Constructor Description BasicAuthStrategy(String username, String password)Creates a new BasicAuthStrategy.
-
Method Summary
All Methods Instance Methods Concrete 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
public AuthStrategy.AuthType getType()
Description copied from interface:AuthStrategyReturns the auth type of this strategy.- Specified by:
getTypein interfaceAuthStrategy- Returns:
- the authentication type
-
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
-
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
-
-