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:
Phillip Webb
2020-07-29 18:18:05 -07:00
committed by Rob Winch
parent 01d90c9881
commit 52f20b5281
426 changed files with 1668 additions and 1617 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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