Apply updated Code Style

Closes gh-13881
This commit is contained in:
Marcus Da Coregio
2023-09-29 11:44:32 -03:00
parent 650692964e
commit 64e2a2ff8b
1172 changed files with 10805 additions and 8768 deletions

View File

@@ -74,7 +74,7 @@ class MessageExpressionConfigAttribute implements ConfigAttribute, EvaluationCon
public EvaluationContext postProcess(EvaluationContext ctx, Message<?> message) {
if (this.matcher instanceof SimpDestinationMessageMatcher) {
Map<String, String> variables = ((SimpDestinationMessageMatcher) this.matcher)
.extractPathVariables(message);
.extractPathVariables(message);
for (Map.Entry<String, String> entry : variables.entrySet()) {
ctx.setVariable(entry.getKey(), entry.getValue());
}

View File

@@ -88,7 +88,7 @@ import org.springframework.util.StringUtils;
public final class AuthenticationPrincipalArgumentResolver implements HandlerMethodArgumentResolver {
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy();
.getContextHolderStrategy();
private ExpressionParser parser = new SpelExpressionParser();

View File

@@ -47,7 +47,7 @@ public final class SecurityContextChannelInterceptor extends ChannelInterceptorA
private static final ThreadLocal<Stack<SecurityContext>> originalContext = new ThreadLocal<>();
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy();
.getContextHolderStrategy();
private SecurityContext empty = this.securityContextHolderStrategy.createEmptyContext();

View File

@@ -53,7 +53,7 @@ public final class CsrfChannelInterceptor extends ChannelInterceptorAdapter {
throw new MissingCsrfTokenException(null);
}
String actualTokenValue = SimpMessageHeaderAccessor.wrap(message)
.getFirstNativeHeader(expectedToken.getHeaderName());
.getFirstNativeHeader(expectedToken.getHeaderName());
boolean csrfCheckPassed = expectedToken.getToken().equals(actualTokenValue);
if (!csrfCheckPassed) {
throw new InvalidCsrfTokenException(expectedToken, actualTokenValue);

View File

@@ -55,7 +55,7 @@ public final class XorCsrfChannelInterceptor implements ChannelInterceptor {
throw new MissingCsrfTokenException(null);
}
String actualToken = SimpMessageHeaderAccessor.wrap(message)
.getFirstNativeHeader(expectedToken.getHeaderName());
.getFirstNativeHeader(expectedToken.getHeaderName());
String actualTokenValue = XorCsrfTokenUtils.getTokenValue(actualToken, expectedToken.getToken());
boolean csrfCheckPassed = equalsConstantTime(expectedToken.getToken(), actualTokenValue);
if (!csrfCheckPassed) {

View File

@@ -45,7 +45,7 @@ public final class CsrfTokenHandshakeInterceptor implements HandshakeInterceptor
Map<String, Object> attributes) {
HttpServletRequest httpRequest = ((ServletServerHttpRequest) request).getServletRequest();
DeferredCsrfToken deferredCsrfToken = (DeferredCsrfToken) httpRequest
.getAttribute(DeferredCsrfToken.class.getName());
.getAttribute(DeferredCsrfToken.class.getName());
if (deferredCsrfToken == null) {
return true;
}

View File

@@ -119,8 +119,9 @@ public class DefaultMessageSecurityExpressionHandlerTests {
EvaluationContext context = this.handler.createEvaluationContext(mockAuthenticationSupplier, this.message);
verifyNoInteractions(mockAuthenticationSupplier);
assertThat(context.getRootObject()).extracting(TypedValue::getValue)
.asInstanceOf(InstanceOfAssertFactories.type(MessageSecurityExpressionRoot.class))
.extracting(SecurityExpressionRoot::getAuthentication).isEqualTo(this.authentication);
.asInstanceOf(InstanceOfAssertFactories.type(MessageSecurityExpressionRoot.class))
.extracting(SecurityExpressionRoot::getAuthentication)
.isEqualTo(this.authentication);
verify(mockAuthenticationSupplier).get();
}

View File

@@ -67,7 +67,7 @@ public class ExpressionBasedMessageSecurityMetadataSourceFactoryTests {
this.matcherToExpression.put(this.matcher1, this.expression1);
this.matcherToExpression.put(this.matcher2, this.expression2);
this.source = ExpressionBasedMessageSecurityMetadataSourceFactory
.createExpressionMessageMetadataSource(this.matcherToExpression);
.createExpressionMessageMetadataSource(this.matcherToExpression);
this.rootObject = new MessageSecurityExpressionRoot(this.authentication, this.message);
}
@@ -85,7 +85,7 @@ public class ExpressionBasedMessageSecurityMetadataSourceFactoryTests {
ConfigAttribute attr = attrs.iterator().next();
assertThat(attr).isInstanceOf(MessageExpressionConfigAttribute.class);
assertThat(((MessageExpressionConfigAttribute) attr).getAuthorizeExpression().getValue(this.rootObject))
.isEqualTo(true);
.isEqualTo(true);
}
@Test
@@ -96,7 +96,7 @@ public class ExpressionBasedMessageSecurityMetadataSourceFactoryTests {
ConfigAttribute attr = attrs.iterator().next();
assertThat(attr).isInstanceOf(MessageExpressionConfigAttribute.class);
assertThat(((MessageExpressionConfigAttribute) attr).getAuthorizeExpression().getValue(this.rootObject))
.isEqualTo(false);
.isEqualTo(false);
}
}

View File

@@ -60,7 +60,7 @@ public class MessageExpressionConfigAttributeTests {
@Test
public void constructorNullMatcher() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new MessageExpressionConfigAttribute(this.expression, null));
.isThrownBy(() -> new MessageExpressionConfigAttribute(this.expression, null));
}
@Test

View File

@@ -71,7 +71,7 @@ public class MessageExpressionVoterTests {
@BeforeEach
public void setup() {
this.attributes = Arrays
.<ConfigAttribute>asList(new MessageExpressionConfigAttribute(this.expression, this.matcher));
.<ConfigAttribute>asList(new MessageExpressionConfigAttribute(this.expression, this.matcher));
this.voter = new MessageExpressionVoter();
}
@@ -79,21 +79,21 @@ public class MessageExpressionVoterTests {
public void voteGranted() {
given(this.expression.getValue(any(EvaluationContext.class), eq(Boolean.class))).willReturn(true);
assertThat(this.voter.vote(this.authentication, this.message, this.attributes))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
@Test
public void voteDenied() {
given(this.expression.getValue(any(EvaluationContext.class), eq(Boolean.class))).willReturn(false);
assertThat(this.voter.vote(this.authentication, this.message, this.attributes))
.isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
.isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
}
@Test
public void voteAbstain() {
this.attributes = Arrays.<ConfigAttribute>asList(new SecurityConfig("ROLE_USER"));
assertThat(this.voter.vote(this.authentication, this.message, this.attributes))
.isEqualTo(AccessDecisionVoter.ACCESS_ABSTAIN);
.isEqualTo(AccessDecisionVoter.ACCESS_ABSTAIN);
}
@Test
@@ -125,10 +125,10 @@ public class MessageExpressionVoterTests {
public void customExpressionHandler() {
this.voter.setExpressionHandler(this.expressionHandler);
given(this.expressionHandler.createEvaluationContext(this.authentication, this.message))
.willReturn(this.evaluationContext);
.willReturn(this.evaluationContext);
given(this.expression.getValue(this.evaluationContext, Boolean.class)).willReturn(true);
assertThat(this.voter.vote(this.authentication, this.message, this.attributes))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
verify(this.expressionHandler).createEvaluationContext(this.authentication, this.message);
}
@@ -137,13 +137,13 @@ public class MessageExpressionVoterTests {
final MessageExpressionConfigAttribute configAttribute = mock(MessageExpressionConfigAttribute.class);
this.voter.setExpressionHandler(this.expressionHandler);
given(this.expressionHandler.createEvaluationContext(this.authentication, this.message))
.willReturn(this.evaluationContext);
.willReturn(this.evaluationContext);
given(configAttribute.getAuthorizeExpression()).willReturn(this.expression);
this.attributes = Arrays.<ConfigAttribute>asList(configAttribute);
given(configAttribute.postProcess(this.evaluationContext, this.message)).willReturn(this.evaluationContext);
given(this.expression.getValue(any(EvaluationContext.class), eq(Boolean.class))).willReturn(true);
assertThat(this.voter.vote(this.authentication, this.message, this.attributes))
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
.isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
verify(configAttribute).postProcess(this.evaluationContext, this.message);
}

View File

@@ -89,13 +89,13 @@ public class AuthorizationChannelInterceptorTests {
public void preSendWhenDenyThenException() {
given(this.authorizationManager.check(any(), any())).willReturn(new AuthorizationDecision(false));
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> this.interceptor.preSend(this.message, this.channel));
.isThrownBy(() -> this.interceptor.preSend(this.message, this.channel));
}
@Test
public void setEventPublisherWhenNullThenException() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> this.interceptor.setAuthorizationEventPublisher(null));
.isThrownBy(() -> this.interceptor.setAuthorizationEventPublisher(null));
}
@Test

View File

@@ -118,10 +118,10 @@ public class ChannelSecurityInterceptorTests {
@Test
public void preSendDeny() {
given(this.source.getAttributes(this.message)).willReturn(this.attrs);
willThrow(new AccessDeniedException("")).given(this.accessDecisionManager).decide(any(Authentication.class),
eq(this.message), eq(this.attrs));
willThrow(new AccessDeniedException("")).given(this.accessDecisionManager)
.decide(any(Authentication.class), eq(this.message), eq(this.attrs));
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> this.interceptor.preSend(this.message, this.channel));
.isThrownBy(() -> this.interceptor.preSend(this.message, this.channel));
}
@SuppressWarnings("unchecked")
@@ -129,7 +129,7 @@ public class ChannelSecurityInterceptorTests {
public void preSendPostSendRunAs() {
given(this.source.getAttributes(this.message)).willReturn(this.attrs);
given(this.runAsManager.buildRunAs(any(Authentication.class), any(), any(Collection.class)))
.willReturn(this.runAs);
.willReturn(this.runAs);
Message<?> preSend = this.interceptor.preSend(this.message, this.channel);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(this.runAs);
this.interceptor.postSend(preSend, this.channel, true);
@@ -146,7 +146,7 @@ public class ChannelSecurityInterceptorTests {
public void preSendFinallySendRunAs() {
given(this.source.getAttributes(this.message)).willReturn(this.attrs);
given(this.runAsManager.buildRunAs(any(Authentication.class), any(), any(Collection.class)))
.willReturn(this.runAs);
.willReturn(this.runAs);
Message<?> preSend = this.interceptor.preSend(this.message, this.channel);
assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(this.runAs);
this.interceptor.afterSendCompletion(preSend, this.channel, true, new RuntimeException());

View File

@@ -100,14 +100,14 @@ public class AuthenticationPrincipalArgumentResolverTests {
public void resolveArgumentUserDetails() throws Exception {
setAuthenticationPrincipal(new User("user", "password", AuthorityUtils.createAuthorityList("ROLE_USER")));
assertThat(this.resolver.resolveArgument(showUserAnnotationUserDetails(), null))
.isEqualTo(this.expectedPrincipal);
.isEqualTo(this.expectedPrincipal);
}
@Test
public void resolveArgumentCustomUserPrincipal() throws Exception {
setAuthenticationPrincipal(new CustomUserPrincipal());
assertThat(this.resolver.resolveArgument(showUserAnnotationCustomUserPrincipal(), null))
.isEqualTo(this.expectedPrincipal);
.isEqualTo(this.expectedPrincipal);
}
@Test
@@ -151,14 +151,14 @@ public class AuthenticationPrincipalArgumentResolverTests {
public void resolveArgumentErrorOnInvalidType() throws Exception {
setAuthenticationPrincipal(new CustomUserPrincipal());
assertThatExceptionOfType(ClassCastException.class)
.isThrownBy(() -> this.resolver.resolveArgument(showUserAnnotationErrorOnInvalidType(), null));
.isThrownBy(() -> this.resolver.resolveArgument(showUserAnnotationErrorOnInvalidType(), null));
}
@Test
public void resolveArgumentCustomserErrorOnInvalidType() throws Exception {
setAuthenticationPrincipal(new CustomUserPrincipal());
assertThatExceptionOfType(ClassCastException.class).isThrownBy(
() -> this.resolver.resolveArgument(showUserAnnotationCurrentUserErrorOnInvalidType(), null));
assertThatExceptionOfType(ClassCastException.class)
.isThrownBy(() -> this.resolver.resolveArgument(showUserAnnotationCurrentUserErrorOnInvalidType(), null));
}
@Test
@@ -219,7 +219,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
private void setAuthenticationPrincipal(Object principal) {
this.expectedPrincipal = principal;
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken(this.expectedPrincipal, "password", "ROLE_USER"));
.setAuthentication(new TestingAuthenticationToken(this.expectedPrincipal, "password", "ROLE_USER"));
}
@Target({ ElementType.PARAMETER })

View File

@@ -214,8 +214,9 @@ public final class ResolvableMethod {
}
private String formatMethod() {
return (method().getName() + Arrays.stream(this.method.getParameters()).map(this::formatParameter)
.collect(Collectors.joining(",\n\t", "(\n\t", "\n)")));
return (method().getName() + Arrays.stream(this.method.getParameters())
.map(this::formatParameter)
.collect(Collectors.joining(",\n\t", "(\n\t", "\n)")));
}
private String formatParameter(Parameter param) {
@@ -350,7 +351,7 @@ public final class ResolvableMethod {
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));
.allMatch((annotType) -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null));
return this;
}
@@ -362,8 +363,9 @@ public final class ResolvableMethod {
String message = "annotationNotPresent=" + Arrays.toString(annotationTypes);
addFilter(message, (candidate) -> {
if (annotationTypes.length != 0) {
return Arrays.stream(annotationTypes).noneMatch(
(annotType) -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null);
return Arrays.stream(annotationTypes)
.noneMatch((
annotType) -> AnnotatedElementUtils.findMergedAnnotation(candidate, annotType) != null);
}
else {
return candidate.getAnnotations().length == 0;
@@ -422,8 +424,9 @@ public final class ResolvableMethod {
}
private String formatMethods(Set<Method> methods) {
return "\nMatched:\n" + methods.stream().map(Method::toGenericString)
.collect(Collectors.joining(",\n\t", "[\n\t", "\n]"));
return "\nMatched:\n" + methods.stream()
.map(Method::toGenericString)
.collect(Collectors.joining(",\n\t", "[\n\t", "\n]"));
}
public ResolvableMethod mockCall(Consumer<T> invoker) {
@@ -497,8 +500,9 @@ public final class ResolvableMethod {
}
private String formatFilters() {
return this.filters.stream().map(Object::toString)
.collect(Collectors.joining(",\n\t\t", "[\n\t\t", "\n\t]"));
return this.filters.stream()
.map(Object::toString)
.collect(Collectors.joining(",\n\t\t", "[\n\t\t", "\n\t]"));
}
}

View File

@@ -49,7 +49,7 @@ public class CurrentSecurityContextArgumentResolverTests {
@Test
public void resolveArgumentWhenAuthenticationPrincipalAndEmptyContextThenNull() {
Object result = this.resolver.resolveArgument(arg0("currentSecurityContextOnMonoSecurityContext"), null)
.block();
.block();
assertThat(result).isNull();
}
@@ -57,8 +57,9 @@ public class CurrentSecurityContextArgumentResolverTests {
public void resolveArgumentWhenAuthenticationPrincipalThenFound() {
Authentication authentication = TestAuthentication.authenticatedUser();
Mono<SecurityContext> result = (Mono<SecurityContext>) this.resolver
.resolveArgument(arg0("currentSecurityContextOnMonoSecurityContext"), null)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication)).block();
.resolveArgument(arg0("currentSecurityContextOnMonoSecurityContext"), null)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication))
.block();
assertThat(result.block().getAuthentication()).isEqualTo(authentication);
}
@@ -75,8 +76,9 @@ public class CurrentSecurityContextArgumentResolverTests {
public void resolveArgumentWhenMonoAndAuthenticationPrincipalThenFound() {
Authentication authentication = TestAuthentication.authenticatedUser();
Mono<UserDetails> result = (Mono<UserDetails>) this.resolver
.resolveArgument(arg0("currentUserOnMonoUserDetails"), null)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication)).block();
.resolveArgument(arg0("currentUserOnMonoUserDetails"), null)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication))
.block();
assertThat(result.block()).isEqualTo(authentication.getPrincipal());
}
@@ -88,8 +90,9 @@ public class CurrentSecurityContextArgumentResolverTests {
public void resolveArgumentWhenExpressionThenFound() {
Authentication authentication = TestAuthentication.authenticatedUser();
Mono<String> result = (Mono<String>) this.resolver
.resolveArgument(arg0("authenticationPrincipalExpression"), null)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication)).block();
.resolveArgument(arg0("authenticationPrincipalExpression"), null)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication))
.block();
assertThat(result.block()).isEqualTo(authentication.getName());
}

View File

@@ -65,13 +65,13 @@ public class AndMessageMatcherTests {
@Test
public void constructorNullList() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AndMessageMatcher<>((List<MessageMatcher<Object>>) null));
.isThrownBy(() -> new AndMessageMatcher<>((List<MessageMatcher<Object>>) null));
}
@Test
public void constructorListContainsNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new AndMessageMatcher<>(Arrays.asList((MessageMatcher<Object>) null)));
.isThrownBy(() -> new AndMessageMatcher<>(Arrays.asList((MessageMatcher<Object>) null)));
}
@Test

View File

@@ -65,13 +65,13 @@ public class OrMessageMatcherTests {
@Test
public void constructorNullList() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new OrMessageMatcher<>((List<MessageMatcher<Object>>) null));
.isThrownBy(() -> new OrMessageMatcher<>((List<MessageMatcher<Object>>) null));
}
@Test
public void constructorListContainsNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new OrMessageMatcher<>(Arrays.asList((MessageMatcher<Object>) null)));
.isThrownBy(() -> new OrMessageMatcher<>(Arrays.asList((MessageMatcher<Object>) null)));
}
@Test

View File

@@ -116,28 +116,28 @@ public class CsrfChannelInterceptorTests {
public void preSendNoToken() {
this.messageHeaders.removeNativeHeader(this.token.getHeaderName());
assertThatExceptionOfType(InvalidCsrfTokenException.class)
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
}
@Test
public void preSendInvalidToken() {
this.messageHeaders.setNativeHeader(this.token.getHeaderName(), this.token.getToken() + "invalid");
assertThatExceptionOfType(InvalidCsrfTokenException.class)
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
}
@Test
public void preSendMissingToken() {
this.messageHeaders.getSessionAttributes().clear();
assertThatExceptionOfType(MissingCsrfTokenException.class)
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
}
@Test
public void preSendMissingTokenNullSessionAttributes() {
this.messageHeaders.setSessionAttributes(null);
assertThatExceptionOfType(MissingCsrfTokenException.class)
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
.isThrownBy(() -> this.interceptor.preSend(message(), this.channel));
}
private Message<String> message() {