Package at.jku.dke.etutor.task_app.auth
Class AuthenticationService
java.lang.Object
at.jku.dke.etutor.task_app.auth.AuthenticationService
Provides a method for authenticating clients using API keys.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionOptional
<org.springframework.security.core.Authentication> authenticate
(jakarta.servlet.http.HttpServletRequest request) Returns the authentication object for the specified request.Optional
<org.springframework.security.core.Authentication> authenticate
(String apiKey) Returns the authentication for the specified API key.
-
Constructor Details
-
AuthenticationService
Creates a new instance of classAuthenticationService
.- Parameters:
config
- The configuration containing the API keys.
-
-
Method Details
-
authenticate
Returns the authentication for the specified API key.- Parameters:
apiKey
- The API key.- Returns:
- The authentication. Either empty if
apiKey
wasnull
or the authentication. - Throws:
org.springframework.security.authentication.BadCredentialsException
- If theapiKey
is notnull
, but the API-Key is invalid.
-
authenticate
public Optional<org.springframework.security.core.Authentication> authenticate(jakarta.servlet.http.HttpServletRequest request) Returns the authentication object for the specified request.This method extracts the API key from the HTTP header
AuthConstants.AUTH_TOKEN_HEADER_NAME
.- Parameters:
request
- The HTTP request to authenticate.- Returns:
- The authentication. Either empty if no header was found or the authentication.
- Throws:
org.springframework.security.authentication.BadCredentialsException
- If the header was found, but the API-Key is invalid.
-