Add logging for invalid authentication principal in AuthenticatedUuid and annotate with @Slf4j

This commit is contained in:
akastijn 2025-10-24 21:43:50 +02:00
parent bc0739f707
commit 6531526278

View File

@ -1,5 +1,7 @@
package com.alttd.altitudeweb.controllers.data_from_auth;
import com.nimbusds.jwt.JWT;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
@ -10,6 +12,7 @@ import org.springframework.web.server.ResponseStatusException;
import java.util.UUID;
@Slf4j
@Service
public class AuthenticatedUuid {
@Value("${UNSECURED:#{false}}")
@ -25,6 +28,9 @@ public class AuthenticatedUuid {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || !(authentication.getPrincipal() instanceof Jwt jwt)) {
log.error("Authentication principal is null {} or not a JWT {}",
authentication == null, authentication == null ?
"null" : authentication.getPrincipal() instanceof JWT);
if (unsecured) {
return UUID.fromString("55e46bc3-2a29-4c53-850f-dbd944dc5c5f");
}