Use parenthesis with single-arg lambdas
Use regular expression search/replace to ensure all single-arg lambdas have parenthesis. This aligns with the style used in Spring Boot and ensure that single-arg and multi-arg lambdas are consistent. Issue gh-8945
This commit is contained in:
+1
-1
@@ -233,7 +233,7 @@ public class ExceptionTranslationFilter extends GenericFilterBean {
|
||||
protected void initExtractorMap() {
|
||||
super.initExtractorMap();
|
||||
|
||||
registerExtractor(ServletException.class, throwable -> {
|
||||
registerExtractor(ServletException.class, (throwable) -> {
|
||||
ThrowableAnalyzer.verifyThrowableHierarchy(throwable, ServletException.class);
|
||||
return ((ServletException) throwable).getRootCause();
|
||||
});
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
public AuthenticationFilter(AuthenticationManager authenticationManager,
|
||||
AuthenticationConverter authenticationConverter) {
|
||||
this((AuthenticationManagerResolver<HttpServletRequest>) r -> authenticationManager, authenticationConverter);
|
||||
this((AuthenticationManagerResolver<HttpServletRequest>) (r) -> authenticationManager, authenticationConverter);
|
||||
}
|
||||
|
||||
public AuthenticationFilter(AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver,
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public final class CookieClearingLogoutHandler implements LogoutHandler {
|
||||
|
||||
@Override
|
||||
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
|
||||
this.cookiesToClear.forEach(f -> response.addCookie(f.apply(request)));
|
||||
this.cookiesToClear.forEach((f) -> response.addCookie(f.apply(request)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class DefaultLoginPageGeneratingFilter extends GenericFilterBean {
|
||||
|
||||
private Map<String, String> saml2AuthenticationUrlToProviderName;
|
||||
|
||||
private Function<HttpServletRequest, Map<String, String>> resolveHiddenInputs = request -> Collections.emptyMap();
|
||||
private Function<HttpServletRequest, Map<String, String>> resolveHiddenInputs = (request) -> Collections.emptyMap();
|
||||
|
||||
public DefaultLoginPageGeneratingFilter() {
|
||||
}
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class DefaultLogoutPageGeneratingFilter extends OncePerRequestFilter {
|
||||
|
||||
private RequestMatcher matcher = new AntPathRequestMatcher("/logout", "GET");
|
||||
|
||||
private Function<HttpServletRequest, Map<String, String>> resolveHiddenInputs = request -> Collections.emptyMap();
|
||||
private Function<HttpServletRequest, Map<String, String>> resolveHiddenInputs = (request) -> Collections.emptyMap();
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
|
||||
@@ -112,13 +112,13 @@ public class StrictHttpFirewall implements HttpFirewall {
|
||||
|
||||
private Set<String> allowedHttpMethods = createDefaultAllowedHttpMethods();
|
||||
|
||||
private Predicate<String> allowedHostnames = hostname -> true;
|
||||
private Predicate<String> allowedHostnames = (hostname) -> true;
|
||||
|
||||
private static final Pattern ASSIGNED_AND_NOT_ISO_CONTROL_PATTERN = Pattern
|
||||
.compile("[\\p{IsAssigned}&&[^\\p{IsControl}]]*");
|
||||
|
||||
private static final Predicate<String> ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE = s -> ASSIGNED_AND_NOT_ISO_CONTROL_PATTERN
|
||||
.matcher(s).matches();
|
||||
private static final Predicate<String> ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE = (
|
||||
s) -> ASSIGNED_AND_NOT_ISO_CONTROL_PATTERN.matcher(s).matches();
|
||||
|
||||
private Predicate<String> allowedHeaderNames = ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE;
|
||||
|
||||
@@ -126,7 +126,7 @@ public class StrictHttpFirewall implements HttpFirewall {
|
||||
|
||||
private Predicate<String> allowedParameterNames = ASSIGNED_AND_NOT_ISO_CONTROL_PREDICATE;
|
||||
|
||||
private Predicate<String> allowedParameterValues = value -> true;
|
||||
private Predicate<String> allowedParameterValues = (value) -> true;
|
||||
|
||||
public StrictHttpFirewall() {
|
||||
urlBlocklistsAddAll(FORBIDDEN_SEMICOLON);
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class CompositeHeaderWriter implements HeaderWriter {
|
||||
|
||||
@Override
|
||||
public void writeHeaders(HttpServletRequest request, HttpServletResponse response) {
|
||||
this.headerWriters.forEach(headerWriter -> headerWriter.writeHeaders(request, response));
|
||||
this.headerWriters.forEach((headerWriter) -> headerWriter.writeHeaders(request, response));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class SecurityHeaders {
|
||||
*/
|
||||
public static Consumer<HttpHeaders> bearerToken(String bearerTokenValue) {
|
||||
Assert.hasText(bearerTokenValue, "bearerTokenValue cannot be null");
|
||||
return headers -> headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + bearerTokenValue);
|
||||
return (headers) -> headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + bearerTokenValue);
|
||||
}
|
||||
|
||||
private SecurityHeaders() {
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class AuthenticationPrincipalArgumentResolver extends HandlerMethodArgume
|
||||
public Mono<Object> resolveArgument(MethodParameter parameter, BindingContext bindingContext,
|
||||
ServerWebExchange exchange) {
|
||||
ReactiveAdapter adapter = getAdapterRegistry().getAdapter(parameter.getParameterType());
|
||||
return ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication).flatMap(a -> {
|
||||
return ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication).flatMap((a) -> {
|
||||
Object p = resolvePrincipal(parameter, a.getPrincipal());
|
||||
Mono<Object> principal = Mono.justOrEmpty(p);
|
||||
return adapter == null ? principal : Mono.just(adapter.fromPublisher(principal));
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ public class CurrentSecurityContextArgumentResolver extends HandlerMethodArgumen
|
||||
if (reactiveSecurityContext == null) {
|
||||
return null;
|
||||
}
|
||||
return reactiveSecurityContext.flatMap(a -> {
|
||||
return reactiveSecurityContext.flatMap((a) -> {
|
||||
Object p = resolveSecurityContext(parameter, a);
|
||||
Mono<Object> o = Mono.justOrEmpty(p);
|
||||
return adapter == null ? o : Mono.just(adapter.fromPublisher(o));
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ public class DefaultSavedRequest implements SavedRequest {
|
||||
}
|
||||
|
||||
private void addHeader(String name, String value) {
|
||||
List<String> values = this.headers.computeIfAbsent(name, k -> new ArrayList<>());
|
||||
List<String> values = this.headers.computeIfAbsent(name, (k) -> new ArrayList<>());
|
||||
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
+5
-5
@@ -60,16 +60,16 @@ public class DelegatingServerAuthenticationEntryPoint implements ServerAuthentic
|
||||
|
||||
@Override
|
||||
public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex) {
|
||||
return Flux.fromIterable(this.entryPoints).filterWhen(entry -> isMatch(exchange, entry)).next()
|
||||
.map(entry -> entry.getEntryPoint()).doOnNext(it -> {
|
||||
return Flux.fromIterable(this.entryPoints).filterWhen((entry) -> isMatch(exchange, entry)).next()
|
||||
.map((entry) -> entry.getEntryPoint()).doOnNext((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Match found! Executing " + it);
|
||||
}
|
||||
}).switchIfEmpty(Mono.just(this.defaultEntryPoint).doOnNext(it -> {
|
||||
}).switchIfEmpty(Mono.just(this.defaultEntryPoint).doOnNext((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("No match found. Using default entry point " + this.defaultEntryPoint);
|
||||
}
|
||||
})).flatMap(entryPoint -> entryPoint.commence(exchange, ex));
|
||||
})).flatMap((entryPoint) -> entryPoint.commence(exchange, ex));
|
||||
}
|
||||
|
||||
private Mono<Boolean> isMatch(ServerWebExchange exchange, DelegateEntry entry) {
|
||||
@@ -77,7 +77,7 @@ public class DelegatingServerAuthenticationEntryPoint implements ServerAuthentic
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Trying to match using " + matcher);
|
||||
}
|
||||
return matcher.matches(exchange).map(result -> result.isMatch());
|
||||
return matcher.matches(exchange).map((result) -> result.isMatch());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class MatcherSecurityWebFilterChain implements SecurityWebFilterChain {
|
||||
|
||||
@Override
|
||||
public Mono<Boolean> matches(ServerWebExchange exchange) {
|
||||
return this.matcher.matches(exchange).map(m -> m.isMatch());
|
||||
return this.matcher.matches(exchange).map((m) -> m.isMatch());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class ServerFormLoginAuthenticationConverter implements Function<ServerWe
|
||||
@Override
|
||||
@Deprecated
|
||||
public Mono<Authentication> apply(ServerWebExchange exchange) {
|
||||
return exchange.getFormData().map(data -> createAuthentication(data));
|
||||
return exchange.getFormData().map((data) -> createAuthentication(data));
|
||||
}
|
||||
|
||||
private UsernamePasswordAuthenticationToken createAuthentication(MultiValueMap<String, String> data) {
|
||||
|
||||
@@ -49,12 +49,12 @@ public class WebFilterChainProxy implements WebFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return Flux.fromIterable(this.filters)
|
||||
.filterWhen(securityWebFilterChain -> securityWebFilterChain.matches(exchange)).next()
|
||||
.filterWhen((securityWebFilterChain) -> securityWebFilterChain.matches(exchange)).next()
|
||||
.switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
|
||||
.flatMap(securityWebFilterChain -> securityWebFilterChain.getWebFilters().collectList())
|
||||
.map(filters -> new FilteringWebHandler(webHandler -> chain.filter(webHandler), filters))
|
||||
.map(handler -> new DefaultWebFilterChain(handler))
|
||||
.flatMap(securedChain -> securedChain.filter(exchange));
|
||||
.flatMap((securityWebFilterChain) -> securityWebFilterChain.getWebFilters().collectList())
|
||||
.map((filters) -> new FilteringWebHandler((webHandler) -> chain.filter(webHandler), filters))
|
||||
.map((handler) -> new DefaultWebFilterChain(handler))
|
||||
.flatMap((securedChain) -> securedChain.filter(exchange));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class AnonymousAuthenticationWebFilter implements WebFilter {
|
||||
return chain.filter(exchange)
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext)))
|
||||
.then(Mono.empty());
|
||||
})).flatMap(securityContext -> {
|
||||
})).flatMap((securityContext) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("SecurityContext contains anonymous token: '" + securityContext.getAuthentication() + "'");
|
||||
}
|
||||
|
||||
+2
-2
@@ -43,8 +43,8 @@ public final class AuthenticationConverterServerWebExchangeMatcher implements Se
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(ServerWebExchange exchange) {
|
||||
return this.serverAuthenticationConverter.convert(exchange).flatMap(a -> MatchResult.match())
|
||||
.onErrorResume(e -> MatchResult.notMatch()).switchIfEmpty(MatchResult.notMatch());
|
||||
return this.serverAuthenticationConverter.convert(exchange).flatMap((a) -> MatchResult.match())
|
||||
.onErrorResume((e) -> MatchResult.notMatch()).switchIfEmpty(MatchResult.notMatch());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-8
@@ -91,7 +91,7 @@ public class AuthenticationWebFilter implements WebFilter {
|
||||
*/
|
||||
public AuthenticationWebFilter(ReactiveAuthenticationManager authenticationManager) {
|
||||
Assert.notNull(authenticationManager, "authenticationManager cannot be null");
|
||||
this.authenticationManagerResolver = request -> Mono.just(authenticationManager);
|
||||
this.authenticationManagerResolver = (request) -> Mono.just(authenticationManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,22 +107,22 @@ public class AuthenticationWebFilter implements WebFilter {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return this.requiresAuthenticationMatcher.matches(exchange).filter(matchResult -> matchResult.isMatch())
|
||||
.flatMap(matchResult -> this.authenticationConverter.convert(exchange))
|
||||
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))
|
||||
.onErrorResume(AuthenticationException.class, e -> this.authenticationFailureHandler
|
||||
.flatMap((token) -> authenticate(exchange, chain, token))
|
||||
.onErrorResume(AuthenticationException.class, (e) -> this.authenticationFailureHandler
|
||||
.onAuthenticationFailure(new WebFilterExchange(exchange, chain), e));
|
||||
}
|
||||
|
||||
private Mono<Void> authenticate(ServerWebExchange exchange, WebFilterChain chain, Authentication token) {
|
||||
return this.authenticationManagerResolver.resolve(exchange)
|
||||
.flatMap(authenticationManager -> authenticationManager.authenticate(token))
|
||||
.flatMap((authenticationManager) -> authenticationManager.authenticate(token))
|
||||
.switchIfEmpty(Mono.defer(
|
||||
() -> Mono.error(new IllegalStateException("No provider found for " + token.getClass()))))
|
||||
.flatMap(authentication -> onAuthenticationSuccess(authentication,
|
||||
.flatMap((authentication) -> onAuthenticationSuccess(authentication,
|
||||
new WebFilterExchange(exchange, chain)))
|
||||
.doOnError(AuthenticationException.class, e -> {
|
||||
.doOnError(AuthenticationException.class, (e) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Authentication failed: " + e.getMessage());
|
||||
}
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class DelegatingServerAuthenticationSuccessHandler implements ServerAuthe
|
||||
@Override
|
||||
public Mono<Void> onAuthenticationSuccess(WebFilterExchange exchange, Authentication authentication) {
|
||||
return Flux.fromIterable(this.delegates)
|
||||
.concatMap(delegate -> delegate.onAuthenticationSuccess(exchange, authentication)).then();
|
||||
.concatMap((delegate) -> delegate.onAuthenticationSuccess(exchange, authentication)).then();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ public class ReactivePreAuthenticatedAuthenticationManager implements ReactiveAu
|
||||
return Mono.just(authentication).filter(this::supports).map(Authentication::getName)
|
||||
.flatMap(this.userDetailsService::findByUsername)
|
||||
.switchIfEmpty(Mono.error(() -> new UsernameNotFoundException("User not found")))
|
||||
.doOnNext(this.userDetailsChecker::check).map(ud -> {
|
||||
.doOnNext(this.userDetailsChecker::check).map((ud) -> {
|
||||
PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(ud,
|
||||
authentication.getCredentials(), ud.getAuthorities());
|
||||
result.setDetails(authentication.getDetails());
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class RedirectServerAuthenticationSuccessHandler implements ServerAuthent
|
||||
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange, Authentication authentication) {
|
||||
ServerWebExchange exchange = webFilterExchange.getExchange();
|
||||
return this.requestCache.getRedirectUri(exchange).defaultIfEmpty(this.location)
|
||||
.flatMap(location -> this.redirectStrategy.sendRedirect(exchange, location));
|
||||
.flatMap((location) -> this.redirectStrategy.sendRedirect(exchange, location));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
-8
@@ -168,8 +168,8 @@ public class SwitchUserWebFilter implements WebFilter {
|
||||
|
||||
return switchUser(webFilterExchange).switchIfEmpty(Mono.defer(() -> exitSwitchUser(webFilterExchange)))
|
||||
.switchIfEmpty(Mono.defer(() -> chain.filter(exchange).then(Mono.empty())))
|
||||
.flatMap(authentication -> onAuthenticationSuccess(authentication, webFilterExchange))
|
||||
.onErrorResume(SwitchUserAuthenticationException.class, exception -> Mono.empty());
|
||||
.flatMap((authentication) -> onAuthenticationSuccess(authentication, webFilterExchange))
|
||||
.onErrorResume(SwitchUserAuthenticationException.class, (exception) -> Mono.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,11 +183,11 @@ public class SwitchUserWebFilter implements WebFilter {
|
||||
protected Mono<Authentication> switchUser(WebFilterExchange webFilterExchange) {
|
||||
return this.switchUserMatcher.matches(webFilterExchange.getExchange())
|
||||
.filter(ServerWebExchangeMatcher.MatchResult::isMatch)
|
||||
.flatMap(matchResult -> ReactiveSecurityContextHolder.getContext())
|
||||
.map(SecurityContext::getAuthentication).flatMap(currentAuthentication -> {
|
||||
.flatMap((matchResult) -> ReactiveSecurityContextHolder.getContext())
|
||||
.map(SecurityContext::getAuthentication).flatMap((currentAuthentication) -> {
|
||||
final String username = getUsername(webFilterExchange.getExchange());
|
||||
return attemptSwitchUser(currentAuthentication, username);
|
||||
}).onErrorResume(AuthenticationException.class, e -> onAuthenticationFailure(e, webFilterExchange)
|
||||
}).onErrorResume(AuthenticationException.class, (e) -> onAuthenticationFailure(e, webFilterExchange)
|
||||
.then(Mono.error(new SwitchUserAuthenticationException(e))));
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class SwitchUserWebFilter implements WebFilter {
|
||||
protected Mono<Authentication> exitSwitchUser(WebFilterExchange webFilterExchange) {
|
||||
return this.exitUserMatcher.matches(webFilterExchange.getExchange())
|
||||
.filter(ServerWebExchangeMatcher.MatchResult::isMatch)
|
||||
.flatMap(matchResult -> ReactiveSecurityContextHolder.getContext()
|
||||
.flatMap((matchResult) -> ReactiveSecurityContextHolder.getContext()
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.switchIfEmpty(Mono.error(this::noCurrentUserException)))
|
||||
.map(this::attemptExitUser);
|
||||
@@ -228,7 +228,7 @@ public class SwitchUserWebFilter implements WebFilter {
|
||||
return this.userDetailsService.findByUsername(userName)
|
||||
.switchIfEmpty(Mono.error(this::noTargetAuthenticationException))
|
||||
.doOnNext(this.userDetailsChecker::check)
|
||||
.map(userDetails -> createSwitchUserToken(userDetails, currentAuthentication));
|
||||
.map((userDetails) -> createSwitchUserToken(userDetails, currentAuthentication));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -255,7 +255,7 @@ public class SwitchUserWebFilter implements WebFilter {
|
||||
return Mono.justOrEmpty(this.failureHandler).switchIfEmpty(Mono.defer(() -> {
|
||||
this.logger.error("Switch User failed", exception);
|
||||
return Mono.error(exception);
|
||||
})).flatMap(failureHandler -> failureHandler.onAuthenticationFailure(webFilterExchange, exception));
|
||||
})).flatMap((failureHandler) -> failureHandler.onAuthenticationFailure(webFilterExchange, exception));
|
||||
}
|
||||
|
||||
private Authentication createSwitchUserToken(UserDetails targetUser, Authentication currentAuthentication) {
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class DelegatingServerLogoutHandler implements ServerLogoutHandler {
|
||||
|
||||
@Override
|
||||
public Mono<Void> logout(WebFilterExchange exchange, Authentication authentication) {
|
||||
return Flux.fromIterable(this.delegates).concatMap(delegate -> delegate.logout(exchange, authentication))
|
||||
return Flux.fromIterable(this.delegates).concatMap((delegate) -> delegate.logout(exchange, authentication))
|
||||
.then();
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -57,9 +57,9 @@ public class LogoutWebFilter implements WebFilter {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return this.requiresLogout.matches(exchange).filter(result -> result.isMatch())
|
||||
.switchIfEmpty(chain.filter(exchange).then(Mono.empty())).map(result -> exchange)
|
||||
.flatMap(this::flatMapAuthentication).flatMap(authentication -> {
|
||||
return this.requiresLogout.matches(exchange).filter((result) -> result.isMatch())
|
||||
.switchIfEmpty(chain.filter(exchange).then(Mono.empty())).map((result) -> exchange)
|
||||
.flatMap(this::flatMapAuthentication).flatMap((authentication) -> {
|
||||
WebFilterExchange webFilterExchange = new WebFilterExchange(exchange, chain);
|
||||
return logout(webFilterExchange, authentication);
|
||||
});
|
||||
|
||||
+4
-3
@@ -45,13 +45,14 @@ public class AuthorizationWebFilter implements WebFilter {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return ReactiveSecurityContextHolder.getContext().filter(c -> c.getAuthentication() != null)
|
||||
return ReactiveSecurityContextHolder.getContext().filter((c) -> c.getAuthentication() != null)
|
||||
.map(SecurityContext::getAuthentication)
|
||||
.as(authentication -> this.authorizationManager.verify(authentication, exchange)).doOnSuccess(it -> {
|
||||
.as((authentication) -> this.authorizationManager.verify(authentication, exchange))
|
||||
.doOnSuccess((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Authorization successful");
|
||||
}
|
||||
}).doOnError(AccessDeniedException.class, e -> {
|
||||
}).doOnError(AccessDeniedException.class, (e) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Authorization failed: " + e.getMessage());
|
||||
}
|
||||
|
||||
+2
-2
@@ -49,8 +49,8 @@ public final class DelegatingReactiveAuthorizationManager implements ReactiveAut
|
||||
|
||||
@Override
|
||||
public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, ServerWebExchange exchange) {
|
||||
return Flux.fromIterable(this.mappings).concatMap(mapping -> mapping.getMatcher().matches(exchange)
|
||||
.filter(MatchResult::isMatch).map(MatchResult::getVariables).flatMap(variables -> {
|
||||
return Flux.fromIterable(this.mappings).concatMap((mapping) -> mapping.getMatcher().matches(exchange)
|
||||
.filter(MatchResult::isMatch).map(MatchResult::getVariables).flatMap((variables) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
"Checking authorization on '" + exchange.getRequest().getPath().pathWithinApplication()
|
||||
|
||||
+2
-2
@@ -42,8 +42,8 @@ public class ExceptionTranslationWebFilter implements WebFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return chain.filter(exchange).onErrorResume(AccessDeniedException.class,
|
||||
denied -> exchange.getPrincipal().switchIfEmpty(commenceAuthentication(exchange, denied))
|
||||
.flatMap(principal -> this.accessDeniedHandler.handle(exchange, denied)));
|
||||
(denied) -> exchange.getPrincipal().switchIfEmpty(commenceAuthentication(exchange, denied))
|
||||
.flatMap((principal) -> this.accessDeniedHandler.handle(exchange, denied)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -50,12 +50,12 @@ public class HttpStatusServerAccessDeniedHandler implements ServerAccessDeniedHa
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException ex) {
|
||||
return Mono.defer(() -> Mono.just(exchange.getResponse())).flatMap(response -> {
|
||||
return Mono.defer(() -> Mono.just(exchange.getResponse())).flatMap((response) -> {
|
||||
response.setStatusCode(this.httpStatus);
|
||||
response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
|
||||
DataBufferFactory dataBufferFactory = response.bufferFactory();
|
||||
DataBuffer buffer = dataBufferFactory.wrap(ex.getMessage().getBytes(Charset.defaultCharset()));
|
||||
return response.writeWith(Mono.just(buffer)).doOnError(error -> DataBufferUtils.release(buffer));
|
||||
return response.writeWith(Mono.just(buffer)).doOnError((error) -> DataBufferUtils.release(buffer));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -69,9 +69,9 @@ public class ServerWebExchangeDelegatingServerAccessDeniedHandler implements Ser
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange, AccessDeniedException denied) {
|
||||
return Flux.fromIterable(this.handlers).filterWhen(entry -> isMatch(exchange, entry)).next()
|
||||
return Flux.fromIterable(this.handlers).filterWhen((entry) -> isMatch(exchange, entry)).next()
|
||||
.map(DelegateEntry::getAccessDeniedHandler).defaultIfEmpty(this.defaultHandler)
|
||||
.flatMap(handler -> handler.handle(exchange, denied));
|
||||
.flatMap((handler) -> handler.handle(exchange, denied));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public class ReactorContextWebFilter implements WebFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return chain.filter(exchange)
|
||||
.subscriberContext(c -> c.hasKey(SecurityContext.class) ? c : withSecurityContext(c, exchange));
|
||||
.subscriberContext((c) -> c.hasKey(SecurityContext.class) ? c : withSecurityContext(c, exchange));
|
||||
}
|
||||
|
||||
private Context withSecurityContext(Context mainContext, ServerWebExchange exchange) {
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class SecurityContextServerWebExchange extends ServerWebExchangeDecorator
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Principal> Mono<T> getPrincipal() {
|
||||
return this.context.map(c -> (T) c.getAuthentication());
|
||||
return this.context.map((c) -> (T) c.getAuthentication());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -56,7 +56,7 @@ public class WebSessionServerSecurityContextRepository implements ServerSecurity
|
||||
|
||||
@Override
|
||||
public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
|
||||
return exchange.getSession().doOnNext(session -> {
|
||||
return exchange.getSession().doOnNext((session) -> {
|
||||
if (context == null) {
|
||||
session.getAttributes().remove(this.springSecurityContextAttrName);
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -69,12 +69,12 @@ public class WebSessionServerSecurityContextRepository implements ServerSecurity
|
||||
logger.debug("Saved SecurityContext '" + context + "' in WebSession: '" + session + "'");
|
||||
}
|
||||
}
|
||||
}).flatMap(session -> session.changeSessionId());
|
||||
}).flatMap((session) -> session.changeSessionId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<SecurityContext> load(ServerWebExchange exchange) {
|
||||
return exchange.getSession().flatMap(session -> {
|
||||
return exchange.getSession().flatMap((session) -> {
|
||||
SecurityContext context = (SecurityContext) session.getAttribute(this.springSecurityContextAttrName);
|
||||
if (logger.isDebugEnabled()) {
|
||||
if (context == null) {
|
||||
|
||||
@@ -116,11 +116,11 @@ public class CsrfWebFilter implements WebFilter {
|
||||
return chain.filter(exchange).then(Mono.empty());
|
||||
}
|
||||
|
||||
return this.requireCsrfProtectionMatcher.matches(exchange).filter(matchResult -> matchResult.isMatch())
|
||||
.filter(matchResult -> !exchange.getAttributes().containsKey(CsrfToken.class.getName()))
|
||||
.flatMap(m -> validateToken(exchange)).flatMap(m -> continueFilterChain(exchange, chain))
|
||||
return this.requireCsrfProtectionMatcher.matches(exchange).filter((matchResult) -> matchResult.isMatch())
|
||||
.filter((matchResult) -> !exchange.getAttributes().containsKey(CsrfToken.class.getName()))
|
||||
.flatMap((m) -> validateToken(exchange)).flatMap((m) -> continueFilterChain(exchange, chain))
|
||||
.switchIfEmpty(continueFilterChain(exchange, chain).then(Mono.empty()))
|
||||
.onErrorResume(CsrfException.class, e -> this.accessDeniedHandler.handle(exchange, e));
|
||||
.onErrorResume(CsrfException.class, (e) -> this.accessDeniedHandler.handle(exchange, e));
|
||||
}
|
||||
|
||||
public static void skipExchange(ServerWebExchange exchange) {
|
||||
@@ -131,15 +131,15 @@ public class CsrfWebFilter implements WebFilter {
|
||||
return this.csrfTokenRepository.loadToken(exchange)
|
||||
.switchIfEmpty(Mono
|
||||
.defer(() -> Mono.error(new CsrfException("CSRF Token has been associated to this client"))))
|
||||
.filterWhen(expected -> containsValidCsrfToken(exchange, expected))
|
||||
.filterWhen((expected) -> containsValidCsrfToken(exchange, expected))
|
||||
.switchIfEmpty(Mono.defer(() -> Mono.error(new CsrfException("Invalid CSRF Token")))).then();
|
||||
}
|
||||
|
||||
private Mono<Boolean> containsValidCsrfToken(ServerWebExchange exchange, CsrfToken expected) {
|
||||
return exchange.getFormData().flatMap(data -> Mono.justOrEmpty(data.getFirst(expected.getParameterName())))
|
||||
return exchange.getFormData().flatMap((data) -> Mono.justOrEmpty(data.getFirst(expected.getParameterName())))
|
||||
.switchIfEmpty(Mono.justOrEmpty(exchange.getRequest().getHeaders().getFirst(expected.getHeaderName())))
|
||||
.switchIfEmpty(tokenFromMultipartData(exchange, expected))
|
||||
.map(actual -> actual.equals(expected.getToken()));
|
||||
.map((actual) -> actual.equals(expected.getToken()));
|
||||
}
|
||||
|
||||
private Mono<String> tokenFromMultipartData(ServerWebExchange exchange, CsrfToken expected) {
|
||||
@@ -152,7 +152,7 @@ public class CsrfWebFilter implements WebFilter {
|
||||
if (!contentType.includes(MediaType.MULTIPART_FORM_DATA)) {
|
||||
return Mono.empty();
|
||||
}
|
||||
return exchange.getMultipartData().map(d -> d.getFirst(expected.getParameterName())).cast(FormFieldPart.class)
|
||||
return exchange.getMultipartData().map((d) -> d.getFirst(expected.getParameterName())).cast(FormFieldPart.class)
|
||||
.map(FormFieldPart::value);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class CsrfWebFilter implements WebFilter {
|
||||
|
||||
private Mono<CsrfToken> generateToken(ServerWebExchange exchange) {
|
||||
return this.csrfTokenRepository.generateToken(exchange)
|
||||
.delayUntil(token -> this.csrfTokenRepository.saveToken(exchange, token));
|
||||
.delayUntil((token) -> this.csrfTokenRepository.saveToken(exchange, token));
|
||||
}
|
||||
|
||||
private static class DefaultRequireCsrfProtectionMatcher implements ServerWebExchangeMatcher {
|
||||
@@ -180,8 +180,8 @@ public class CsrfWebFilter implements WebFilter {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(ServerWebExchange exchange) {
|
||||
return Mono.just(exchange.getRequest()).flatMap(r -> Mono.justOrEmpty(r.getMethod()))
|
||||
.filter(m -> ALLOWED_METHODS.contains(m)).flatMap(m -> MatchResult.notMatch())
|
||||
return Mono.just(exchange.getRequest()).flatMap((r) -> Mono.justOrEmpty(r.getMethod()))
|
||||
.filter((m) -> ALLOWED_METHODS.contains(m)).flatMap((m) -> MatchResult.notMatch())
|
||||
.switchIfEmpty(MatchResult.match());
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -58,8 +58,8 @@ public class WebSessionServerCsrfTokenRepository implements ServerCsrfTokenRepos
|
||||
|
||||
@Override
|
||||
public Mono<Void> saveToken(ServerWebExchange exchange, CsrfToken token) {
|
||||
return exchange.getSession().doOnNext(session -> putToken(session.getAttributes(), token))
|
||||
.flatMap(session -> session.changeSessionId());
|
||||
return exchange.getSession().doOnNext((session) -> putToken(session.getAttributes(), token))
|
||||
.flatMap((session) -> session.changeSessionId());
|
||||
}
|
||||
|
||||
private void putToken(Map<String, Object> attributes, CsrfToken token) {
|
||||
@@ -73,8 +73,8 @@ public class WebSessionServerCsrfTokenRepository implements ServerCsrfTokenRepos
|
||||
|
||||
@Override
|
||||
public Mono<CsrfToken> loadToken(ServerWebExchange exchange) {
|
||||
return exchange.getSession().filter(s -> s.getAttributes().containsKey(this.sessionAttributeName))
|
||||
.map(s -> s.getAttribute(this.sessionAttributeName));
|
||||
return exchange.getSession().filter((s) -> s.getAttributes().containsKey(this.sessionAttributeName))
|
||||
.map((s) -> s.getAttribute(this.sessionAttributeName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class CompositeServerHttpHeadersWriter implements ServerHttpHeadersWriter
|
||||
|
||||
@Override
|
||||
public Mono<Void> writeHttpHeaders(ServerWebExchange exchange) {
|
||||
return Flux.fromIterable(this.writers).concatMap(w -> w.writeHttpHeaders(exchange)).then();
|
||||
return Flux.fromIterable(this.writers).concatMap((w) -> w.writeHttpHeaders(exchange)).then();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -71,8 +71,8 @@ public class CookieServerRequestCache implements ServerRequestCache {
|
||||
|
||||
@Override
|
||||
public Mono<Void> saveRequest(ServerWebExchange exchange) {
|
||||
return this.saveRequestMatcher.matches(exchange).filter(m -> m.isMatch()).map(m -> exchange.getResponse())
|
||||
.map(ServerHttpResponse::getCookies).doOnNext(cookies -> {
|
||||
return this.saveRequestMatcher.matches(exchange).filter((m) -> m.isMatch()).map((m) -> exchange.getResponse())
|
||||
.map(ServerHttpResponse::getCookies).doOnNext((cookies) -> {
|
||||
ResponseCookie redirectUriCookie = createRedirectUriCookie(exchange.getRequest());
|
||||
cookies.add(REDIRECT_URI_COOKIE_NAME, redirectUriCookie);
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -86,13 +86,13 @@ public class CookieServerRequestCache implements ServerRequestCache {
|
||||
MultiValueMap<String, HttpCookie> cookieMap = exchange.getRequest().getCookies();
|
||||
return Mono.justOrEmpty(cookieMap.getFirst(REDIRECT_URI_COOKIE_NAME)).map(HttpCookie::getValue)
|
||||
.map(CookieServerRequestCache::decodeCookie)
|
||||
.onErrorResume(IllegalArgumentException.class, e -> Mono.empty()).map(URI::create);
|
||||
.onErrorResume(IllegalArgumentException.class, (e) -> Mono.empty()).map(URI::create);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ServerHttpRequest> removeMatchingRequest(ServerWebExchange exchange) {
|
||||
return Mono.just(exchange.getResponse()).map(ServerHttpResponse::getCookies).doOnNext(
|
||||
cookies -> cookies.add(REDIRECT_URI_COOKIE_NAME, invalidateRedirectUriCookie(exchange.getRequest())))
|
||||
(cookies) -> cookies.add(REDIRECT_URI_COOKIE_NAME, invalidateRedirectUriCookie(exchange.getRequest())))
|
||||
.thenReturn(exchange.getRequest());
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ public class ServerRequestCacheWebFilter implements WebFilter {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return this.requestCache.removeMatchingRequest(exchange).map(r -> exchange.mutate().request(r).build())
|
||||
.defaultIfEmpty(exchange).flatMap(e -> chain.filter(e));
|
||||
return this.requestCache.removeMatchingRequest(exchange).map((r) -> exchange.mutate().request(r).build())
|
||||
.defaultIfEmpty(exchange).flatMap((e) -> chain.filter(e));
|
||||
}
|
||||
|
||||
public void setRequestCache(ServerRequestCache requestCache) {
|
||||
|
||||
+4
-4
@@ -69,7 +69,7 @@ public class WebSessionServerRequestCache implements ServerRequestCache {
|
||||
@Override
|
||||
public Mono<Void> saveRequest(ServerWebExchange exchange) {
|
||||
return this.saveRequestMatcher.matches(exchange).filter(MatchResult::isMatch)
|
||||
.flatMap(m -> exchange.getSession()).map(WebSession::getAttributes).doOnNext(attrs -> {
|
||||
.flatMap((m) -> exchange.getSession()).map(WebSession::getAttributes).doOnNext((attrs) -> {
|
||||
String requestPath = pathInApplication(exchange.getRequest());
|
||||
attrs.put(this.sessionAttrName, requestPath);
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -81,13 +81,13 @@ public class WebSessionServerRequestCache implements ServerRequestCache {
|
||||
@Override
|
||||
public Mono<URI> getRedirectUri(ServerWebExchange exchange) {
|
||||
return exchange.getSession()
|
||||
.flatMap(session -> Mono.justOrEmpty(session.<String>getAttribute(this.sessionAttrName)))
|
||||
.flatMap((session) -> Mono.justOrEmpty(session.<String>getAttribute(this.sessionAttrName)))
|
||||
.map(URI::create);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ServerHttpRequest> removeMatchingRequest(ServerWebExchange exchange) {
|
||||
return exchange.getSession().map(WebSession::getAttributes).filter(attributes -> {
|
||||
return exchange.getSession().map(WebSession::getAttributes).filter((attributes) -> {
|
||||
String requestPath = pathInApplication(exchange.getRequest());
|
||||
boolean removed = attributes.remove(this.sessionAttrName, requestPath);
|
||||
if (removed) {
|
||||
@@ -96,7 +96,7 @@ public class WebSessionServerRequestCache implements ServerRequestCache {
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}).map(attributes -> exchange.getRequest());
|
||||
}).map((attributes) -> exchange.getRequest());
|
||||
}
|
||||
|
||||
private static String pathInApplication(ServerHttpRequest request) {
|
||||
|
||||
+3
-3
@@ -57,9 +57,9 @@ public final class HttpsRedirectWebFilter implements WebFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return Mono.just(exchange).filter(this::isInsecure).flatMap(this.requiresHttpsRedirectMatcher::matches)
|
||||
.filter(matchResult -> matchResult.isMatch()).switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
|
||||
.map(matchResult -> createRedirectUri(exchange))
|
||||
.flatMap(uri -> this.redirectStrategy.sendRedirect(exchange, uri));
|
||||
.filter((matchResult) -> matchResult.isMatch()).switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
|
||||
.map((matchResult) -> createRedirectUri(exchange))
|
||||
.flatMap((uri) -> this.redirectStrategy.sendRedirect(exchange, uri));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ public class LoginPageGeneratingWebFilter implements WebFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return this.matcher.matches(exchange).filter(ServerWebExchangeMatcher.MatchResult::isMatch)
|
||||
.switchIfEmpty(chain.filter(exchange).then(Mono.empty())).flatMap(matchResult -> render(exchange));
|
||||
.switchIfEmpty(chain.filter(exchange).then(Mono.empty())).flatMap((matchResult) -> render(exchange));
|
||||
}
|
||||
|
||||
private Mono<Void> render(ServerWebExchange exchange) {
|
||||
@@ -77,7 +77,7 @@ public class LoginPageGeneratingWebFilter implements WebFilter {
|
||||
private Mono<DataBuffer> createBuffer(ServerWebExchange exchange) {
|
||||
|
||||
Mono<CsrfToken> token = exchange.getAttributeOrDefault(CsrfToken.class.getName(), Mono.empty());
|
||||
return token.map(LoginPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map(csrfTokenHtmlInput -> {
|
||||
return token.map(LoginPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map((csrfTokenHtmlInput) -> {
|
||||
byte[] bytes = createPage(exchange, csrfTokenHtmlInput);
|
||||
DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
|
||||
return bufferFactory.wrap(bytes);
|
||||
|
||||
+3
-3
@@ -46,7 +46,7 @@ public class LogoutPageGeneratingWebFilter implements WebFilter {
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
return this.matcher.matches(exchange).filter(ServerWebExchangeMatcher.MatchResult::isMatch)
|
||||
.switchIfEmpty(chain.filter(exchange).then(Mono.empty())).flatMap(matchResult -> render(exchange));
|
||||
.switchIfEmpty(chain.filter(exchange).then(Mono.empty())).flatMap((matchResult) -> render(exchange));
|
||||
}
|
||||
|
||||
private Mono<Void> render(ServerWebExchange exchange) {
|
||||
@@ -54,12 +54,12 @@ public class LogoutPageGeneratingWebFilter implements WebFilter {
|
||||
result.setStatusCode(HttpStatus.OK);
|
||||
result.getHeaders().setContentType(MediaType.TEXT_HTML);
|
||||
return result.writeWith(createBuffer(exchange));
|
||||
// .doOnError( error -> DataBufferUtils.release(buffer));
|
||||
// .doOnError( (error) -> DataBufferUtils.release(buffer));
|
||||
}
|
||||
|
||||
private Mono<DataBuffer> createBuffer(ServerWebExchange exchange) {
|
||||
Mono<CsrfToken> token = exchange.getAttributeOrDefault(CsrfToken.class.getName(), Mono.empty());
|
||||
return token.map(LogoutPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map(csrfTokenHtmlInput -> {
|
||||
return token.map(LogoutPageGeneratingWebFilter::csrfToken).defaultIfEmpty("").map((csrfTokenHtmlInput) -> {
|
||||
byte[] bytes = createPage(csrfTokenHtmlInput);
|
||||
DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
|
||||
return bufferFactory.wrap(bytes);
|
||||
|
||||
+5
-5
@@ -56,14 +56,14 @@ public class AndServerWebExchangeMatcher implements ServerWebExchangeMatcher {
|
||||
public Mono<MatchResult> matches(ServerWebExchange exchange) {
|
||||
return Mono.defer(() -> {
|
||||
Map<String, Object> variables = new HashMap<>();
|
||||
return Flux.fromIterable(this.matchers).doOnNext(it -> {
|
||||
return Flux.fromIterable(this.matchers).doOnNext((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Trying to match using " + it);
|
||||
}
|
||||
}).flatMap(matcher -> matcher.matches(exchange))
|
||||
.doOnNext(matchResult -> variables.putAll(matchResult.getVariables())).all(MatchResult::isMatch)
|
||||
.flatMap(allMatch -> allMatch ? MatchResult.match(variables) : MatchResult.notMatch())
|
||||
.doOnNext(it -> {
|
||||
}).flatMap((matcher) -> matcher.matches(exchange))
|
||||
.doOnNext((matchResult) -> variables.putAll(matchResult.getVariables())).all(MatchResult::isMatch)
|
||||
.flatMap((allMatch) -> allMatch ? MatchResult.match(variables) : MatchResult.notMatch())
|
||||
.doOnNext((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(it.isMatch() ? "All requestMatchers returned true" : "Did not match");
|
||||
}
|
||||
|
||||
+2
-2
@@ -44,8 +44,8 @@ public class NegatedServerWebExchangeMatcher implements ServerWebExchangeMatcher
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(ServerWebExchange exchange) {
|
||||
return this.matcher.matches(exchange).flatMap(m -> m.isMatch() ? MatchResult.notMatch() : MatchResult.match())
|
||||
.doOnNext(it -> {
|
||||
return this.matcher.matches(exchange).flatMap((m) -> m.isMatch() ? MatchResult.notMatch() : MatchResult.match())
|
||||
.doOnNext((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("matches = " + it.isMatch());
|
||||
}
|
||||
|
||||
+3
-3
@@ -52,12 +52,12 @@ public class OrServerWebExchangeMatcher implements ServerWebExchangeMatcher {
|
||||
|
||||
@Override
|
||||
public Mono<MatchResult> matches(ServerWebExchange exchange) {
|
||||
return Flux.fromIterable(this.matchers).doOnNext(it -> {
|
||||
return Flux.fromIterable(this.matchers).doOnNext((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Trying to match using " + it);
|
||||
}
|
||||
}).flatMap(m -> m.matches(exchange)).filter(MatchResult::isMatch).next().switchIfEmpty(MatchResult.notMatch())
|
||||
.doOnNext(it -> {
|
||||
}).flatMap((m) -> m.matches(exchange)).filter(MatchResult::isMatch).next().switchIfEmpty(MatchResult.notMatch())
|
||||
.doOnNext((it) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(it.isMatch() ? "matched" : "No matches found");
|
||||
}
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ public final class PathPatternParserServerWebExchangeMatcher implements ServerWe
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
PathContainer path = request.getPath().pathWithinApplication();
|
||||
if (this.method != null && !this.method.equals(request.getMethod())) {
|
||||
return MatchResult.notMatch().doOnNext(result -> {
|
||||
return MatchResult.notMatch().doOnNext((result) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Request '" + request.getMethod() + " " + path + "' doesn't match '" + this.method
|
||||
+ " " + this.pattern.getPatternString() + "'");
|
||||
@@ -82,7 +82,7 @@ public final class PathPatternParserServerWebExchangeMatcher implements ServerWe
|
||||
}
|
||||
boolean match = this.pattern.matches(path);
|
||||
if (!match) {
|
||||
return MatchResult.notMatch().doOnNext(result -> {
|
||||
return MatchResult.notMatch().doOnNext((result) -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Request '" + request.getMethod() + " " + path + "' doesn't match '" + this.method
|
||||
+ " " + this.pattern.getPatternString() + "'");
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ public class ConcurrentSessionFilter extends GenericFilterBean {
|
||||
() -> expiredUrl + " isn't a valid redirect URL");
|
||||
this.expiredUrl = expiredUrl;
|
||||
this.sessionRegistry = sessionRegistry;
|
||||
this.sessionInformationExpiredStrategy = event -> {
|
||||
this.sessionInformationExpiredStrategy = (event) -> {
|
||||
HttpServletRequest request = event.getRequest();
|
||||
HttpServletResponse response = event.getResponse();
|
||||
SessionInformation info = event.getSessionInformation();
|
||||
|
||||
@@ -41,14 +41,14 @@ public class ThrowableAnalyzer {
|
||||
*
|
||||
* @see Throwable#getCause()
|
||||
*/
|
||||
public static final ThrowableCauseExtractor DEFAULT_EXTRACTOR = throwable -> throwable.getCause();
|
||||
public static final ThrowableCauseExtractor DEFAULT_EXTRACTOR = (throwable) -> throwable.getCause();
|
||||
|
||||
/**
|
||||
* Default extractor for {@link InvocationTargetException} instances.
|
||||
*
|
||||
* @see InvocationTargetException#getTargetException()
|
||||
*/
|
||||
public static final ThrowableCauseExtractor INVOCATIONTARGET_EXTRACTOR = throwable -> {
|
||||
public static final ThrowableCauseExtractor INVOCATIONTARGET_EXTRACTOR = (throwable) -> {
|
||||
verifyThrowableHierarchy(throwable, InvocationTargetException.class);
|
||||
return ((InvocationTargetException) throwable).getTargetException();
|
||||
};
|
||||
|
||||
@@ -74,7 +74,7 @@ public class FilterChainProxyTests {
|
||||
public void setup() throws Exception {
|
||||
this.matcher = mock(RequestMatcher.class);
|
||||
this.filter = mock(Filter.class);
|
||||
willAnswer((Answer<Object>) inv -> {
|
||||
willAnswer((Answer<Object>) (inv) -> {
|
||||
Object[] args = inv.getArguments();
|
||||
FilterChain fc = (FilterChain) args[2];
|
||||
HttpServletRequestWrapper extraWrapper = new HttpServletRequestWrapper((HttpServletRequest) args[0]);
|
||||
@@ -191,7 +191,7 @@ public class FilterChainProxyTests {
|
||||
@Test
|
||||
public void doFilterClearsSecurityContextHolder() throws Exception {
|
||||
given(this.matcher.matches(any(HttpServletRequest.class))).willReturn(true);
|
||||
willAnswer((Answer<Object>) inv -> {
|
||||
willAnswer((Answer<Object>) (inv) -> {
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new TestingAuthenticationToken("username", "password"));
|
||||
return null;
|
||||
@@ -206,7 +206,7 @@ public class FilterChainProxyTests {
|
||||
@Test
|
||||
public void doFilterClearsSecurityContextHolderWithException() throws Exception {
|
||||
given(this.matcher.matches(any(HttpServletRequest.class))).willReturn(true);
|
||||
willAnswer((Answer<Object>) inv -> {
|
||||
willAnswer((Answer<Object>) (inv) -> {
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new TestingAuthenticationToken("username", "password"));
|
||||
throw new ServletException("oops");
|
||||
@@ -228,10 +228,10 @@ public class FilterChainProxyTests {
|
||||
public void doFilterClearsSecurityContextHolderOnceOnForwards() throws Exception {
|
||||
final FilterChain innerChain = mock(FilterChain.class);
|
||||
given(this.matcher.matches(any(HttpServletRequest.class))).willReturn(true);
|
||||
willAnswer((Answer<Object>) inv -> {
|
||||
willAnswer((Answer<Object>) (inv) -> {
|
||||
TestingAuthenticationToken expected = new TestingAuthenticationToken("username", "password");
|
||||
SecurityContextHolder.getContext().setAuthentication(expected);
|
||||
willAnswer((Answer<Object>) inv1 -> {
|
||||
willAnswer((Answer<Object>) (inv1) -> {
|
||||
innerChain.doFilter(this.request, this.response);
|
||||
return null;
|
||||
}).given(this.filter).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class),
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class WebExpressionVoterTests {
|
||||
Expression ex = mock(Expression.class);
|
||||
EvaluationContextPostProcessor postProcessor = mock(EvaluationContextPostProcessor.class);
|
||||
given(postProcessor.postProcess(any(EvaluationContext.class), any(FilterInvocation.class)))
|
||||
.willAnswer(invocation -> invocation.getArgument(0));
|
||||
.willAnswer((invocation) -> invocation.getArgument(0));
|
||||
WebExpressionConfigAttribute weca = new WebExpressionConfigAttribute(ex, postProcessor);
|
||||
EvaluationContext ctx = mock(EvaluationContext.class);
|
||||
SecurityExpressionHandler eh = mock(SecurityExpressionHandler.class);
|
||||
|
||||
+1
-1
@@ -153,7 +153,7 @@ public class UsernamePasswordAuthenticationFilterTests {
|
||||
private AuthenticationManager createAuthenticationManager() {
|
||||
AuthenticationManager am = mock(AuthenticationManager.class);
|
||||
given(am.authenticate(any(Authentication.class)))
|
||||
.willAnswer((Answer<Authentication>) invocation -> (Authentication) invocation.getArguments()[0]);
|
||||
.willAnswer((Answer<Authentication>) (invocation) -> (Authentication) invocation.getArguments()[0]);
|
||||
|
||||
return am;
|
||||
}
|
||||
|
||||
+1
-1
@@ -423,7 +423,7 @@ public class AbstractPreAuthenticatedProcessingFilterTests {
|
||||
}
|
||||
else {
|
||||
given(am.authenticate(any(Authentication.class)))
|
||||
.willAnswer((Answer<Authentication>) invocation -> (Authentication) invocation.getArguments()[0]);
|
||||
.willAnswer((Answer<Authentication>) (invocation) -> (Authentication) invocation.getArguments()[0]);
|
||||
}
|
||||
|
||||
filter.setAuthenticationManager(am);
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ public class PreAuthenticatedAuthenticationProviderTests {
|
||||
|
||||
private AuthenticationUserDetailsService<PreAuthenticatedAuthenticationToken> getPreAuthenticatedUserDetailsService(
|
||||
final UserDetails aUserDetails) {
|
||||
return token -> {
|
||||
return (token) -> {
|
||||
if (aUserDetails != null && aUserDetails.getUsername().equals(token.getName())) {
|
||||
return aUserDetails;
|
||||
}
|
||||
|
||||
+1
-1
@@ -151,7 +151,7 @@ public class RequestAttributeAuthenticationFilterTests {
|
||||
private AuthenticationManager createAuthenticationManager() {
|
||||
AuthenticationManager am = mock(AuthenticationManager.class);
|
||||
given(am.authenticate(any(Authentication.class)))
|
||||
.willAnswer((Answer<Authentication>) invocation -> (Authentication) invocation.getArguments()[0]);
|
||||
.willAnswer((Answer<Authentication>) (invocation) -> (Authentication) invocation.getArguments()[0]);
|
||||
|
||||
return am;
|
||||
}
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ public class RequestHeaderAuthenticationFilterTests {
|
||||
private AuthenticationManager createAuthenticationManager() {
|
||||
AuthenticationManager am = mock(AuthenticationManager.class);
|
||||
given(am.authenticate(any(Authentication.class)))
|
||||
.willAnswer((Answer<Authentication>) invocation -> (Authentication) invocation.getArguments()[0]);
|
||||
.willAnswer((Answer<Authentication>) (invocation) -> (Authentication) invocation.getArguments()[0]);
|
||||
|
||||
return am;
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class WebSpherePreAuthenticatedProcessingFilterTests {
|
||||
|
||||
AuthenticationManager am = mock(AuthenticationManager.class);
|
||||
given(am.authenticate(any(Authentication.class)))
|
||||
.willAnswer((Answer<Authentication>) invocation -> (Authentication) invocation.getArguments()[0]);
|
||||
.willAnswer((Answer<Authentication>) (invocation) -> (Authentication) invocation.getArguments()[0]);
|
||||
|
||||
filter.setAuthenticationManager(am);
|
||||
WebSpherePreAuthenticatedWebAuthenticationDetailsSource ads = new WebSpherePreAuthenticatedWebAuthenticationDetailsSource(
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class DefaultLogoutPageGeneratingFilterTests {
|
||||
|
||||
@Test
|
||||
public void doFilterWhenHiddenInputsSetThenHiddenInputsRendered() throws Exception {
|
||||
this.filter.setResolveHiddenInputs(r -> Collections.singletonMap("_csrf", "csrf-token-1"));
|
||||
this.filter.setResolveHiddenInputs((r) -> Collections.singletonMap("_csrf", "csrf-token-1"));
|
||||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new Object()).addFilters(this.filter).build();
|
||||
|
||||
mockMvc.perform(get("/logout")).andExpect(
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ public class DigestAuthenticationFilterTests {
|
||||
SecurityContextHolder.clearContext();
|
||||
|
||||
// Create User Details Service
|
||||
UserDetailsService uds = username -> new User("rod,ok", "koala",
|
||||
UserDetailsService uds = (username) -> new User("rod,ok", "koala",
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
|
||||
|
||||
DigestAuthenticationEntryPoint ep = new DigestAuthenticationEntryPoint();
|
||||
|
||||
+6
-6
@@ -581,7 +581,7 @@ public class StrictHttpFirewallTests {
|
||||
@Test
|
||||
public void getFirewalledRequestWhenTrustedDomainThenNoException() {
|
||||
this.request.addHeader("Host", "example.org");
|
||||
this.firewall.setAllowedHostnames(hostname -> hostname.equals("example.org"));
|
||||
this.firewall.setAllowedHostnames((hostname) -> hostname.equals("example.org"));
|
||||
|
||||
assertThatCode(() -> this.firewall.getFirewalledRequest(this.request)).doesNotThrowAnyException();
|
||||
}
|
||||
@@ -589,14 +589,14 @@ public class StrictHttpFirewallTests {
|
||||
@Test(expected = RequestRejectedException.class)
|
||||
public void getFirewalledRequestWhenUntrustedDomainThenException() {
|
||||
this.request.addHeader("Host", "example.org");
|
||||
this.firewall.setAllowedHostnames(hostname -> hostname.equals("myexample.org"));
|
||||
this.firewall.setAllowedHostnames((hostname) -> hostname.equals("myexample.org"));
|
||||
|
||||
this.firewall.getFirewalledRequest(this.request);
|
||||
}
|
||||
|
||||
@Test(expected = RequestRejectedException.class)
|
||||
public void getFirewalledRequestGetHeaderWhenNotAllowedHeaderNameThenException() {
|
||||
this.firewall.setAllowedHeaderNames(name -> !name.equals("bad name"));
|
||||
this.firewall.setAllowedHeaderNames((name) -> !name.equals("bad name"));
|
||||
|
||||
HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
|
||||
request.getHeader("bad name");
|
||||
@@ -605,7 +605,7 @@ public class StrictHttpFirewallTests {
|
||||
@Test(expected = RequestRejectedException.class)
|
||||
public void getFirewalledRequestGetHeaderWhenNotAllowedHeaderValueThenException() {
|
||||
this.request.addHeader("good name", "bad value");
|
||||
this.firewall.setAllowedHeaderValues(value -> !value.equals("bad value"));
|
||||
this.firewall.setAllowedHeaderValues((value) -> !value.equals("bad value"));
|
||||
|
||||
HttpServletRequest request = this.firewall.getFirewalledRequest(this.request);
|
||||
request.getHeader("good name");
|
||||
@@ -717,7 +717,7 @@ public class StrictHttpFirewallTests {
|
||||
|
||||
@Test(expected = RequestRejectedException.class)
|
||||
public void getFirewalledRequestGetParameterValuesWhenNotAllowedInParameterValueThenException() {
|
||||
this.firewall.setAllowedParameterValues(value -> !value.equals("bad value"));
|
||||
this.firewall.setAllowedParameterValues((value) -> !value.equals("bad value"));
|
||||
|
||||
this.request.addParameter("Something", "bad value");
|
||||
|
||||
@@ -727,7 +727,7 @@ public class StrictHttpFirewallTests {
|
||||
|
||||
@Test(expected = RequestRejectedException.class)
|
||||
public void getFirewalledRequestGetParameterValuesWhenNotAllowedInParameterNameThenException() {
|
||||
this.firewall.setAllowedParameterNames(value -> !value.equals("bad name"));
|
||||
this.firewall.setAllowedParameterNames((value) -> !value.equals("bad name"));
|
||||
|
||||
this.request.addParameter("bad name", "good value");
|
||||
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public class JaasApiIntegrationFilterTests {
|
||||
this.authenticatedSubject.getPrincipals().add(() -> "principal");
|
||||
this.authenticatedSubject.getPrivateCredentials().add("password");
|
||||
this.authenticatedSubject.getPublicCredentials().add("username");
|
||||
this.callbackHandler = callbacks -> {
|
||||
this.callbackHandler = (callbacks) -> {
|
||||
for (Callback callback : callbacks) {
|
||||
if (callback instanceof NameCallback) {
|
||||
((NameCallback) callback).setName("user");
|
||||
|
||||
@@ -119,7 +119,7 @@ import org.springframework.web.bind.annotation.ValueConstants;
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* ResolvableMethod.on(TestController.class).mockCall(o -> o.handle(null)).method();
|
||||
* ResolvableMethod.on(TestController.class).mockCall((o) -> o.handle(null)).method();
|
||||
* </pre>
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -318,7 +318,7 @@ public final class ResolvableMethod {
|
||||
* Filter on methods with the given name.
|
||||
*/
|
||||
public Builder<T> named(String methodName) {
|
||||
addFilter("methodName=" + methodName, m -> m.getName().equals(methodName));
|
||||
addFilter("methodName=" + methodName, (m) -> m.getName().equals(methodName));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -339,8 +339,8 @@ public final class ResolvableMethod {
|
||||
@SafeVarargs
|
||||
public final Builder<T> annotPresent(Class<? extends Annotation>... annotationTypes) {
|
||||
String message = "annotationPresent=" + Arrays.toString(annotationTypes);
|
||||
addFilter(message, candidate -> Arrays.stream(annotationTypes)
|
||||
.allMatch(annotType -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null));
|
||||
addFilter(message, (candidate) -> Arrays.stream(annotationTypes)
|
||||
.allMatch((annotType) -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -350,10 +350,10 @@ public final class ResolvableMethod {
|
||||
@SafeVarargs
|
||||
public final Builder<T> annotNotPresent(Class<? extends Annotation>... annotationTypes) {
|
||||
String message = "annotationNotPresent=" + Arrays.toString(annotationTypes);
|
||||
addFilter(message, candidate -> {
|
||||
addFilter(message, (candidate) -> {
|
||||
if (annotationTypes.length != 0) {
|
||||
return Arrays.stream(annotationTypes).noneMatch(
|
||||
annotType -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null);
|
||||
(annotType) -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null);
|
||||
}
|
||||
else {
|
||||
return candidate.getAnnotations().length == 0;
|
||||
@@ -388,7 +388,7 @@ public final class ResolvableMethod {
|
||||
public Builder<T> returning(ResolvableType returnType) {
|
||||
String expected = returnType.toString();
|
||||
String message = "returnType=" + expected;
|
||||
addFilter(message, m -> expected.equals(ResolvableType.forMethodReturnType(m).toString()));
|
||||
addFilter(message, (m) -> expected.equals(ResolvableType.forMethodReturnType(m).toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ public final class ResolvableMethod {
|
||||
}
|
||||
|
||||
private boolean isMatch(Method method) {
|
||||
return this.filters.stream().allMatch(p -> p.test(method));
|
||||
return this.filters.stream().allMatch((p) -> p.test(method));
|
||||
}
|
||||
|
||||
private String formatMethods(Set<Method> methods) {
|
||||
@@ -567,7 +567,7 @@ public final class ResolvableMethod {
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final ArgResolver annotPresent(Class<? extends Annotation>... annotationTypes) {
|
||||
this.filters.add(param -> Arrays.stream(annotationTypes).allMatch(param::hasParameterAnnotation));
|
||||
this.filters.add((param) -> Arrays.stream(annotationTypes).allMatch(param::hasParameterAnnotation));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -577,7 +577,7 @@ public final class ResolvableMethod {
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final ArgResolver annotNotPresent(Class<? extends Annotation>... annotationTypes) {
|
||||
this.filters.add(param -> (annotationTypes.length != 0)
|
||||
this.filters.add((param) -> (annotationTypes.length != 0)
|
||||
? Arrays.stream(annotationTypes).noneMatch(param::hasParameterAnnotation)
|
||||
: param.getParameterAnnotations().length == 0);
|
||||
return this;
|
||||
@@ -604,7 +604,7 @@ public final class ResolvableMethod {
|
||||
* @param type the expected type
|
||||
*/
|
||||
public MethodParameter arg(ResolvableType type) {
|
||||
this.filters.add(p -> type.toString().equals(ResolvableType.forMethodParameter(p).toString()));
|
||||
this.filters.add((p) -> type.toString().equals(ResolvableType.forMethodParameter(p).toString()));
|
||||
return arg();
|
||||
}
|
||||
|
||||
@@ -624,7 +624,7 @@ public final class ResolvableMethod {
|
||||
for (int i = 0; i < ResolvableMethod.this.method.getParameterCount(); i++) {
|
||||
MethodParameter param = new SynthesizingMethodParameter(ResolvableMethod.this.method, i);
|
||||
param.initParameterNameDiscovery(nameDiscoverer);
|
||||
if (this.filters.stream().allMatch(p -> p.test(param))) {
|
||||
if (this.filters.stream().allMatch((p) -> p.test(param))) {
|
||||
matches.add(param);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class CookieRequestCacheTests {
|
||||
@Test
|
||||
public void getMatchingRequestWhenRequestMatcherDefinedThenReturnsCorrectSubsetOfCachedRequests() {
|
||||
CookieRequestCache cookieRequestCache = new CookieRequestCache();
|
||||
cookieRequestCache.setRequestMatcher(request -> request.getRequestURI().equals("/expected-destination"));
|
||||
cookieRequestCache.setRequestMatcher((request) -> request.getRequestURI().equals("/expected-destination"));
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/destination");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class HttpSessionRequestCacheTests {
|
||||
@Test
|
||||
public void requestMatcherDefinesCorrectSubsetOfCachedRequests() {
|
||||
HttpSessionRequestCache cache = new HttpSessionRequestCache();
|
||||
cache.setRequestMatcher(request -> request.getMethod().equals("GET"));
|
||||
cache.setRequestMatcher((request) -> request.getMethod().equals("GET"));
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/destination");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class WebFilterChainProxyTests {
|
||||
@Test
|
||||
public void filterWhenNoMatchThenContinuesChainAnd404() {
|
||||
List<WebFilter> filters = Arrays.asList(new Http200WebFilter());
|
||||
ServerWebExchangeMatcher notMatch = exchange -> MatchResult.notMatch();
|
||||
ServerWebExchangeMatcher notMatch = (exchange) -> MatchResult.notMatch();
|
||||
MatcherSecurityWebFilterChain chain = new MatcherSecurityWebFilterChain(notMatch, filters);
|
||||
WebFilterChainProxy filter = new WebFilterChainProxy(chain);
|
||||
|
||||
|
||||
+13
-13
@@ -87,7 +87,7 @@ public class AuthenticationWebFilterTests {
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
EntityExchangeResult<String> result = client.get().uri("/").exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith(b -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.expectBody(String.class).consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.returnResult();
|
||||
|
||||
verifyZeroInteractions(this.authenticationManager);
|
||||
@@ -101,7 +101,7 @@ public class AuthenticationWebFilterTests {
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
EntityExchangeResult<String> result = client.get().uri("/").exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith(b -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.expectBody(String.class).consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.returnResult();
|
||||
|
||||
verifyZeroInteractions(this.authenticationManagerResolver);
|
||||
@@ -117,8 +117,8 @@ public class AuthenticationWebFilterTests {
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
EntityExchangeResult<String> result = client.get().uri("/")
|
||||
.headers(headers -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith(b -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.headers((headers) -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.returnResult();
|
||||
|
||||
assertThat(result.getResponseCookies()).isEmpty();
|
||||
@@ -135,8 +135,8 @@ public class AuthenticationWebFilterTests {
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
EntityExchangeResult<String> result = client.get().uri("/")
|
||||
.headers(headers -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith(b -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.headers((headers) -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.returnResult();
|
||||
|
||||
assertThat(result.getResponseCookies()).isEmpty();
|
||||
@@ -151,7 +151,7 @@ public class AuthenticationWebFilterTests {
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
EntityExchangeResult<Void> result = client.get().uri("/")
|
||||
.headers(headers -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isUnauthorized()
|
||||
.headers((headers) -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isUnauthorized()
|
||||
.expectHeader().valueMatches("WWW-Authenticate", "Basic realm=\"Realm\"").expectBody().isEmpty();
|
||||
|
||||
assertThat(result.getResponseCookies()).isEmpty();
|
||||
@@ -168,7 +168,7 @@ public class AuthenticationWebFilterTests {
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
EntityExchangeResult<Void> result = client.get().uri("/")
|
||||
.headers(headers -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isUnauthorized()
|
||||
.headers((headers) -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isUnauthorized()
|
||||
.expectHeader().valueMatches("WWW-Authenticate", "Basic realm=\"Realm\"").expectBody().isEmpty();
|
||||
|
||||
assertThat(result.getResponseCookies()).isEmpty();
|
||||
@@ -181,7 +181,7 @@ public class AuthenticationWebFilterTests {
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
client.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class)
|
||||
.consumeWith(b -> assertThat(b.getResponseBody()).isEqualTo("ok")).returnResult();
|
||||
.consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok")).returnResult();
|
||||
|
||||
verify(this.securityContextRepository, never()).save(any(), any());
|
||||
verifyZeroInteractions(this.authenticationManager, this.successHandler, this.failureHandler);
|
||||
@@ -205,7 +205,7 @@ public class AuthenticationWebFilterTests {
|
||||
given(this.authenticationConverter.convert(any())).willReturn(authentication);
|
||||
given(this.authenticationManager.authenticate(any())).willReturn(authentication);
|
||||
given(this.successHandler.onAuthenticationSuccess(any(), any())).willReturn(Mono.empty());
|
||||
given(this.securityContextRepository.save(any(), any())).willAnswer(a -> Mono.just(a.getArguments()[0]));
|
||||
given(this.securityContextRepository.save(any(), any())).willAnswer((a) -> Mono.just(a.getArguments()[0]));
|
||||
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
@@ -232,13 +232,13 @@ public class AuthenticationWebFilterTests {
|
||||
|
||||
@Test
|
||||
public void filterWhenNotMatchAndConvertAndAuthenticationSuccessThenContinues() {
|
||||
this.filter.setRequiresAuthenticationMatcher(e -> ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
this.filter.setRequiresAuthenticationMatcher((e) -> ServerWebExchangeMatcher.MatchResult.notMatch());
|
||||
|
||||
WebTestClient client = WebTestClientBuilder.bindToWebFilters(this.filter).build();
|
||||
|
||||
EntityExchangeResult<String> result = client.get().uri("/")
|
||||
.headers(headers -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith(b -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.headers((headers) -> headers.setBasicAuth("test", "this")).exchange().expectStatus().isOk()
|
||||
.expectBody(String.class).consumeWith((b) -> assertThat(b.getResponseBody()).isEqualTo("ok"))
|
||||
.returnResult();
|
||||
|
||||
assertThat(result.getResponseCookies()).isEmpty();
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class DelegatingServerAuthenticationSuccessHandlerTests {
|
||||
AtomicBoolean slowDone = new AtomicBoolean();
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ServerAuthenticationSuccessHandler slow = (exchange, authentication) -> Mono.delay(Duration.ofMillis(100))
|
||||
.doOnSuccess(__ -> slowDone.set(true)).then();
|
||||
.doOnSuccess((__) -> slowDone.set(true)).then();
|
||||
ServerAuthenticationSuccessHandler second = (exchange, authentication) -> Mono.fromRunnable(() -> {
|
||||
latch.countDown();
|
||||
assertThat(slowDone.get()).describedAs("ServerAuthenticationSuccessHandler should be executed sequentially")
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ public class RedirectServerAuthenticationFailureHandlerTests {
|
||||
|
||||
private WebFilterExchange createExchange() {
|
||||
return new WebFilterExchange(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()),
|
||||
new DefaultWebFilterChain(e -> Mono.empty()));
|
||||
new DefaultWebFilterChain((e) -> Mono.empty()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -149,10 +149,10 @@ public class SwitchUserWebFilterTests {
|
||||
assertThat(switchUserAuthentication.getAuthorities()).anyMatch(SwitchUserGrantedAuthority.class::isInstance);
|
||||
assertThat(switchUserAuthentication.getAuthorities())
|
||||
.anyMatch((a) -> a.getAuthority().contains(SwitchUserWebFilter.ROLE_PREVIOUS_ADMINISTRATOR));
|
||||
assertThat(
|
||||
switchUserAuthentication.getAuthorities().stream().filter(a -> a instanceof SwitchUserGrantedAuthority)
|
||||
.map(a -> ((SwitchUserGrantedAuthority) a).getSource()).map(Principal::getName))
|
||||
.contains(originalAuthentication.getName());
|
||||
assertThat(switchUserAuthentication.getAuthorities().stream()
|
||||
.filter((a) -> a instanceof SwitchUserGrantedAuthority)
|
||||
.map((a) -> ((SwitchUserGrantedAuthority) a).getSource()).map(Principal::getName))
|
||||
.contains(originalAuthentication.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,8 +192,8 @@ public class SwitchUserWebFilterTests {
|
||||
|
||||
assertThat(secondSwitchUserAuthentication.getName()).isEqualTo(targetUsername);
|
||||
assertThat(secondSwitchUserAuthentication.getAuthorities().stream()
|
||||
.filter(a -> a instanceof SwitchUserGrantedAuthority)
|
||||
.map(a -> ((SwitchUserGrantedAuthority) a).getSource()).map(Principal::getName).findFirst()
|
||||
.filter((a) -> a instanceof SwitchUserGrantedAuthority)
|
||||
.map((a) -> ((SwitchUserGrantedAuthority) a).getSource()).map(Principal::getName).findFirst()
|
||||
.orElse(null)).isEqualTo(originalAuthentication.getName());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class DelegatingServerLogoutHandlerTests {
|
||||
AtomicBoolean slowDone = new AtomicBoolean();
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ServerLogoutHandler slow = (exchange, authentication) -> Mono.delay(Duration.ofMillis(100))
|
||||
.doOnSuccess(__ -> slowDone.set(true)).then();
|
||||
.doOnSuccess((__) -> slowDone.set(true)).then();
|
||||
ServerLogoutHandler second = (exchange, authentication) -> Mono.fromRunnable(() -> {
|
||||
latch.countDown();
|
||||
assertThat(slowDone.get()).describedAs("ServerLogoutHandler should be executed sequentially").isTrue();
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class LogoutWebFilterTests {
|
||||
.setLogoutHandler(new DelegatingServerLogoutHandler(this.handler1, this.handler2, this.handler3));
|
||||
|
||||
assertThat(getLogoutHandler()).isNotNull().isExactlyInstanceOf(DelegatingServerLogoutHandler.class)
|
||||
.extracting(delegatingLogoutHandler -> ((Collection<ServerLogoutHandler>) ReflectionTestUtils
|
||||
.extracting((delegatingLogoutHandler) -> ((Collection<ServerLogoutHandler>) ReflectionTestUtils
|
||||
.getField(delegatingLogoutHandler, DelegatingServerLogoutHandler.class, "delegates")).stream()
|
||||
.map(ServerLogoutHandler::getClass).collect(Collectors.toList()))
|
||||
.isEqualTo(Arrays.asList(this.handler1.getClass(), this.handler2.getClass(), this.handler3.getClass()));
|
||||
|
||||
+2
-2
@@ -66,7 +66,7 @@ public class AuthorizationWebFilterTests {
|
||||
public void filterWhenNoAuthenticationThenThrowsAccessDenied() {
|
||||
given(this.chain.filter(this.exchange)).willReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter(
|
||||
(a, e) -> a.flatMap(auth -> Mono.error(new AccessDeniedException("Denied"))));
|
||||
(a, e) -> a.flatMap((auth) -> Mono.error(new AccessDeniedException("Denied"))));
|
||||
|
||||
Mono<Void> result = filter.filter(this.exchange, this.chain).subscriberContext(
|
||||
ReactiveSecurityContextHolder.withSecurityContext(Mono.just(new SecurityContextImpl())));
|
||||
@@ -123,7 +123,7 @@ public class AuthorizationWebFilterTests {
|
||||
PublisherProbe<SecurityContext> context = PublisherProbe.empty();
|
||||
given(this.chain.filter(this.exchange)).willReturn(this.chainResult.mono());
|
||||
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> a
|
||||
.map(auth -> new AuthorizationDecision(true)).defaultIfEmpty(new AuthorizationDecision(true)));
|
||||
.map((auth) -> new AuthorizationDecision(true)).defaultIfEmpty(new AuthorizationDecision(true)));
|
||||
|
||||
Mono<Void> result = filter.filter(this.exchange, this.chain)
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(context.mono()));
|
||||
|
||||
+2
-2
@@ -100,7 +100,7 @@ public class ReactorContextWebFilterTests {
|
||||
given(this.repository.load(any())).willReturn(Mono.just(context));
|
||||
this.handler = WebTestHandler.bindToWebFilters(this.filter,
|
||||
(e, c) -> ReactiveSecurityContextHolder.getContext().map(SecurityContext::getAuthentication)
|
||||
.doOnSuccess(p -> assertThat(p).isSameAs(this.principal)).flatMap(p -> c.filter(e)));
|
||||
.doOnSuccess((p) -> assertThat(p).isSameAs(this.principal)).flatMap((p) -> c.filter(e)));
|
||||
|
||||
WebTestHandler.WebHandlerResult result = this.handler.exchange(this.exchange);
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ReactorContextWebFilterTests {
|
||||
String contextKey = "main";
|
||||
WebFilter mainContextWebFilter = (e, c) -> c.filter(e).subscriberContext(Context.of(contextKey, true));
|
||||
|
||||
WebFilterChain chain = new DefaultWebFilterChain(e -> Mono.empty(), mainContextWebFilter, this.filter);
|
||||
WebFilterChain chain = new DefaultWebFilterChain((e) -> Mono.empty(), mainContextWebFilter, this.filter);
|
||||
Mono<Void> filter = chain.filter(MockServerWebExchange.from(this.exchange.build()));
|
||||
StepVerifier.create(filter).expectAccessibleContext().hasKey(contextKey).then().verifyComplete();
|
||||
}
|
||||
|
||||
+11
-9
@@ -45,11 +45,11 @@ public class SecurityContextServerWebExchangeWebFilterTests {
|
||||
@Test
|
||||
public void filterWhenExistingContextAndPrincipalNotNullThenContextPopulated() {
|
||||
Mono<Void> result = this.filter
|
||||
.filter(this.exchange, new DefaultWebFilterChain(e -> e.getPrincipal()
|
||||
.doOnSuccess(contextPrincipal -> assertThat(contextPrincipal).isEqualTo(this.principal))
|
||||
.flatMap(contextPrincipal -> Mono.subscriberContext())
|
||||
.doOnSuccess(context -> assertThat(context.<String>get("foo")).isEqualTo("bar")).then()))
|
||||
.subscriberContext(context -> context.put("foo", "bar"))
|
||||
.filter(this.exchange, new DefaultWebFilterChain((e) -> e.getPrincipal()
|
||||
.doOnSuccess((contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(this.principal))
|
||||
.flatMap((contextPrincipal) -> Mono.subscriberContext())
|
||||
.doOnSuccess((context) -> assertThat(context.<String>get("foo")).isEqualTo("bar")).then()))
|
||||
.subscriberContext((context) -> context.put("foo", "bar"))
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.principal));
|
||||
|
||||
StepVerifier.create(result).verifyComplete();
|
||||
@@ -59,8 +59,9 @@ public class SecurityContextServerWebExchangeWebFilterTests {
|
||||
public void filterWhenPrincipalNotNullThenContextPopulated() {
|
||||
Mono<Void> result = this.filter
|
||||
.filter(this.exchange,
|
||||
new DefaultWebFilterChain(e -> e.getPrincipal()
|
||||
.doOnSuccess(contextPrincipal -> assertThat(contextPrincipal).isEqualTo(this.principal))
|
||||
new DefaultWebFilterChain((e) -> e.getPrincipal()
|
||||
.doOnSuccess(
|
||||
(contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(this.principal))
|
||||
.then()))
|
||||
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.principal));
|
||||
|
||||
@@ -71,8 +72,9 @@ public class SecurityContextServerWebExchangeWebFilterTests {
|
||||
public void filterWhenPrincipalNullThenContextEmpty() {
|
||||
Authentication defaultAuthentication = new TestingAuthenticationToken("anonymouse", "anonymous", "TEST");
|
||||
Mono<Void> result = this.filter.filter(this.exchange,
|
||||
new DefaultWebFilterChain(e -> e.getPrincipal().defaultIfEmpty(defaultAuthentication)
|
||||
.doOnSuccess(contextPrincipal -> assertThat(contextPrincipal).isEqualTo(defaultAuthentication))
|
||||
new DefaultWebFilterChain((e) -> e.getPrincipal().defaultIfEmpty(defaultAuthentication)
|
||||
.doOnSuccess(
|
||||
(contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(defaultAuthentication))
|
||||
.then()));
|
||||
StepVerifier.create(result).verifyComplete();
|
||||
}
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class WebSessionServerCsrfTokenRepositoryTests {
|
||||
@Test
|
||||
public void saveTokenWhenDefaultThenAddsToSession() {
|
||||
Mono<CsrfToken> result = this.repository.generateToken(this.exchange)
|
||||
.delayUntil(t -> this.repository.saveToken(this.exchange, t));
|
||||
.delayUntil((t) -> this.repository.saveToken(this.exchange, t));
|
||||
result.block();
|
||||
|
||||
WebSession session = this.exchange.getSession().block();
|
||||
|
||||
+3
-3
@@ -99,9 +99,9 @@ public class CompositeServerHttpHeadersWriterTests {
|
||||
public void writeHttpHeadersSequential() throws Exception {
|
||||
AtomicBoolean slowDone = new AtomicBoolean();
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ServerHttpHeadersWriter slow = exchange -> Mono.delay(Duration.ofMillis(100))
|
||||
.doOnSuccess(__ -> slowDone.set(true)).then();
|
||||
ServerHttpHeadersWriter second = exchange -> Mono.fromRunnable(() -> {
|
||||
ServerHttpHeadersWriter slow = (exchange) -> Mono.delay(Duration.ofMillis(100))
|
||||
.doOnSuccess((__) -> slowDone.set(true)).then();
|
||||
ServerHttpHeadersWriter second = (exchange) -> Mono.fromRunnable(() -> {
|
||||
latch.countDown();
|
||||
assertThat(slowDone.get()).describedAs("ServerLogoutHandler should be executed sequentially").isTrue();
|
||||
});
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ public class CookieServerRequestCacheTests {
|
||||
|
||||
@Test
|
||||
public void saveRequestWhenPostRequestAndCustomMatcherThenRequestUriInCookie() {
|
||||
this.cache.setSaveRequestMatcher(e -> ServerWebExchangeMatcher.MatchResult.match());
|
||||
this.cache.setSaveRequestMatcher((e) -> ServerWebExchangeMatcher.MatchResult.match());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/"));
|
||||
this.cache.saveRequest(exchange).block();
|
||||
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public class WebSessionServerRequestCacheTests {
|
||||
|
||||
@Test
|
||||
public void saveRequestGetRequestWhenPostAndCustomMatcherThenFound() {
|
||||
this.cache.setSaveRequestMatcher(e -> ServerWebExchangeMatcher.MatchResult.match());
|
||||
this.cache.setSaveRequestMatcher((e) -> ServerWebExchangeMatcher.MatchResult.match());
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/secured/"));
|
||||
this.cache.saveRequest(exchange).block();
|
||||
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ public class LoginPageGeneratingWebFilterTests {
|
||||
MockServerWebExchange exchange = MockServerWebExchange
|
||||
.from(MockServerHttpRequest.get("/test/login").contextPath("/test"));
|
||||
|
||||
filter.filter(exchange, e -> Mono.empty()).block();
|
||||
filter.filter(exchange, (e) -> Mono.empty()).block();
|
||||
|
||||
assertThat(exchange.getResponse().getBodyAsString().block()).contains("action=\"/test/login\"");
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class LoginPageGeneratingWebFilterTests {
|
||||
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/login"));
|
||||
|
||||
filter.filter(exchange, e -> Mono.empty()).block();
|
||||
filter.filter(exchange, (e) -> Mono.empty()).block();
|
||||
|
||||
assertThat(exchange.getResponse().getBodyAsString().block()).contains("action=\"/login\"");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user