Remove unnecessary lambda blocks
Remove lambda blocks that aren't needed and replace instead with a simple expression. Issue gh-8945
This commit is contained in:
parent
52f20b5281
commit
612fb22a7f
|
@ -221,9 +221,9 @@ public class RSocketMessageHandlerITests {
|
|||
|
||||
@Bean
|
||||
PayloadSocketAcceptorInterceptor rsocketInterceptor(RSocketSecurity rsocket) {
|
||||
rsocket.authorizePayload((authorize) -> {
|
||||
authorize.route("secure.*").authenticated().anyExchange().permitAll();
|
||||
}).basicAuthentication(Customizer.withDefaults());
|
||||
rsocket.authorizePayload(
|
||||
(authorize) -> authorize.route("secure.*").authenticated().anyExchange().permitAll())
|
||||
.basicAuthentication(Customizer.withDefaults());
|
||||
return rsocket.build();
|
||||
}
|
||||
|
||||
|
@ -247,9 +247,8 @@ public class RSocketMessageHandlerITests {
|
|||
|
||||
@MessageMapping({ "secure.send", "send" })
|
||||
Mono<Void> send(Mono<String> payload) {
|
||||
return payload.doOnNext(this::add).then(Mono.fromRunnable(() -> {
|
||||
doNotifyAll();
|
||||
}));
|
||||
return payload.doOnNext(this::add).then(Mono.fromRunnable(() -> doNotifyAll()));
|
||||
|
||||
}
|
||||
|
||||
private synchronized void doNotifyAll() {
|
||||
|
|
|
@ -336,12 +336,10 @@ public class HeaderSpecTests {
|
|||
@Test
|
||||
public void headersWhenCustomHeadersWriter() {
|
||||
this.expectedHeaders.add(CUSTOM_HEADER, CUSTOM_VALUE);
|
||||
this.http.headers((headers) -> headers.writer((exchange) -> {
|
||||
return Mono.just(exchange).doOnNext((it) -> {
|
||||
it.getResponse().getHeaders().add(CUSTOM_HEADER, CUSTOM_VALUE);
|
||||
}).then();
|
||||
this.http.headers((headers) -> headers.writer((exchange) -> Mono.just(exchange)
|
||||
.doOnNext((it) -> it.getResponse().getHeaders().add(CUSTOM_HEADER, CUSTOM_VALUE)).then()
|
||||
|
||||
}));
|
||||
));
|
||||
|
||||
assertHeaders();
|
||||
}
|
||||
|
|
|
@ -186,9 +186,7 @@ final class HtmlUnitWebTestClient {
|
|||
}
|
||||
|
||||
private ClientRequest withClientCookies(ClientRequest request) {
|
||||
return ClientRequest.from(request).cookies((c) -> {
|
||||
c.addAll(clientCookies());
|
||||
}).build();
|
||||
return ClientRequest.from(request).cookies((c) -> c.addAll(clientCookies())).build();
|
||||
}
|
||||
|
||||
private MultiValueMap<String, String> clientCookies() {
|
||||
|
|
|
@ -51,9 +51,7 @@ public class SecurityJackson2ModulesTests {
|
|||
@Test
|
||||
public void readValueWhenNotAllowedOrMappedThenThrowsException() {
|
||||
String content = "{\"@class\":\"org.springframework.security.jackson2.SecurityJackson2ModulesTests$NotAllowlisted\",\"property\":\"bar\"}";
|
||||
assertThatThrownBy(() -> {
|
||||
this.mapper.readValue(content, Object.class);
|
||||
}).hasStackTraceContaining("allowlist");
|
||||
assertThatThrownBy(() -> this.mapper.readValue(content, Object.class)).hasStackTraceContaining("allowlist");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
||||
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||
<suppressions>
|
||||
<suppress files=".*" checks="SpringJavadoc" />
|
||||
<suppress files=".*" checks="SpringLambda" />
|
||||
<suppress files=".*" checks="SpringMethodOrder" />
|
||||
<suppress files=".*" checks="SpringMethodVisibility" />
|
||||
<suppress files=".*" checks="SpringTernary" />
|
||||
|
@ -16,6 +14,7 @@
|
|||
<suppress files=".*" checks="JavadocType" />
|
||||
<suppress files=".*" checks="JavadocVariable" />
|
||||
<suppress files=".*" checks="NonEmptyAtclauseDescription" />
|
||||
<suppress files=".*" checks="SpringJavadoc" />
|
||||
|
||||
<!-- Ignore third-party code -->
|
||||
<suppress files="BCrypt\.java|BCryptTests\.java" checks=".*"/>
|
||||
|
|
|
@ -146,16 +146,14 @@ public final class DefaultReactiveOAuth2AuthorizedClientManager implements React
|
|||
.flatMap((serverWebExchange) -> Mono.justOrEmpty(authorizeRequest.getAuthorizedClient())
|
||||
.switchIfEmpty(Mono
|
||||
.defer(() -> loadAuthorizedClient(clientRegistrationId, principal, serverWebExchange)))
|
||||
.flatMap((authorizedClient) -> {
|
||||
// Re-authorize
|
||||
return authorizationContext(authorizeRequest, authorizedClient)
|
||||
.flatMap((authorizationContext) -> authorize(authorizationContext, principal,
|
||||
serverWebExchange))
|
||||
// Default to the existing authorizedClient if the
|
||||
// client was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient);
|
||||
}).switchIfEmpty(Mono.defer(() ->
|
||||
.flatMap((authorizedClient) -> // Re-authorize
|
||||
authorizationContext(authorizeRequest, authorizedClient).flatMap(
|
||||
(authorizationContext) -> authorize(authorizationContext, principal, serverWebExchange))
|
||||
// Default to the existing authorizedClient if the
|
||||
// client was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient))
|
||||
.switchIfEmpty(Mono.defer(() ->
|
||||
// Authorize
|
||||
this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId)
|
||||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException(
|
||||
|
|
|
@ -565,20 +565,16 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
|
|||
String clientRegistrationId = authorizeRequest.getClientRegistrationId();
|
||||
Authentication principal = authorizeRequest.getPrincipal();
|
||||
|
||||
return Mono.justOrEmpty(authorizeRequest.getAuthorizedClient())
|
||||
.switchIfEmpty(Mono.defer(() -> this.authorizedClientRepository
|
||||
.loadAuthorizedClient(clientRegistrationId, principal, null)))
|
||||
.flatMap((authorizedClient) -> {
|
||||
// Re-authorize
|
||||
return Mono
|
||||
.just(OAuth2AuthorizationContext.withAuthorizedClient(authorizedClient)
|
||||
.principal(principal).build())
|
||||
.flatMap((authorizationContext) -> authorize(authorizationContext, principal))
|
||||
// Default to the existing authorizedClient if the client
|
||||
// was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient);
|
||||
}).switchIfEmpty(Mono.defer(() ->
|
||||
return Mono.justOrEmpty(authorizeRequest.getAuthorizedClient()).switchIfEmpty(Mono.defer(
|
||||
() -> this.authorizedClientRepository.loadAuthorizedClient(clientRegistrationId, principal, null)))
|
||||
.flatMap((authorizedClient) -> // Re-authorize
|
||||
Mono.just(OAuth2AuthorizationContext.withAuthorizedClient(authorizedClient).principal(principal)
|
||||
.build()).flatMap((authorizationContext) -> authorize(authorizationContext, principal))
|
||||
// Default to the existing authorizedClient if the client
|
||||
// was not re-authorized
|
||||
.defaultIfEmpty(authorizeRequest.getAuthorizedClient() != null
|
||||
? authorizeRequest.getAuthorizedClient() : authorizedClient))
|
||||
.switchIfEmpty(Mono.defer(() ->
|
||||
// Authorize
|
||||
this.clientRegistrationRepository.findByRegistrationId(clientRegistrationId)
|
||||
.switchIfEmpty(Mono.error(() -> new IllegalArgumentException(
|
||||
|
|
|
@ -85,10 +85,10 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests {
|
|||
OAuth2AuthorizationExchange authorizationExchange = new OAuth2AuthorizationExchange(this.authorizationRequest,
|
||||
authorizationResponse);
|
||||
|
||||
assertThatThrownBy(() -> {
|
||||
this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange));
|
||||
}).isInstanceOf(OAuth2AuthorizationException.class).hasMessageContaining(OAuth2ErrorCodes.INVALID_REQUEST);
|
||||
assertThatThrownBy(() -> this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange)))
|
||||
.isInstanceOf(OAuth2AuthorizationException.class)
|
||||
.hasMessageContaining(OAuth2ErrorCodes.INVALID_REQUEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -98,10 +98,10 @@ public class OAuth2AuthorizationCodeAuthenticationProviderTests {
|
|||
OAuth2AuthorizationExchange authorizationExchange = new OAuth2AuthorizationExchange(this.authorizationRequest,
|
||||
authorizationResponse);
|
||||
|
||||
assertThatThrownBy(() -> {
|
||||
this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange));
|
||||
}).isInstanceOf(OAuth2AuthorizationException.class).hasMessageContaining("invalid_state_parameter");
|
||||
assertThatThrownBy(() -> this.authenticationProvider.authenticate(
|
||||
new OAuth2AuthorizationCodeAuthenticationToken(this.clientRegistration, authorizationExchange)))
|
||||
.isInstanceOf(OAuth2AuthorizationException.class)
|
||||
.hasMessageContaining("invalid_state_parameter");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
import static org.assertj.core.api.Assertions.assertThatObject;
|
||||
|
||||
/**
|
||||
* Tests for {@link ClaimAccessor}.
|
||||
|
@ -142,12 +142,7 @@ public class ClaimAccessorTests {
|
|||
String expectedClaimValue = "true";
|
||||
String claimName = "boolean";
|
||||
this.claims.put(claimName, expectedClaimValue);
|
||||
|
||||
Throwable thrown = catchThrowable(() -> {
|
||||
boolean actualClaimValue = this.claimAccessor.getClaim(claimName);
|
||||
});
|
||||
|
||||
assertThat(thrown).isInstanceOf(ClassCastException.class);
|
||||
assertThatObject(this.claimAccessor.getClaim(claimName)).isNotInstanceOf(Boolean.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,16 +38,14 @@ public class HeaderBearerTokenResolverTests {
|
|||
|
||||
@Test
|
||||
public void constructorWhenHeaderNullThenThrowIllegalArgumentException() {
|
||||
assertThatCode(() -> {
|
||||
new HeaderBearerTokenResolver(null);
|
||||
}).isInstanceOf(IllegalArgumentException.class).hasMessage("header cannot be empty");
|
||||
assertThatCode(() -> new HeaderBearerTokenResolver(null)).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("header cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorWhenHeaderEmptyThenThrowIllegalArgumentException() {
|
||||
assertThatCode(() -> {
|
||||
new HeaderBearerTokenResolver("");
|
||||
}).isInstanceOf(IllegalArgumentException.class).hasMessage("header cannot be empty");
|
||||
assertThatCode(() -> new HeaderBearerTokenResolver("")).isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessage("header cannot be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -94,9 +94,8 @@ public class PayloadInterceptorRSocketTests {
|
|||
public void constructorWhenNullDelegateThenException() {
|
||||
this.delegate = null;
|
||||
List<PayloadInterceptor> interceptors = Arrays.asList(this.interceptor);
|
||||
assertThatCode(() -> {
|
||||
new PayloadInterceptorRSocket(this.delegate, interceptors, this.metadataMimeType, this.dataMimeType);
|
||||
}).isInstanceOf(IllegalArgumentException.class);
|
||||
assertThatCode(() -> new PayloadInterceptorRSocket(this.delegate, interceptors, this.metadataMimeType,
|
||||
this.dataMimeType)).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -43,9 +43,7 @@ public class StaticServerHttpHeadersWriter implements ServerHttpHeadersWriter {
|
|||
HttpHeaders headers = exchange.getResponse().getHeaders();
|
||||
boolean containsOneHeaderToAdd = Collections.disjoint(headers.keySet(), this.headersToAdd.keySet());
|
||||
if (containsOneHeaderToAdd) {
|
||||
this.headersToAdd.forEach((name, values) -> {
|
||||
headers.put(name, values);
|
||||
});
|
||||
this.headersToAdd.forEach(headers::put);
|
||||
}
|
||||
return Mono.empty();
|
||||
}
|
||||
|
|
|
@ -111,9 +111,8 @@ public class CurrentSecurityContextArgumentResolverTests {
|
|||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
Authentication authentication = context.getAuthentication();
|
||||
context.setAuthentication(null);
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> {
|
||||
this.resolver.resolveArgument(showSecurityContextAuthenticationWithPrincipal(), null, null, null);
|
||||
});
|
||||
assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> this.resolver
|
||||
.resolveArgument(showSecurityContextAuthenticationWithPrincipal(), null, null, null));
|
||||
context.setAuthentication(authentication);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue