-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProblemServerAuthenticationEntryPoint.java
30 lines (25 loc) · 1.17 KB
/
ProblemServerAuthenticationEntryPoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.ksoot.problem.spring.advice.security;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ksoot.problem.spring.advice.webflux.SpringWebfluxProblemResponseUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ProblemDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@RequiredArgsConstructor
public class ProblemServerAuthenticationEntryPoint implements ServerAuthenticationEntryPoint {
private final SecurityAdviceTraits<ServerWebExchange, Mono<ResponseEntity<ProblemDetail>>> advice;
private final ObjectMapper objectMapper;
@Override
public Mono<Void> commence(
final ServerWebExchange exchange, final AuthenticationException exception) {
return this.advice
.handleAuthenticationException(exception, exchange)
.flatMap(
entity ->
SpringWebfluxProblemResponseUtils.writeResponse(
entity, exchange, this.objectMapper));
}
}