Class AuthenticationService

java.lang.Object
at.jku.dke.etutor.task_app.auth.AuthenticationService

@Service public class AuthenticationService extends Object
Provides a method for authenticating clients using API keys.
  • Constructor Details

    • AuthenticationService

      public AuthenticationService(ApiKeyConfiguration config)
      Creates a new instance of class AuthenticationService.
      Parameters:
      config - The configuration containing the API keys.
  • Method Details

    • authenticate

      public Optional<org.springframework.security.core.Authentication> authenticate(String apiKey)
      Returns the authentication for the specified API key.
      Parameters:
      apiKey - The API key.
      Returns:
      The authentication. Either empty if apiKey was null or the authentication.
      Throws:
      org.springframework.security.authentication.BadCredentialsException - If the apiKey is not null, 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.