Browse Source

SecurityContextRepository save return Mono<Void>

Rob Winch 8 năm trước cách đây
mục cha
commit
8e80398715

+ 1 - 1
webflux/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java

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

+ 1 - 1
webflux/src/main/java/org/springframework/security/web/server/context/SecurityContextRepository.java

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

+ 3 - 3
webflux/src/main/java/org/springframework/security/web/server/context/ServerWebExchangeAttributeSecurityContextRepository.java

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

+ 2 - 2
webflux/src/main/java/org/springframework/security/web/server/context/WebSessionSecurityContextRepository.java

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

+ 1 - 1
webflux/src/test/java/org/springframework/security/web/server/context/ServerWebExchangeAttributeSecurityContextRepositoryTests.java

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