Class 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 encoded username:password string.

    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)
    • Constructor Detail

      • BasicAuthStrategy

        public BasicAuthStrategy​(String username,
                                 String password)
        Creates a new BasicAuthStrategy.
        Parameters:
        username - the username for basic authentication
        password - the password for basic authentication
    • Method Detail

      • applyAuthHeaders

        public RocketHeaders applyAuthHeaders​(RocketHeaders headers)
        Description copied from interface: AuthStrategy
        Applies authentication headers to an existing HttpHeader object.
        Specified by:
        applyAuthHeaders in interface AuthStrategy
        Parameters:
        headers - the current HttpHeader to update
        Returns:
        the updated HttpHeader
      • needsTokenRefresh

        public boolean needsTokenRefresh()
        Description copied from interface: AuthStrategy
        Indicates whether this strategy needs a token refresh.
        Specified by:
        needsTokenRefresh in interface AuthStrategy
        Returns:
        true if token refresh is required
      • refreshCredentials

        public boolean refreshCredentials()
        Description copied from interface: AuthStrategy
        Handles refreshing the authentication credentials for strategies that support it.
        Specified by:
        refreshCredentials in interface AuthStrategy
        Returns:
        true if the credentials were successfully refreshed