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