Class ApiTokenAuthentication
java.lang.Object
overit.geocallapp.wfm.orchestrator.planning.utilities.rest.authentication.strategies.ApiTokenAuthentication
- All Implemented Interfaces:
AuthenticationStrategy
Authentication strategy that uses a static API token.
This strategy is suitable for APIs that use a fixed token for authentication.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionApiTokenAuthentication(String token) Creates a new API token authentication with the specified token and "Bearer" prefix.ApiTokenAuthentication(String token, String prefix) Creates a new API token authentication with the specified token and prefix. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyAuthentication(org.springframework.http.HttpHeaders headers) Applies authentication information to the provided HTTP headers.booleanisValid()Checks if the current authentication is valid.voidRefreshes the authentication if needed.
-
Field Details
-
LOG
-
-
Constructor Details
-
ApiTokenAuthentication
Creates a new API token authentication with the specified token and "Bearer" prefix.- Parameters:
token- The API token to use for authentication
-
ApiTokenAuthentication
Creates a new API token authentication with the specified token and prefix.- Parameters:
token- The API token to use for authenticationprefix- The prefix to use before the token (e.g., "Bearer", "Token", "ApiKey")
-
-
Method Details
-
applyAuthentication
public void applyAuthentication(org.springframework.http.HttpHeaders headers) throws DAValidateException Description copied from interface:AuthenticationStrategyApplies authentication information to the provided HTTP headers.- Specified by:
applyAuthenticationin interfaceAuthenticationStrategy- Parameters:
headers- The HTTP headers to which authentication information should be added- Throws:
DAValidateException- if authentication fails
-
isValid
public boolean isValid()Description copied from interface:AuthenticationStrategyChecks if the current authentication is valid.- Specified by:
isValidin interfaceAuthenticationStrategy- Returns:
- true if the authentication is valid, false otherwise
-
refreshAuthentication
Description copied from interface:AuthenticationStrategyRefreshes the authentication if needed. This method should be called before using the authentication if isValid() returns false.- Specified by:
refreshAuthenticationin interfaceAuthenticationStrategy- Throws:
DAValidateException- if authentication refresh fails
-