Class AuthManager
java.lang.Object
overit.geocallapp.wfm.orchestrator.planning.utilities.rest.AuthManager
Manager for authentication strategies.
This class provides factory methods for creating different authentication strategies
and applies authentication to HTTP headers.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAuthManager(AuthenticationStrategy authStrategy) Creates a new authentication manager with the specified authentication strategy. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyAuthentication(org.springframework.http.HttpHeaders headers) Applies authentication to the provided HTTP headers.Gets the underlying authentication strategy.booleanisValid()Checks if the current authentication is valid.voidRefreshes the authentication if needed.static AuthManagerwithApiToken(String token) Creates a new authentication manager that uses API token authentication.static AuthManagerwithApiToken(String token, String prefix) Creates a new authentication manager that uses API token authentication with a custom prefix.static AuthManagerwithBasicAuth(String username, String password) Creates a new authentication manager that uses HTTP Basic Authentication.static AuthManagerwithUsernamePassword(String authUrl, String username, String password) Creates a new authentication manager that uses username/password authentication with JWT token.
-
Field Details
-
LOG
-
-
Constructor Details
-
AuthManager
Creates a new authentication manager with the specified authentication strategy.- Parameters:
authStrategy- The authentication strategy to use
-
-
Method Details
-
withApiToken
Creates a new authentication manager that uses API token authentication.- Parameters:
token- The API token to use for authentication- Returns:
- A new authentication manager
-
withApiToken
Creates a new authentication manager that uses API token authentication with a custom prefix.- Parameters:
token- The API token to use for authenticationprefix- The prefix to use before the token (e.g., "Bearer", "Token", "ApiKey")- Returns:
- A new authentication manager
-
withUsernamePassword
Creates a new authentication manager that uses username/password authentication with JWT token.- Parameters:
authUrl- The URL to use for authenticationusername- The username to use for authenticationpassword- The password to use for authentication- Returns:
- A new authentication manager
-
withBasicAuth
Creates a new authentication manager that uses HTTP Basic Authentication.- Parameters:
username- The username to use for authenticationpassword- The password to use for authentication- Returns:
- A new authentication manager
-
applyAuthentication
public void applyAuthentication(org.springframework.http.HttpHeaders headers) throws DAValidateException Applies authentication to the provided HTTP headers.- Parameters:
headers- The HTTP headers to which authentication information should be added- Throws:
DAValidateException- if authentication fails
-
isValid
public boolean isValid()Checks if the current authentication is valid.- Returns:
- true if the authentication is valid, false otherwise
-
refreshAuthentication
Refreshes the authentication if needed.- Throws:
DAValidateException- if authentication refresh fails
-
getAuthStrategy
Gets the underlying authentication strategy.- Returns:
- The authentication strategy
-