SecurityContextRepository save return Mono<Void>

This commit is contained in:
Rob Winch 2017-09-11 20:18:13 -05:00
parent 8ce3b08136
commit 8e80398715
5 changed files with 8 additions and 8 deletions

View File

@ -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(

View File

@ -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);
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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);