Skip to content

Commit

Permalink
Debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
GodCipher committed May 29, 2024
1 parent f2e2e18 commit ecd31d0
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.luzifer.spring.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

@Slf4j
public class ApiKeyAuthenticationProvider implements AuthenticationProvider {

private final String apiKey;
Expand All @@ -17,10 +19,16 @@ public ApiKeyAuthenticationProvider(String apiKey) {
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
ApiKeyAuthenticationToken authenticationToken = (ApiKeyAuthenticationToken) authentication;

log.info(
"Authenticating API key {} against actual API key {}",
authenticationToken.getCredentials(),
apiKey);
if (authenticationToken.getCredentials() instanceof String credentials) {
if (apiKey.equals(credentials)) {
log.info("API key {} authenticated successfully", apiKey);
return new ApiKeyAuthenticationToken(apiKey, apiKey);
}
log.info("API key {} was not the expected value", credentials);
}

throw new BadCredentialsException("The API key was not found or not the expected value.");
Expand Down

0 comments on commit ecd31d0

Please sign in to comment.