mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-24 11:13:30 +00:00
SecurityContextRepository save return Mono<Void>
This commit is contained in:
parent
8ce3b08136
commit
8e80398715
@ -76,7 +76,7 @@ public class AuthenticationWebFilter implements WebFilter {
|
||||
SecurityContextImpl securityContext = new SecurityContextImpl();
|
||||
securityContext.setAuthentication(authentication);
|
||||
return this.securityContextRepository.save(exchange, securityContext)
|
||||
.flatMap( wrappedExchange -> this.authenticationSuccessHandler.success(authentication, wrappedExchange, chain));
|
||||
.then(this.authenticationSuccessHandler.success(authentication, exchange, chain));
|
||||
}
|
||||
|
||||
public void setSecurityContextRepository(
|
||||
|
@ -24,7 +24,7 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
public interface SecurityContextRepository {
|
||||
|
||||
Mono<ServerWebExchange> save(ServerWebExchange exchange, SecurityContext context);
|
||||
Mono<Void> save(ServerWebExchange exchange, SecurityContext context);
|
||||
|
||||
Mono<SecurityContext> load(ServerWebExchange exchange);
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ import reactor.core.publisher.Mono;
|
||||
public class ServerWebExchangeAttributeSecurityContextRepository implements SecurityContextRepository {
|
||||
final String ATTR = "USER";
|
||||
|
||||
public Mono<ServerWebExchange> save(ServerWebExchange exchange, SecurityContext context) {
|
||||
exchange.getAttributes().put(ATTR, context);
|
||||
return Mono.just(new SecurityContextRepositoryServerWebExchange(exchange, this));
|
||||
public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
|
||||
return Mono.fromRunnable(() ->exchange.getAttributes().put(ATTR, context));
|
||||
|
||||
}
|
||||
|
||||
public Mono<SecurityContext> load(ServerWebExchange exchange) {
|
||||
|
@ -30,10 +30,10 @@ import reactor.core.publisher.Mono;
|
||||
public class WebSessionSecurityContextRepository implements SecurityContextRepository {
|
||||
final String SESSION_ATTR = "USER";
|
||||
|
||||
public Mono<ServerWebExchange> save(ServerWebExchange exchange, SecurityContext context) {
|
||||
public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
|
||||
return exchange.getSession()
|
||||
.doOnNext(session -> session.getAttributes().put(SESSION_ATTR, context))
|
||||
.flatMap( session -> Mono.just(new SecurityContextRepositoryServerWebExchange(exchange, this)));
|
||||
.then();
|
||||
}
|
||||
|
||||
public Mono<SecurityContext> load(ServerWebExchange exchange) {
|
||||
|
@ -38,7 +38,7 @@ public class ServerWebExchangeAttributeSecurityContextRepositoryTests {
|
||||
@Test
|
||||
public void saveAndLoad() {
|
||||
SecurityContext context = new SecurityContextImpl();
|
||||
this.repository.save(this.exchange, context);
|
||||
this.repository.save(this.exchange, context).block();
|
||||
|
||||
Mono<SecurityContext> loaded = this.repository.load(this.exchange);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user