Class BasicAuthentication
java.lang.Object
overit.geocallapp.wfm.orchestrator.planning.utilities.rest.authentication.strategies.BasicAuthentication
- All Implemented Interfaces:
AuthenticationStrategy
Authentication strategy that uses username and password for authentication.
This strategy supports two modes:
1. JWT token mode: obtains a JWT token using username/password and uses it for subsequent requests
2. Basic Auth mode: uses HTTP Basic Authentication for each request
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBasicAuthentication(String authUrl, String username, String password) Creates a new username/password authentication with the specified parameters using JWT token mode.BasicAuthentication(String authUrl, String username, String password, boolean useBasicAuth) Creates a new username/password authentication with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyAuthentication(org.springframework.http.HttpHeaders headers) Applies authentication information to the provided HTTP headers.getToken()Gets the current JWT token.booleanisValid()Checks if the current authentication is valid.voidRefreshes the authentication if needed.
-
Field Details
-
LOG
-
-
Constructor Details
-
BasicAuthentication
Creates a new username/password authentication with the specified parameters using JWT token mode.- Parameters:
authUrl- The URL to use for authenticationusername- The username to use for authenticationpassword- The password to use for authentication
-
BasicAuthentication
Creates a new username/password authentication with the specified parameters.- Parameters:
authUrl- The URL to use for authentication (can be null if useBasicAuth is true)username- The username to use for authenticationpassword- The password to use for authenticationuseBasicAuth- If true, uses HTTP Basic Authentication for each request instead of JWT token
-
-
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
-
getToken
Gets the current JWT token.- Returns:
- The current JWT token
- Throws:
DAValidateException- if authentication fails
-