Skip to content

Commit b0dbd19

Browse files
committed
use ObjectMapper for JSON serialization in CustomAuthenticationEntryPoint
1 parent b73e2c2 commit b0dbd19

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

backend/spring-boot/src/main/java/org/bugzkit/api/shared/error/handling/CustomAuthenticationEntryPoint.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414
import org.springframework.security.core.AuthenticationException;
1515
import org.springframework.security.web.AuthenticationEntryPoint;
1616
import org.springframework.stereotype.Component;
17+
import tools.jackson.databind.ObjectMapper;
1718

1819
@Slf4j
1920
@Component
2021
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
2122
private final MessageService messageService;
23+
private final ObjectMapper objectMapper;
2224

23-
public CustomAuthenticationEntryPoint(MessageService messageService) {
25+
public CustomAuthenticationEntryPoint(MessageService messageService, ObjectMapper objectMapper) {
2426
this.messageService = messageService;
27+
this.objectMapper = objectMapper;
2528
}
2629

2730
@Override
@@ -37,7 +40,7 @@ public void commence(
3740
response.setHeader(HttpHeaders.X_REQUEST_ID, requestId);
3841
response.setContentType(MediaType.APPLICATION_PROBLEM_JSON_VALUE);
3942
response.setStatus(HttpStatus.UNAUTHORIZED.value());
40-
response.getOutputStream().println(errorMessage.toString());
43+
objectMapper.writeValue(response.getOutputStream(), errorMessage);
4144
log.error("Auth failed", e);
4245
MDC.clear();
4346
}

0 commit comments

Comments
 (0)