forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultServerAuthenticationEntryPoint.java
31 lines (27 loc) · 1.12 KB
/
DefaultServerAuthenticationEntryPoint.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
31
package run.halo.app.security;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
* Default authentication entry point.
* See <a href="https://datatracker.ietf.org/doc/html/rfc7235#section-4.1">
* https://datatracker.ietf.org/doc/html/rfc7235#section-4.1</a>
* for more.
*
* @author johnniang
*/
public class DefaultServerAuthenticationEntryPoint implements ServerAuthenticationEntryPoint {
@Override
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex) {
return Mono.defer(() -> {
var response = exchange.getResponse();
var wwwAuthenticate = "FormLogin realm=\"console\"";
response.getHeaders().set(HttpHeaders.WWW_AUTHENTICATE, wwwAuthenticate);
response.setStatusCode(HttpStatus.UNAUTHORIZED);
return response.setComplete();
});
}
}