Add noformat blocks around auth config

Find `auth` config using a regex search of `^\s*auths*$` and protect
them against formatting.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-23 12:58:41 -07:00
committed by Rob Winch
parent 103d822e46
commit 63b5998fad
46 changed files with 158 additions and 64 deletions

View File

@@ -113,9 +113,11 @@ public class AuthenticationManagerBuilderTests {
static class PasswordEncoderGlobalConfig extends WebSecurityConfigurerAdapter {
@Autowired
void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
// @formatter:on
}
@Bean
@@ -139,9 +141,11 @@ public class AuthenticationManagerBuilderTests {
@EnableWebSecurity
static class PasswordEncoderConfig extends WebSecurityConfigurerAdapter {
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
// @formatter:on
}
@Bean

View File

@@ -28,9 +28,11 @@ import org.springframework.security.config.annotation.authentication.builders.Au
public class BaseAuthenticationConfig {
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
// @formatter:on
}
}

View File

@@ -55,9 +55,11 @@ public class NamespaceAuthenticationManagerTests {
static class EraseCredentialsTrueDefaultConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}
@@ -77,10 +79,12 @@ public class NamespaceAuthenticationManagerTests {
static class EraseCredentialsFalseConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.eraseCredentials(false)
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}
@@ -97,10 +101,12 @@ public class NamespaceAuthenticationManagerTests {
static class GlobalEraseCredentialsFalseConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.eraseCredentials(false)
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}
}

View File

@@ -56,8 +56,10 @@ public class NamespaceAuthenticationProviderTests {
@EnableWebSecurity
static class AuthenticationProviderRefConfig extends WebSecurityConfigurerAdapter {
protected void configure(AuthenticationManagerBuilder auth) {
// @formatter:off
auth
.authenticationProvider(authenticationProvider());
// @formatter:on
}
@Bean
@@ -80,8 +82,10 @@ public class NamespaceAuthenticationProviderTests {
@EnableWebSecurity
static class UserServiceRefConfig extends WebSecurityConfigurerAdapter {
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.userDetailsService(userDetailsService());
// @formatter:on
}
@Bean

View File

@@ -63,11 +63,13 @@ public class NamespaceJdbcUserServiceTests {
private DataSource dataSource;
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.jdbcAuthentication()
.withDefaultSchema()
.withUser(PasswordEncodedUser.user())
.dataSource(this.dataSource); // jdbc-user-service@data-source-ref
// @formatter:on
}
}
@@ -94,6 +96,7 @@ public class NamespaceJdbcUserServiceTests {
private DataSource dataSource;
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.jdbcAuthentication()
// jdbc-user-service@dataSource
@@ -108,6 +111,7 @@ public class NamespaceJdbcUserServiceTests {
.groupAuthoritiesByUsername(JdbcUserDetailsManager.DEF_GROUP_AUTHORITIES_BY_USERNAME_QUERY)
// jdbc-user-service@role-prefix
.rolePrefix("ROLE_");
// @formatter:on
}

View File

@@ -61,10 +61,12 @@ public class NamespacePasswordEncoderTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password(encoder.encode("password")).roles("USER").and()
.passwordEncoder(encoder);
// @formatter:on
}
}
@@ -82,12 +84,14 @@ public class NamespacePasswordEncoderTests {
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
// @formatter:off
auth
.jdbcAuthentication()
.withDefaultSchema()
.dataSource(dataSource())
.withUser("user").password(encoder.encode("password")).roles("USER").and()
.passwordEncoder(encoder);
// @formatter:on
}
@Bean
@@ -116,9 +120,11 @@ public class NamespacePasswordEncoderTests {
.roles("USER")
.build();
InMemoryUserDetailsManager uds = new InMemoryUserDetailsManager(user);
// @formatter:off
auth
.userDetailsService(uds)
.passwordEncoder(encoder);
// @formatter:on
}
@Bean

View File

@@ -49,15 +49,15 @@ public class PasswordEncoderConfigurerTests {
@EnableWebSecurity
static class PasswordEncoderConfig extends WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
BCryptPasswordEncoder encoder = passwordEncoder();
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password(encoder.encode("password")).roles("USER").and()
.passwordEncoder(encoder);
// @formatter:on
}
// @formatter:on
@Override
protected void configure(HttpSecurity http) {
@@ -80,15 +80,15 @@ public class PasswordEncoderConfigurerTests {
@EnableWebSecurity
static class PasswordEncoderNoAuthManagerLoadsConfig extends
WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
BCryptPasswordEncoder encoder = passwordEncoder();
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password(encoder.encode("password")).roles("USER").and()
.passwordEncoder(encoder);
// @formatter:on
}
// @formatter:on
@Bean
public BCryptPasswordEncoder passwordEncoder() {

View File

@@ -241,9 +241,11 @@ public class AuthenticationConfigurationTests {
static class ConfiguresInMemoryConfigurerAdapter extends GlobalAuthenticationConfigurerAdapter {
public void init(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}

View File

@@ -134,8 +134,10 @@ public class GlobalMethodSecurityConfigurationTests {
public static class InMemoryAuthWithGlobalMethodSecurityConfig extends GlobalMethodSecurityConfiguration {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication();
// @formatter:on
}
@Bean

View File

@@ -74,10 +74,12 @@ public class SampleEnableGlobalMethodSecurityTests {
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
// @formatter:on
}
}
@@ -109,10 +111,12 @@ public class SampleEnableGlobalMethodSecurityTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
// @formatter:on
}
}

View File

@@ -135,9 +135,11 @@ public class SampleWebSecurityConfigurerAdapterTests {
public static class HelloWorldWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}
@@ -233,10 +235,12 @@ public class SampleWebSecurityConfigurerAdapterTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user())
.withUser(PasswordEncodedUser.admin());
// @formatter:on
}
}
@@ -346,10 +350,12 @@ public class SampleWebSecurityConfigurerAdapterTests {
public static class SampleMultiHttpSecurityConfig {
@Autowired
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user())
.withUser(PasswordEncodedUser.admin());
// @formatter:on
}
@Configuration

View File

@@ -146,9 +146,11 @@ public class WebSecurityConfigurerAdapterPowermockTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
@Override

View File

@@ -96,9 +96,11 @@ public class WebSecurityConfigurerAdapterTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
@Override
@@ -125,9 +127,11 @@ public class WebSecurityConfigurerAdapterTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
@Override
@@ -152,9 +156,11 @@ public class WebSecurityConfigurerAdapterTests {
static class InMemoryConfigureProtectedConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
@Override
@@ -180,9 +186,11 @@ public class WebSecurityConfigurerAdapterTests {
static class InMemoryConfigureGlobalConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
@Override
@@ -283,9 +291,11 @@ public class WebSecurityConfigurerAdapterTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}

View File

@@ -75,9 +75,11 @@ public class HttpConfigurationTests {
}
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}

View File

@@ -479,9 +479,11 @@ public class NamespaceHttpTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
}

View File

@@ -79,8 +79,10 @@ public class AuthenticationPrincipalArgumentResolverTests {
static class Config {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication();
// @formatter:off
}
@Bean

View File

@@ -64,9 +64,11 @@ public class EnableWebSecurityTests {
static class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
@Bean

View File

@@ -90,8 +90,10 @@ public class HttpSecurityAntMatchersTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication();
// @formatter:on
}
}
@@ -123,8 +125,10 @@ public class HttpSecurityAntMatchersTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication();
// @formatter:on
}
}

View File

@@ -95,8 +95,10 @@ public class HttpSecurityLogoutTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication();
// @formatter:on
}
}

View File

@@ -77,9 +77,11 @@ public class NamespaceHttpExpressionHandlerTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("rod").password("password").roles("USER", "ADMIN");
// @formatter:on
}
@Override

View File

@@ -147,10 +147,12 @@ public class NamespaceHttpInterceptUrlTests {
}
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
// @formatter:on
}
}

View File

@@ -79,10 +79,12 @@ public class NamespaceHttpPortMappingsTests {
}
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("password").roles("USER", "ADMIN");
// @formatter:on
}
}
}

View File

@@ -78,10 +78,12 @@ public class NamespaceHttpRequestCacheTests {
}
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user())
.withUser(PasswordEncodedUser.admin());
// @formatter:on
}
@Bean
@@ -114,10 +116,12 @@ public class NamespaceHttpRequestCacheTests {
}
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user())
.withUser(PasswordEncodedUser.admin());
// @formatter:on
}
}

View File

@@ -81,9 +81,11 @@ public class NamespaceHttpX509Tests {
public static class X509Config extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("rod").password("password").roles("USER", "ADMIN");
// @formatter:on
}
@Override
@@ -114,9 +116,11 @@ public class NamespaceHttpX509Tests {
static class AuthenticationDetailsSourceRefConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("rod").password("password").roles("USER", "ADMIN");
// @formatter:on
}
@Override
@@ -152,9 +156,11 @@ public class NamespaceHttpX509Tests {
public static class SubjectPrincipalRegexConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("rod").password("password").roles("USER", "ADMIN");
// @formatter:on
}
@Override
@@ -183,9 +189,11 @@ public class NamespaceHttpX509Tests {
public static class CustomPrincipalExtractorConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("rod@example.com").password("password").roles("USER", "ADMIN");
// @formatter:on
}
@Override
@@ -222,9 +230,11 @@ public class NamespaceHttpX509Tests {
public static class UserDetailsServiceRefConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("rod").password("password").roles("USER", "ADMIN");
// @formatter:on
}
@Override

View File

@@ -441,8 +441,10 @@ public class NamespaceRememberMeTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.userDetailsService(USERDETAILS_SERVICE);
// @formatter:on
}
}

View File

@@ -113,14 +113,14 @@ public class SessionManagementConfigurerServlet31Tests {
// @formatter:on
}
// @formatter:off
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
// @formatter:on
}
private void loadConfig(Class<?>... classes) {

View File

@@ -71,13 +71,13 @@ public class SessionManagementConfigurerSessionAuthenticationStrategyTests {
// @formatter:on
}
// @formatter:off
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser(PasswordEncodedUser.user());
// @formatter:on
}
// @formatter:on
}
}

View File

@@ -78,8 +78,10 @@ public class SessionManagementConfigurerTransientAuthenticationTests {
@Override
protected void configure(AuthenticationManagerBuilder auth) {
// @formatter:off
auth
.authenticationProvider(new TransientAuthenticationProvider());
// @formatter:on
}
}

View File

@@ -158,9 +158,11 @@ public class GrantedAuthorityDefaultsJcTests {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
// @formatter:on
}
@Override