public Mono<Void> doFilter(ServerWebExchange exchange, WebFilterChain chain) { return chain.filter(exchange); } }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { return chain.filter(exchange); } }
@Override public Mono<Void> doFilter(ServerWebExchange exchange, WebFilterChain chain) { return doAsyncWork().flatMap(asyncResult -> { logger.debug("Async result: " + asyncResult); return chain.filter(exchange); }); }
/** * Transform an HTTP POST into another method based on {@code methodParamName}. * @param exchange the current server exchange * @param chain provides a way to delegate to the next filter * @return {@code Mono<Void>} to indicate when request processing is complete */ @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getMethod() != HttpMethod.POST) { return chain.filter(exchange); } return exchange.getFormData() .map(formData -> { String method = formData.getFirst(this.methodParamName); return StringUtils.hasLength(method) ? mapExchange(exchange, method) : exchange; }) .flatMap(chain::filter); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { Map<String, String> weights = getWeights(exchange); groupWeights.forEach((group, config) -> { double r = this.random.nextDouble(); List<Double> ranges = config.ranges; if (log.isTraceEnabled()) { log.trace("Weight for group: "+group +", ranges: "+ranges +", r: "+r); } for (int i = 0; i < ranges.size() - 1; i++) { if (r >= ranges.get(i) && r < ranges.get(i+1)) { String routeId = config.rangeIndexes.get(i); weights.put(group, routeId); break; } } }); if (log.isTraceEnabled()) { log.trace("Weights attr: "+weights); } return chain.filter(exchange); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { return chain.filter(exchange) .subscriberContext(Context.of(ServerWebExchange.class, exchange)); } }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); if (CorsUtils.isCorsRequest(request)) { CorsConfiguration corsConfiguration = this.configSource.getCorsConfiguration(exchange); if (corsConfiguration != null) { boolean isValid = this.processor.process(corsConfiguration, exchange); if (!isValid || CorsUtils.isPreFlightRequest(request)) { return Mono.empty(); } } } return chain.filter(exchange); }
private WebFilter createFilter(String name) { return (exchange, chain) -> { String value = exchange.getAttribute(ATTRIBUTE); value = (value != null ? value + "::" + name : name); exchange.getAttributes().put(ATTRIBUTE, value); return chain.filter(exchange); }; }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { String name = "test-attribute"; String value = exchange.getAttributeOrDefault(name, ""); exchange.getAttributes().put(name, value + ":" + this.name); return chain.filter(exchange); } }
/** * Transform an HTTP POST into another method based on {@code methodParamName}. * @param exchange the current server exchange * @param chain provides a way to delegate to the next filter * @return {@code Mono<Void>} to indicate when request processing is complete */ @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getMethod() != HttpMethod.POST) { return chain.filter(exchange); } return exchange.getFormData() .map(formData -> { String method = formData.getFirst(this.methodParamName); return StringUtils.hasLength(method) ? mapExchange(exchange, method) : exchange; }) .flatMap(chain::filter); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { return this.requiresAuthenticationMatcher.matches(exchange) .filter( matchResult -> matchResult.isMatch()) .flatMap( matchResult -> this.authenticationConverter.convert(exchange)) .switchIfEmpty(chain.filter(exchange).then(Mono.empty())) .flatMap( token -> authenticate(exchange, chain, token)); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); if (hasForwardedHeaders(request)) { exchange = exchange.mutate().request(apply(request)).build(); } return chain.filter(exchange); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); if (CorsUtils.isCorsRequest(request)) { CorsConfiguration corsConfiguration = this.configSource.getCorsConfiguration(exchange); if (corsConfiguration != null) { boolean isValid = this.processor.process(corsConfiguration, exchange); if (!isValid || CorsUtils.isPreFlightRequest(request)) { return Mono.empty(); } } } return chain.filter(exchange); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { exchange = exchange.mutate().principal(this.userMono).build(); return chain.filter(exchange); } }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { return this.authorizationRequestResolver.resolve(exchange) .switchIfEmpty(chain.filter(exchange).then(Mono.empty())) .onErrorResume(ClientAuthorizationRequiredException.class, e -> { return this.requestCache.saveRequest(exchange) .then(this.authorizationRequestResolver.resolve(exchange, e.getClientRegistrationId())); }) .flatMap(clientRegistration -> sendRedirectForAuthorization(exchange, clientRegistration)); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); if (hasForwardedHeaders(request)) { exchange = exchange.mutate().request(apply(request)).build(); } return chain.filter(exchange); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getURI().getHost().equals("github.com")) { return exchange.getResponse().setComplete(); } return chain.filter(exchange); } }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (tracer().currentSpan() != null) { // clear any previous trace tracer().withSpanInScope(null); } String uri = exchange.getRequest().getPath().pathWithinApplication().value(); if (log.isDebugEnabled()) { log.debug("Received a request to uri [" + uri + "]"); } return new MonoWebFilterTrace(chain.filter(exchange), exchange, this); }
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { return chain.filter(exchange); } };
@Test public void defaultPopulatesReactorContext() { this.spring.register(Config.class).autowire(); Authentication currentPrincipal = new TestingAuthenticationToken("user", "password", "ROLE_USER"); WebSessionServerSecurityContextRepository contextRepository = new WebSessionServerSecurityContextRepository(); SecurityContext context = new SecurityContextImpl(currentPrincipal); WebTestClient client = WebTestClientBuilder.bindToWebFilters( (exchange, chain) -> contextRepository.save(exchange, context) .switchIfEmpty(chain.filter(exchange)) .flatMap(e -> chain.filter(exchange)), this.springSecurityFilterChain, (exchange, chain) -> ReactiveSecurityContextHolder.getContext() .map(SecurityContext::getAuthentication) .flatMap( principal -> exchange.getResponse() .writeWith(Mono.just(toDataBuffer(principal.getName())))) ).build(); client .get() .uri("/") .exchange() .expectStatus().isOk() .expectBody(String.class).consumeWith( result -> assertThat(result.getResponseBody()).isEqualTo(currentPrincipal.getName())); }