1
0
mirror of synced 2026-08-05 17:57:15 +00:00

ReactorContextWebFilter preserves main Context

Previously ReactorContextWebFilter overrode
the main Context.

Fixes: gh-4962
This commit is contained in:
Rob Winch
2018-02-08 14:58:08 -06:00
parent c399987450
commit 141e3f581f
2 changed files with 31 additions and 2 deletions
@@ -22,6 +22,7 @@ import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;
/**
* @author Rob Winch
@@ -39,8 +40,12 @@ public class ReactorContextWebFilter implements WebFilter {
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange)
.subscriberContext(c -> c.hasKey(SecurityContext.class) ? c :
Mono.defer(() -> this.repository.load(exchange))
.as(ReactiveSecurityContextHolder::withSecurityContext)
withSecurityContext(c, exchange)
);
}
private Context withSecurityContext(Context mainContext, ServerWebExchange exchange) {
return mainContext.putAll(Mono.defer(() -> this.repository.load(exchange))
.as(ReactiveSecurityContextHolder::withSecurityContext));
}
}