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

@@ -89,22 +89,22 @@ public final class BearerTokenError extends OAuth2Error {
}
private static boolean isDescriptionValid(String description) {
return description == null || description.chars().allMatch(c -> withinTheRangeOf(c, 0x20, 0x21)
return description == null || description.chars().allMatch((c) -> withinTheRangeOf(c, 0x20, 0x21)
|| withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E));
}
private static boolean isErrorCodeValid(String errorCode) {
return errorCode.chars().allMatch(c -> withinTheRangeOf(c, 0x20, 0x21) || withinTheRangeOf(c, 0x23, 0x5B)
return errorCode.chars().allMatch((c) -> withinTheRangeOf(c, 0x20, 0x21) || withinTheRangeOf(c, 0x23, 0x5B)
|| withinTheRangeOf(c, 0x5D, 0x7E));
}
private static boolean isErrorUriValid(String errorUri) {
return errorUri == null || errorUri.chars()
.allMatch(c -> c == 0x21 || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E));
.allMatch((c) -> c == 0x21 || withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E));
}
private static boolean isScopeValid(String scope) {
return scope == null || scope.chars().allMatch(c -> withinTheRangeOf(c, 0x20, 0x21)
return scope == null || scope.chars().allMatch((c) -> withinTheRangeOf(c, 0x20, 0x21)
|| withinTheRangeOf(c, 0x23, 0x5B) || withinTheRangeOf(c, 0x5D, 0x7E));
}

View File

@@ -162,7 +162,7 @@ public final class JwtIssuerAuthenticationManagerResolver implements Authenticat
@Override
public AuthenticationManager resolve(String issuer) {
if (this.trustedIssuer.test(issuer)) {
return this.authenticationManagers.computeIfAbsent(issuer, k -> {
return this.authenticationManagers.computeIfAbsent(issuer, (k) -> {
JwtDecoder jwtDecoder = JwtDecoders.fromIssuerLocation(issuer);
return new JwtAuthenticationProvider(jwtDecoder)::authenticate;
});

View File

@@ -101,7 +101,7 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
* authenticationManagers.put("https://issuerOne.example.org", managerOne);
* authenticationManagers.put("https://issuerTwo.example.org", managerTwo);
* JwtIssuerReactiveAuthenticationManagerResolver resolver = new JwtIssuerReactiveAuthenticationManagerResolver
* (issuer -> Mono.justOrEmpty(authenticationManagers.get(issuer));
* ((issuer) -> Mono.justOrEmpty(authenticationManagers.get(issuer));
* </pre>
*
* The keys in the {@link Map} are the trusted issuers.
@@ -124,7 +124,7 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
@Override
public Mono<ReactiveAuthenticationManager> resolve(ServerWebExchange exchange) {
return this.issuerConverter.convert(exchange)
.flatMap(issuer -> this.issuerAuthenticationManagerResolver.resolve(issuer)
.flatMap((issuer) -> this.issuerAuthenticationManagerResolver.resolve(issuer)
.switchIfEmpty(Mono.error(() -> new InvalidBearerTokenException("Invalid issuer " + issuer))));
}
@@ -134,7 +134,7 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
@Override
public Mono<String> convert(@NonNull ServerWebExchange exchange) {
return this.converter.convert(exchange).map(convertedToken -> {
return this.converter.convert(exchange).map((convertedToken) -> {
BearerTokenAuthenticationToken token = (BearerTokenAuthenticationToken) convertedToken;
try {
String issuer = JWTParser.parse(token.getToken()).getJWTClaimsSet().getIssuer();
@@ -170,7 +170,7 @@ public final class JwtIssuerReactiveAuthenticationManagerResolver
return Mono.empty();
}
return this.authenticationManagers.computeIfAbsent(issuer,
k -> Mono.<ReactiveAuthenticationManager>fromCallable(
(k) -> Mono.<ReactiveAuthenticationManager>fromCallable(
() -> new JwtReactiveAuthenticationManager(ReactiveJwtDecoders.fromIssuerLocation(k)))
.subscribeOn(Schedulers.boundedElastic()).cache());
}

View File

@@ -52,7 +52,7 @@ public final class JwtReactiveAuthenticationManager implements ReactiveAuthentic
@Override
public Mono<Authentication> authenticate(Authentication authentication) {
return Mono.justOrEmpty(authentication).filter(a -> a instanceof BearerTokenAuthenticationToken)
return Mono.justOrEmpty(authentication).filter((a) -> a instanceof BearerTokenAuthenticationToken)
.cast(BearerTokenAuthenticationToken.class).map(BearerTokenAuthenticationToken::getToken)
.flatMap(this.jwtDecoder::decode).flatMap(this.jwtAuthenticationConverter::convert)
.cast(Authentication.class).onErrorMap(JwtException.class, this::onError);

View File

@@ -81,7 +81,7 @@ public class OpaqueTokenReactiveAuthenticationManager implements ReactiveAuthent
}
private Mono<BearerTokenAuthentication> authenticate(String token) {
return this.introspector.introspect(token).map(principal -> {
return this.introspector.introspect(token).map((principal) -> {
Instant iat = principal.getAttribute(OAuth2IntrospectionClaimNames.ISSUED_AT);
Instant exp = principal.getAttribute(OAuth2IntrospectionClaimNames.EXPIRES_AT);

View File

@@ -40,7 +40,7 @@ public final class ReactiveJwtAuthenticationConverter implements Converter<Jwt,
@Override
public Mono<AbstractAuthenticationToken> convert(Jwt jwt) {
return this.jwtGrantedAuthoritiesConverter.convert(jwt).collectList()
.map(authorities -> new JwtAuthenticationToken(jwt, authorities));
.map((authorities) -> new JwtAuthenticationToken(jwt, authorities));
}
/**

View File

@@ -98,7 +98,7 @@ public class NimbusOpaqueTokenIntrospector implements OpaqueTokenIntrospector {
}
private Converter<String, RequestEntity<?>> defaultRequestEntityConverter(URI introspectionUri) {
return token -> {
return (token) -> {
HttpHeaders headers = requestHeaders();
MultiValueMap<String, String> body = requestBody(token);
return new RequestEntity<>(body, headers, HttpMethod.POST, introspectionUri);

View File

@@ -73,7 +73,7 @@ public class NimbusReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
Assert.notNull(clientSecret, "clientSecret cannot be null");
this.introspectionUri = URI.create(introspectionUri);
this.webClient = WebClient.builder().defaultHeaders(h -> h.setBasicAuth(clientId, clientSecret)).build();
this.webClient = WebClient.builder().defaultHeaders((h) -> h.setBasicAuth(clientId, clientSecret)).build();
}
/**
@@ -97,8 +97,8 @@ public class NimbusReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
public Mono<OAuth2AuthenticatedPrincipal> introspect(String token) {
return Mono.just(token).flatMap(this::makeRequest).flatMap(this::adaptToNimbusResponse)
.map(this::parseNimbusResponse).map(this::castToNimbusSuccess)
.doOnNext(response -> validate(token, response)).map(this::convertClaimsSet)
.onErrorMap(e -> !(e instanceof OAuth2IntrospectionException), this::onError);
.doOnNext((response) -> validate(token, response)).map(this::convertClaimsSet)
.onErrorMap((e) -> !(e instanceof OAuth2IntrospectionException), this::onError);
}
private Mono<ClientResponse> makeRequest(String token) {
@@ -115,7 +115,7 @@ public class NimbusReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
.then(Mono.error(new OAuth2IntrospectionException(
"Introspection endpoint responded with " + response.getStatusCode())));
}
return responseEntity.bodyToMono(String.class).doOnNext(response::setContent).map(body -> response);
return responseEntity.bodyToMono(String.class).doOnNext(response::setContent).map((body) -> response);
}
private TokenIntrospectionResponse parseNimbusResponse(HTTPResponse response) {

View File

@@ -85,7 +85,7 @@ public final class BearerTokenAuthenticationFilter extends OncePerRequestFilter
*/
public BearerTokenAuthenticationFilter(AuthenticationManager authenticationManager) {
Assert.notNull(authenticationManager, "authenticationManager cannot be null");
this.authenticationManagerResolver = request -> authenticationManager;
this.authenticationManagerResolver = (request) -> authenticationManager;
}
/**

View File

@@ -63,8 +63,8 @@ public class BearerTokenServerAccessDeniedHandler implements ServerAccessDeniedH
}
return exchange.getPrincipal().filter(AbstractOAuth2TokenAuthenticationToken.class::isInstance)
.map(token -> errorMessageParameters(parameters)).switchIfEmpty(Mono.just(parameters))
.flatMap(params -> respond(exchange, params));
.map((token) -> errorMessageParameters(parameters)).switchIfEmpty(Mono.just(parameters))
.flatMap((params) -> respond(exchange, params));
}
/**

View File

@@ -56,12 +56,12 @@ public final class ServerBearerExchangeFilterFunction implements ExchangeFilterF
*/
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
return oauth2Token().map(token -> bearer(request, token)).defaultIfEmpty(request).flatMap(next::exchange);
return oauth2Token().map((token) -> bearer(request, token)).defaultIfEmpty(request).flatMap(next::exchange);
}
private Mono<AbstractOAuth2Token> oauth2Token() {
return currentAuthentication()
.filter(authentication -> authentication.getCredentials() instanceof AbstractOAuth2Token)
.filter((authentication) -> authentication.getCredentials() instanceof AbstractOAuth2Token)
.map(Authentication::getCredentials).cast(AbstractOAuth2Token.class);
}
@@ -70,7 +70,7 @@ public final class ServerBearerExchangeFilterFunction implements ExchangeFilterF
}
private ClientRequest bearer(ClientRequest request, AbstractOAuth2Token token) {
return ClientRequest.from(request).headers(headers -> headers.setBearerAuth(token.getTokenValue())).build();
return ClientRequest.from(request).headers((headers) -> headers.setBearerAuth(token.getTokenValue())).build();
}
}

View File

@@ -67,12 +67,12 @@ public final class ServletBearerExchangeFilterFunction implements ExchangeFilter
*/
@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
return oauth2Token().map(token -> bearer(request, token)).defaultIfEmpty(request).flatMap(next::exchange);
return oauth2Token().map((token) -> bearer(request, token)).defaultIfEmpty(request).flatMap(next::exchange);
}
private Mono<AbstractOAuth2Token> oauth2Token() {
return Mono.subscriberContext().flatMap(this::currentAuthentication)
.filter(authentication -> authentication.getCredentials() instanceof AbstractOAuth2Token)
.filter((authentication) -> authentication.getCredentials() instanceof AbstractOAuth2Token)
.map(Authentication::getCredentials).cast(AbstractOAuth2Token.class);
}
@@ -91,7 +91,7 @@ public final class ServletBearerExchangeFilterFunction implements ExchangeFilter
}
private ClientRequest bearer(ClientRequest request, AbstractOAuth2Token token) {
return ClientRequest.from(request).headers(headers -> headers.setBearerAuth(token.getTokenValue())).build();
return ClientRequest.from(request).headers((headers) -> headers.setBearerAuth(token.getTokenValue())).build();
}
}

View File

@@ -54,7 +54,7 @@ public class ServerBearerTokenAuthenticationConverter implements ServerAuthentic
@Override
public Mono<Authentication> convert(ServerWebExchange exchange) {
return Mono.fromCallable(() -> token(exchange.getRequest())).map(token -> {
return Mono.fromCallable(() -> token(exchange.getRequest())).map((token) -> {
if (token.isEmpty()) {
BearerTokenError error = invalidTokenError();
throw new OAuth2AuthenticationException(error);

View File

@@ -42,7 +42,7 @@ public final class TestOAuth2AuthenticatedPrincipals {
}
public static OAuth2AuthenticatedPrincipal active() {
return active(attributes -> {
return active((attributes) -> {
});
}

View File

@@ -63,7 +63,7 @@ public class JwtAuthenticationConverterTests {
public void convertWithOverriddenGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Collection<GrantedAuthority>> grantedAuthoritiesConverter = token -> Arrays
Converter<Jwt, Collection<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Arrays
.asList(new SimpleGrantedAuthority("blah"));
this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);

View File

@@ -83,7 +83,7 @@ public class JwtAuthenticationProviderTests {
given(this.jwtDecoder.decode("token")).willThrow(BadJwtException.class);
assertThatCode(() -> this.provider.authenticate(token))
.matches(failed -> failed instanceof OAuth2AuthenticationException)
.matches((failed) -> failed instanceof OAuth2AuthenticationException)
.matches(errorCode(BearerTokenErrorCodes.INVALID_TOKEN));
}
@@ -134,7 +134,7 @@ public class JwtAuthenticationProviderTests {
}
private Predicate<? super Throwable> errorCode(String errorCode) {
return failed -> ((OAuth2AuthenticationException) failed).getError().getErrorCode() == errorCode;
return (failed) -> ((OAuth2AuthenticationException) failed).getError().getErrorCode() == errorCode;
}
}

View File

@@ -97,7 +97,7 @@ public class JwtIssuerAuthenticationManagerResolverTests {
public void resolveWhenUsingCustomIssuerAuthenticationManagerResolverThenUses() {
AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
JwtIssuerAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerAuthenticationManagerResolver(
issuer -> authenticationManager);
(issuer) -> authenticationManager);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Bearer " + this.jwt);

View File

@@ -98,7 +98,7 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
public void resolveWhenUsingCustomIssuerAuthenticationManagerResolverThenUses() {
ReactiveAuthenticationManager authenticationManager = mock(ReactiveAuthenticationManager.class);
JwtIssuerReactiveAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerReactiveAuthenticationManagerResolver(
issuer -> Mono.just(authenticationManager));
(issuer) -> Mono.just(authenticationManager));
MockServerWebExchange exchange = withBearerToken(this.jwt);
assertThat(authenticationManagerResolver.resolve(exchange).block()).isSameAs(authenticationManager);
@@ -110,7 +110,7 @@ public class JwtIssuerReactiveAuthenticationManagerResolverTests {
Map<String, ReactiveAuthenticationManager> authenticationManagers = new HashMap<>();
JwtIssuerReactiveAuthenticationManagerResolver authenticationManagerResolver = new JwtIssuerReactiveAuthenticationManagerResolver(
issuer -> Mono.justOrEmpty(authenticationManagers.get(issuer)));
(issuer) -> Mono.justOrEmpty(authenticationManagers.get(issuer)));
assertThatCode(() -> authenticationManagerResolver.resolve(exchange).block())
.isInstanceOf(OAuth2AuthenticationException.class).hasMessageContaining("Invalid issuer");

View File

@@ -50,7 +50,7 @@ public class OpaqueTokenAuthenticationProviderTests {
@Test
public void authenticateWhenActiveTokenThenOk() throws Exception {
OAuth2AuthenticatedPrincipal principal = TestOAuth2AuthenticatedPrincipals
.active(attributes -> attributes.put("extension_field", "twenty-seven"));
.active((attributes) -> attributes.put("extension_field", "twenty-seven"));
OpaqueTokenIntrospector introspector = mock(OpaqueTokenIntrospector.class);
given(introspector.introspect(any())).willReturn(principal);
OpaqueTokenAuthenticationProvider provider = new OpaqueTokenAuthenticationProvider(introspector);

View File

@@ -51,7 +51,7 @@ public class OpaqueTokenReactiveAuthenticationManagerTests {
@Test
public void authenticateWhenActiveTokenThenOk() throws Exception {
OAuth2AuthenticatedPrincipal authority = TestOAuth2AuthenticatedPrincipals
.active(attributes -> attributes.put("extension_field", "twenty-seven"));
.active((attributes) -> attributes.put("extension_field", "twenty-seven"));
ReactiveOpaqueTokenIntrospector introspector = mock(ReactiveOpaqueTokenIntrospector.class);
given(introspector.introspect(any())).willReturn(Mono.just(authority));
OpaqueTokenReactiveAuthenticationManager provider = new OpaqueTokenReactiveAuthenticationManager(introspector);

View File

@@ -63,7 +63,7 @@ public class ReactiveJwtAuthenticationConverterTests {
public void convertWithOverriddenGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Flux<GrantedAuthority>> grantedAuthoritiesConverter = token -> Flux
Converter<Jwt, Flux<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Flux
.just(new SimpleGrantedAuthority("blah"));
this.jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);

View File

@@ -43,7 +43,7 @@ public class ReactiveJwtGrantedAuthoritiesConverterAdapterTests {
public void convertWithGrantedAuthoritiesConverter() {
Jwt jwt = TestJwts.jwt().claim("scope", "message:read message:write").build();
Converter<Jwt, Collection<GrantedAuthority>> grantedAuthoritiesConverter = token -> Arrays
Converter<Jwt, Collection<GrantedAuthority>> grantedAuthoritiesConverter = (token) -> Arrays
.asList(new SimpleGrantedAuthority("blah"));
Collection<GrantedAuthority> authorities = new ReactiveJwtGrantedAuthoritiesConverterAdapter(

View File

@@ -287,8 +287,8 @@ public class NimbusOpaqueTokenIntrospectorTests {
@Override
public MockResponse dispatch(RecordedRequest request) {
String authorization = request.getHeader(HttpHeaders.AUTHORIZATION);
return Optional.ofNullable(authorization).filter(a -> isAuthorized(authorization, username, password))
.map(a -> ok(response)).orElse(unauthorized());
return Optional.ofNullable(authorization).filter((a) -> isAuthorized(authorization, username, password))
.map((a) -> ok(response)).orElse(unauthorized());
}
};
}

View File

@@ -238,8 +238,8 @@ public class NimbusReactiveOpaqueTokenIntrospectorTests {
@Override
public MockResponse dispatch(RecordedRequest request) {
String authorization = request.getHeader(HttpHeaders.AUTHORIZATION);
return Optional.ofNullable(authorization).filter(a -> isAuthorized(authorization, username, password))
.map(a -> ok(response)).orElse(unauthorized());
return Optional.ofNullable(authorization).filter((a) -> isAuthorized(authorization, username, password))
.map((a) -> ok(response)).orElse(unauthorized());
}
};
}