Skip to content

Commit e913048

Browse files
philwebbrwinch
authored andcommitted
Remove restricted static imports
Replace static imports with class referenced methods. With the exception of a few well known static imports, checkstyle restricts the static imports that a class can use. For example, `asList(...)` would be replaced with `Arrays.asList(...)`. Issue gh-8945
1 parent 9a3fa6e commit e913048

252 files changed

Lines changed: 2216 additions & 2222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎acl/src/test/java/org/springframework/security/acls/jdbc/JdbcAclServiceTests.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
import org.springframework.security.acls.model.Sid;
4444

4545
import static org.assertj.core.api.Assertions.assertThat;
46-
import static org.mockito.AdditionalMatchers.aryEq;
4746
import static org.mockito.ArgumentMatchers.any;
4847
import static org.mockito.ArgumentMatchers.anyList;
4948
import static org.mockito.ArgumentMatchers.anyString;
49+
import static org.mockito.ArgumentMatchers.eq;
5050
import static org.mockito.BDDMockito.given;
5151

5252
/**
@@ -105,7 +105,7 @@ public void findOneChildren() {
105105
List<ObjectIdentity> result = new ArrayList<>();
106106
result.add(new ObjectIdentityImpl(Object.class, "5577"));
107107
Object[] args = { "1", "org.springframework.security.acls.jdbc.JdbcAclServiceTests$MockLongIdDomainObject" };
108-
given(this.jdbcOperations.query(anyString(), aryEq(args), any(RowMapper.class))).willReturn(result);
108+
given(this.jdbcOperations.query(anyString(), eq(args), any(RowMapper.class))).willReturn(result);
109109
ObjectIdentity objectIdentity = new ObjectIdentityImpl(MockLongIdDomainObject.class, 1L);
110110

111111
List<ObjectIdentity> objectIdentities = this.aclService.findChildren(objectIdentity);

‎config/src/integration-test/java/org/springframework/security/config/annotation/authentication/ldap/LdapAuthenticationProviderBuilderSecurityBuilderTests.java‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.net.ServerSocket;
21+
import java.util.Collections;
2122
import java.util.List;
2223

2324
import javax.naming.directory.SearchControls;
@@ -46,7 +47,6 @@
4647
import org.springframework.test.util.ReflectionTestUtils;
4748
import org.springframework.test.web.servlet.MockMvc;
4849

49-
import static java.util.Collections.singleton;
5050
import static org.assertj.core.api.Assertions.assertThat;
5151
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
5252
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated;
@@ -117,17 +117,19 @@ public void rolePrefixCustom() {
117117
public void bindAuthentication() throws Exception {
118118
this.spring.register(BindAuthenticationConfig.class).autowire();
119119

120-
this.mockMvc.perform(formLogin().user("bob").password("bobspassword")).andExpect(authenticated()
121-
.withUsername("bob").withAuthorities(singleton(new SimpleGrantedAuthority("ROLE_DEVELOPERS"))));
120+
this.mockMvc.perform(formLogin().user("bob").password("bobspassword"))
121+
.andExpect(authenticated().withUsername("bob")
122+
.withAuthorities(Collections.singleton(new SimpleGrantedAuthority("ROLE_DEVELOPERS"))));
122123
}
123124

124125
// SEC-2472
125126
@Test
126127
public void canUseCryptoPasswordEncoder() throws Exception {
127128
this.spring.register(PasswordEncoderConfig.class).autowire();
128129

129-
this.mockMvc.perform(formLogin().user("bcrypt").password("password")).andExpect(authenticated()
130-
.withUsername("bcrypt").withAuthorities(singleton(new SimpleGrantedAuthority("ROLE_DEVELOPERS"))));
130+
this.mockMvc.perform(formLogin().user("bcrypt").password("password"))
131+
.andExpect(authenticated().withUsername("bcrypt")
132+
.withAuthorities(Collections.singleton(new SimpleGrantedAuthority("ROLE_DEVELOPERS"))));
131133
}
132134

133135
private LdapAuthenticationProvider ldapProvider() {

‎config/src/integration-test/java/org/springframework/security/config/annotation/authentication/ldap/LdapAuthenticationProviderConfigurerTests.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.config.annotation.authentication.ldap;
1818

19+
import java.util.Collections;
20+
1921
import org.junit.Rule;
2022
import org.junit.Test;
2123

@@ -29,7 +31,6 @@
2931
import org.springframework.security.core.authority.SimpleGrantedAuthority;
3032
import org.springframework.test.web.servlet.MockMvc;
3133

32-
import static java.util.Collections.singleton;
3334
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin;
3435
import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.authenticated;
3536

@@ -54,16 +55,18 @@ public void authenticationManagerSupportMultipleDefaultLdapContextsWithPortsDyna
5455
public void authenticationManagerSupportMultipleLdapContextWithDefaultRolePrefix() throws Exception {
5556
this.spring.register(MultiLdapAuthenticationProvidersConfig.class).autowire();
5657

57-
this.mockMvc.perform(formLogin().user("bob").password("bobspassword")).andExpect(authenticated()
58-
.withUsername("bob").withAuthorities(singleton(new SimpleGrantedAuthority("ROLE_DEVELOPERS"))));
58+
this.mockMvc.perform(formLogin().user("bob").password("bobspassword"))
59+
.andExpect(authenticated().withUsername("bob")
60+
.withAuthorities(Collections.singleton(new SimpleGrantedAuthority("ROLE_DEVELOPERS"))));
5961
}
6062

6163
@Test
6264
public void authenticationManagerSupportMultipleLdapContextWithCustomRolePrefix() throws Exception {
6365
this.spring.register(MultiLdapWithCustomRolePrefixAuthenticationProvidersConfig.class).autowire();
6466

65-
this.mockMvc.perform(formLogin().user("bob").password("bobspassword")).andExpect(authenticated()
66-
.withUsername("bob").withAuthorities(singleton(new SimpleGrantedAuthority("ROL_DEVELOPERS"))));
67+
this.mockMvc.perform(formLogin().user("bob").password("bobspassword"))
68+
.andExpect(authenticated().withUsername("bob")
69+
.withAuthorities(Collections.singleton(new SimpleGrantedAuthority("ROL_DEVELOPERS"))));
6770
}
6871

6972
@Test

‎config/src/integration-test/java/org/springframework/security/config/annotation/rsocket/JwtITests.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import io.rsocket.RSocketFactory;
2323
import io.rsocket.frame.decoder.PayloadDecoder;
24+
import io.rsocket.metadata.WellKnownMimeType;
2425
import io.rsocket.transport.netty.server.CloseableChannel;
2526
import io.rsocket.transport.netty.server.TcpServerTransport;
2627
import org.junit.After;
@@ -51,7 +52,6 @@
5152
import org.springframework.util.MimeType;
5253
import org.springframework.util.MimeTypeUtils;
5354

54-
import static io.rsocket.metadata.WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION;
5555
import static org.assertj.core.api.Assertions.assertThat;
5656
import static org.mockito.ArgumentMatchers.any;
5757
import static org.mockito.BDDMockito.given;
@@ -109,7 +109,8 @@ public void routeWhenBearerThenAuthorized() {
109109

110110
@Test
111111
public void routeWhenAuthenticationBearerThenAuthorized() {
112-
MimeType authenticationMimeType = MimeTypeUtils.parseMimeType(MESSAGE_RSOCKET_AUTHENTICATION.getString());
112+
MimeType authenticationMimeType = MimeTypeUtils
113+
.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString());
113114

114115
BearerTokenMetadata credentials = new BearerTokenMetadata("token");
115116
given(this.decoder.decode(any())).willReturn(Mono.just(jwt()));

‎config/src/integration-test/java/org/springframework/security/config/annotation/rsocket/SimpleAuthenticationITests.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.rsocket.RSocketFactory;
2323
import io.rsocket.exceptions.ApplicationErrorException;
2424
import io.rsocket.frame.decoder.PayloadDecoder;
25+
import io.rsocket.metadata.WellKnownMimeType;
2526
import io.rsocket.transport.netty.server.CloseableChannel;
2627
import io.rsocket.transport.netty.server.TcpServerTransport;
2728
import org.junit.After;
@@ -50,7 +51,6 @@
5051
import org.springframework.util.MimeType;
5152
import org.springframework.util.MimeTypeUtils;
5253

53-
import static io.rsocket.metadata.WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION;
5454
import static org.assertj.core.api.Assertions.assertThat;
5555
import static org.assertj.core.api.Assertions.assertThatCode;
5656

@@ -101,7 +101,8 @@ public void retrieveMonoWhenSecureThenDenied() throws Exception {
101101

102102
@Test
103103
public void retrieveMonoWhenAuthorizedThenGranted() {
104-
MimeType authenticationMimeType = MimeTypeUtils.parseMimeType(MESSAGE_RSOCKET_AUTHENTICATION.getString());
104+
MimeType authenticationMimeType = MimeTypeUtils
105+
.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString());
105106

106107
UsernamePasswordMetadata credentials = new UsernamePasswordMetadata("rob", "password");
107108
this.requester = RSocketRequester.builder().setupMetadata(credentials, authenticationMimeType)

‎config/src/integration-test/java/org/springframework/security/config/ldap/LdapUserServiceBeanDefinitionParserTests.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636

3737
import static org.assertj.core.api.Assertions.assertThat;
3838
import static org.mockito.Mockito.mock;
39-
import static org.springframework.security.config.ldap.LdapUserServiceBeanDefinitionParser.INET_ORG_PERSON_MAPPER_CLASS;
40-
import static org.springframework.security.config.ldap.LdapUserServiceBeanDefinitionParser.LDAP_AUTHORITIES_POPULATOR_CLASS;
41-
import static org.springframework.security.config.ldap.LdapUserServiceBeanDefinitionParser.LDAP_SEARCH_CLASS;
42-
import static org.springframework.security.config.ldap.LdapUserServiceBeanDefinitionParser.LDAP_USER_MAPPER_CLASS;
43-
import static org.springframework.security.config.ldap.LdapUserServiceBeanDefinitionParser.PERSON_MAPPER_CLASS;
4439

4540
/**
4641
* @author Luke Taylor
@@ -61,11 +56,16 @@ public void closeAppContext() {
6156

6257
@Test
6358
public void beanClassNamesAreCorrect() {
64-
assertThat(FilterBasedLdapUserSearch.class.getName()).isEqualTo(LDAP_SEARCH_CLASS);
65-
assertThat(PersonContextMapper.class.getName()).isEqualTo(PERSON_MAPPER_CLASS);
66-
assertThat(InetOrgPersonContextMapper.class.getName()).isEqualTo(INET_ORG_PERSON_MAPPER_CLASS);
67-
assertThat(LdapUserDetailsMapper.class.getName()).isEqualTo(LDAP_USER_MAPPER_CLASS);
68-
assertThat(DefaultLdapAuthoritiesPopulator.class.getName()).isEqualTo(LDAP_AUTHORITIES_POPULATOR_CLASS);
59+
assertThat(FilterBasedLdapUserSearch.class.getName())
60+
.isEqualTo(LdapUserServiceBeanDefinitionParser.LDAP_SEARCH_CLASS);
61+
assertThat(PersonContextMapper.class.getName())
62+
.isEqualTo(LdapUserServiceBeanDefinitionParser.PERSON_MAPPER_CLASS);
63+
assertThat(InetOrgPersonContextMapper.class.getName())
64+
.isEqualTo(LdapUserServiceBeanDefinitionParser.INET_ORG_PERSON_MAPPER_CLASS);
65+
assertThat(LdapUserDetailsMapper.class.getName())
66+
.isEqualTo(LdapUserServiceBeanDefinitionParser.LDAP_USER_MAPPER_CLASS);
67+
assertThat(DefaultLdapAuthoritiesPopulator.class.getName())
68+
.isEqualTo(LdapUserServiceBeanDefinitionParser.LDAP_AUTHORITIES_POPULATOR_CLASS);
6969
assertThat(new LdapUserServiceBeanDefinitionParser().getBeanClassName(mock(Element.class)))
7070
.isEqualTo(LdapUserDetailsService.class.getName());
7171
}

‎config/src/main/java/org/springframework/security/config/annotation/web/configuration/SecurityReactorContextConfiguration.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import org.springframework.web.context.request.RequestContextHolder;
4141
import org.springframework.web.context.request.ServletRequestAttributes;
4242

43-
import static org.springframework.security.config.annotation.web.configuration.SecurityReactorContextConfiguration.SecurityReactorContextSubscriber.SECURITY_CONTEXT_ATTRIBUTES;
44-
4543
/**
4644
* {@link Configuration} that (potentially) adds a "decorating" {@code Publisher} for the
4745
* last operator created in every {@code Mono} or {@code Flux}.
@@ -88,7 +86,7 @@ public void destroy() throws Exception {
8886
}
8987

9088
<T> CoreSubscriber<T> createSubscriberIfNecessary(CoreSubscriber<T> delegate) {
91-
if (delegate.currentContext().hasKey(SECURITY_CONTEXT_ATTRIBUTES)) {
89+
if (delegate.currentContext().hasKey(SecurityReactorContextSubscriber.SECURITY_CONTEXT_ATTRIBUTES)) {
9290
// Already enriched. No need to create Subscriber so return original
9391
return delegate;
9492
}

‎config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurer.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
import org.springframework.security.web.util.matcher.RequestMatcher;
5252
import org.springframework.util.Assert;
5353

54-
import static org.springframework.security.oauth2.jwt.NimbusJwtDecoder.withJwkSetUri;
55-
5654
/**
5755
*
5856
* An {@link AbstractHttpConfigurer} for OAuth 2.0 Resource Server Support.
@@ -367,7 +365,7 @@ public JwtConfigurer decoder(JwtDecoder decoder) {
367365
}
368366

369367
public JwtConfigurer jwkSetUri(String uri) {
370-
this.decoder = withJwkSetUri(uri).build();
368+
this.decoder = NimbusJwtDecoder.withJwkSetUri(uri).build();
371369
return this;
372370
}
373371

‎config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurer.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
4848
import org.springframework.security.web.util.matcher.RequestMatcher;
4949
import org.springframework.util.Assert;
50-
51-
import static org.springframework.util.StringUtils.hasText;
50+
import org.springframework.util.StringUtils;
5251

5352
/**
5453
* An {@link AbstractHttpConfigurer} for SAML 2.0 Login, which leverages the SAML 2.0 Web
@@ -215,7 +214,7 @@ public void init(B http) throws Exception {
215214
setAuthenticationFilter(this.saml2WebSsoAuthenticationFilter);
216215
super.loginProcessingUrl(this.loginProcessingUrl);
217216

218-
if (hasText(this.loginPage)) {
217+
if (StringUtils.hasText(this.loginPage)) {
219218
// Set custom login page
220219
super.loginPage(this.loginPage);
221220
super.init(http);

‎config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java‎

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,6 @@
6868
import org.springframework.util.StringUtils;
6969
import org.springframework.util.xml.DomUtils;
7070

71-
import static org.springframework.security.config.http.SecurityFilters.ANONYMOUS_FILTER;
72-
import static org.springframework.security.config.http.SecurityFilters.BASIC_AUTH_FILTER;
73-
import static org.springframework.security.config.http.SecurityFilters.BEARER_TOKEN_AUTH_FILTER;
74-
import static org.springframework.security.config.http.SecurityFilters.EXCEPTION_TRANSLATION_FILTER;
75-
import static org.springframework.security.config.http.SecurityFilters.FORM_LOGIN_FILTER;
76-
import static org.springframework.security.config.http.SecurityFilters.LOGIN_PAGE_FILTER;
77-
import static org.springframework.security.config.http.SecurityFilters.LOGOUT_FILTER;
78-
import static org.springframework.security.config.http.SecurityFilters.LOGOUT_PAGE_FILTER;
79-
import static org.springframework.security.config.http.SecurityFilters.OAUTH2_AUTHORIZATION_CODE_GRANT_FILTER;
80-
import static org.springframework.security.config.http.SecurityFilters.OAUTH2_AUTHORIZATION_REQUEST_FILTER;
81-
import static org.springframework.security.config.http.SecurityFilters.OAUTH2_LOGIN_FILTER;
82-
import static org.springframework.security.config.http.SecurityFilters.OPENID_FILTER;
83-
import static org.springframework.security.config.http.SecurityFilters.PRE_AUTH_FILTER;
84-
import static org.springframework.security.config.http.SecurityFilters.REMEMBER_ME_FILTER;
85-
import static org.springframework.security.config.http.SecurityFilters.X509_FILTER;
86-
8771
/**
8872
* Handles creation of authentication mechanism filters and related beans for &lt;http&gt;
8973
* parsing.
@@ -993,59 +977,64 @@ List<OrderDecorator> getFilters() {
993977
List<OrderDecorator> filters = new ArrayList<>();
994978

995979
if (this.anonymousFilter != null) {
996-
filters.add(new OrderDecorator(this.anonymousFilter, ANONYMOUS_FILTER));
980+
filters.add(new OrderDecorator(this.anonymousFilter, SecurityFilters.ANONYMOUS_FILTER));
997981
}
998982

999983
if (this.rememberMeFilter != null) {
1000-
filters.add(new OrderDecorator(this.rememberMeFilter, REMEMBER_ME_FILTER));
984+
filters.add(new OrderDecorator(this.rememberMeFilter, SecurityFilters.REMEMBER_ME_FILTER));
1001985
}
1002986

1003987
if (this.logoutFilter != null) {
1004-
filters.add(new OrderDecorator(this.logoutFilter, LOGOUT_FILTER));
988+
filters.add(new OrderDecorator(this.logoutFilter, SecurityFilters.LOGOUT_FILTER));
1005989
}
1006990

1007991
if (this.x509Filter != null) {
1008-
filters.add(new OrderDecorator(this.x509Filter, X509_FILTER));
992+
filters.add(new OrderDecorator(this.x509Filter, SecurityFilters.X509_FILTER));
1009993
}
1010994

1011995
if (this.jeeFilter != null) {
1012-
filters.add(new OrderDecorator(this.jeeFilter, PRE_AUTH_FILTER));
996+
filters.add(new OrderDecorator(this.jeeFilter, SecurityFilters.PRE_AUTH_FILTER));
1013997
}
1014998

1015999
if (this.formFilterId != null) {
1016-
filters.add(new OrderDecorator(new RuntimeBeanReference(this.formFilterId), FORM_LOGIN_FILTER));
1000+
filters.add(
1001+
new OrderDecorator(new RuntimeBeanReference(this.formFilterId), SecurityFilters.FORM_LOGIN_FILTER));
10171002
}
10181003

10191004
if (this.oauth2LoginFilterId != null) {
1020-
filters.add(new OrderDecorator(new RuntimeBeanReference(this.oauth2LoginFilterId), OAUTH2_LOGIN_FILTER));
1005+
filters.add(new OrderDecorator(new RuntimeBeanReference(this.oauth2LoginFilterId),
1006+
SecurityFilters.OAUTH2_LOGIN_FILTER));
10211007
filters.add(new OrderDecorator(this.oauth2AuthorizationRequestRedirectFilter,
1022-
OAUTH2_AUTHORIZATION_REQUEST_FILTER));
1008+
SecurityFilters.OAUTH2_AUTHORIZATION_REQUEST_FILTER));
10231009
}
10241010

10251011
if (this.openIDFilterId != null) {
1026-
filters.add(new OrderDecorator(new RuntimeBeanReference(this.openIDFilterId), OPENID_FILTER));
1012+
filters.add(
1013+
new OrderDecorator(new RuntimeBeanReference(this.openIDFilterId), SecurityFilters.OPENID_FILTER));
10271014
}
10281015

10291016
if (this.loginPageGenerationFilter != null) {
1030-
filters.add(new OrderDecorator(this.loginPageGenerationFilter, LOGIN_PAGE_FILTER));
1031-
filters.add(new OrderDecorator(this.logoutPageGenerationFilter, LOGOUT_PAGE_FILTER));
1017+
filters.add(new OrderDecorator(this.loginPageGenerationFilter, SecurityFilters.LOGIN_PAGE_FILTER));
1018+
filters.add(new OrderDecorator(this.logoutPageGenerationFilter, SecurityFilters.LOGOUT_PAGE_FILTER));
10321019
}
10331020

10341021
if (this.basicFilter != null) {
1035-
filters.add(new OrderDecorator(this.basicFilter, BASIC_AUTH_FILTER));
1022+
filters.add(new OrderDecorator(this.basicFilter, SecurityFilters.BASIC_AUTH_FILTER));
10361023
}
10371024

10381025
if (this.bearerTokenAuthenticationFilter != null) {
1039-
filters.add(new OrderDecorator(this.bearerTokenAuthenticationFilter, BEARER_TOKEN_AUTH_FILTER));
1026+
filters.add(
1027+
new OrderDecorator(this.bearerTokenAuthenticationFilter, SecurityFilters.BEARER_TOKEN_AUTH_FILTER));
10401028
}
10411029

10421030
if (this.authorizationCodeGrantFilter != null) {
10431031
filters.add(new OrderDecorator(this.authorizationRequestRedirectFilter,
1044-
OAUTH2_AUTHORIZATION_REQUEST_FILTER.getOrder() + 1));
1045-
filters.add(new OrderDecorator(this.authorizationCodeGrantFilter, OAUTH2_AUTHORIZATION_CODE_GRANT_FILTER));
1032+
SecurityFilters.OAUTH2_AUTHORIZATION_REQUEST_FILTER.getOrder() + 1));
1033+
filters.add(new OrderDecorator(this.authorizationCodeGrantFilter,
1034+
SecurityFilters.OAUTH2_AUTHORIZATION_CODE_GRANT_FILTER));
10461035
}
10471036

1048-
filters.add(new OrderDecorator(this.etf, EXCEPTION_TRANSLATION_FILTER));
1037+
filters.add(new OrderDecorator(this.etf, SecurityFilters.EXCEPTION_TRANSLATION_FILTER));
10491038

10501039
return filters;
10511040
}

0 commit comments

Comments
 (0)