Add noformat blocks around http config

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

Issue gh-8945
This commit is contained in:
Phillip Webb 2020-07-23 12:40:37 -07:00 committed by Rob Winch
parent 27ac046d8a
commit 103d822e46
65 changed files with 325 additions and 59 deletions

View File

@ -357,18 +357,18 @@ public abstract class WebSecurityConfigurerAdapter implements
* @param http the {@link HttpSecurity} to modify * @param http the {@link HttpSecurity} to modify
* @throws Exception if an error occurs * @throws Exception if an error occurs
*/ */
// @formatter:off
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
logger.debug("Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity)."); logger.debug("Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity).");
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin().and() .formLogin().and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
// @formatter:on
/** /**
* Gets the ApplicationContext * Gets the ApplicationContext

View File

@ -169,17 +169,17 @@ public final class X509Configurer<H extends HttpSecurityBuilder<H>> extends
return this; return this;
} }
// @formatter:off
@Override @Override
public void init(H http) { public void init(H http) {
PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider(); PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider();
authenticationProvider.setPreAuthenticatedUserDetailsService(getAuthenticationUserDetailsService(http)); authenticationProvider.setPreAuthenticatedUserDetailsService(getAuthenticationUserDetailsService(http));
// @formatter:off
http http
.authenticationProvider(authenticationProvider) .authenticationProvider(authenticationProvider)
.setSharedObject(AuthenticationEntryPoint.class, new Http403ForbiddenEntryPoint()); .setSharedObject(AuthenticationEntryPoint.class, new Http403ForbiddenEntryPoint());
// @formatter:on
} }
// @formatter:on
@Override @Override
public void configure(H http) { public void configure(H http) {

View File

@ -96,16 +96,20 @@ class WebFluxSecurityConfiguration {
* @return * @return
*/ */
private SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { private SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
// @formatter:off
http http
.authorizeExchange() .authorizeExchange()
.anyExchange().authenticated(); .anyExchange().authenticated();
// @formatter:on
if (isOAuth2Present && OAuth2ClasspathGuard.shouldConfigure(this.context)) { if (isOAuth2Present && OAuth2ClasspathGuard.shouldConfigure(this.context)) {
OAuth2ClasspathGuard.configure(this.context, http); OAuth2ClasspathGuard.configure(this.context, http);
} else { } else {
// @formatter:off
http http
.httpBasic().and() .httpBasic().and()
.formLogin(); .formLogin();
// @formatter:on
} }
SecurityWebFilterChain result = http.build(); SecurityWebFilterChain result = http.build();
@ -114,9 +118,11 @@ class WebFluxSecurityConfiguration {
private static class OAuth2ClasspathGuard { private static class OAuth2ClasspathGuard {
static void configure(ApplicationContext context, ServerHttpSecurity http) { static void configure(ApplicationContext context, ServerHttpSecurity http) {
// @formatter:off
http http
.oauth2Login().and() .oauth2Login().and()
.oauth2Client(); .oauth2Client();
// @formatter:on
} }
static boolean shouldConfigure(ApplicationContext context) { static boolean shouldConfigure(ApplicationContext context) {

View File

@ -1812,6 +1812,7 @@ public class ServerHttpSecurity {
private void registerDefaultCsrfOverride(ServerHttpSecurity http) { private void registerDefaultCsrfOverride(ServerHttpSecurity http) {
if ( http.csrf != null && !http.csrf.specifiedRequireCsrfProtectionMatcher ) { if ( http.csrf != null && !http.csrf.specifiedRequireCsrfProtectionMatcher ) {
// @formatter:off
http http
.csrf() .csrf()
.requireCsrfProtectionMatcher( .requireCsrfProtectionMatcher(
@ -1819,6 +1820,7 @@ public class ServerHttpSecurity {
CsrfWebFilter.DEFAULT_CSRF_MATCHER, CsrfWebFilter.DEFAULT_CSRF_MATCHER,
new NegatedServerWebExchangeMatcher( new NegatedServerWebExchangeMatcher(
this.authenticationConverterServerWebExchangeMatcher))); this.authenticationConverterServerWebExchangeMatcher)));
// @formatter:on
} }
} }
@ -1920,8 +1922,10 @@ public class ServerHttpSecurity {
AuthenticationWebFilter oauth2 = new BearerTokenAuthenticationWebFilter(authenticationManager); AuthenticationWebFilter oauth2 = new BearerTokenAuthenticationWebFilter(authenticationManager);
oauth2.setServerAuthenticationConverter(bearerTokenConverter); oauth2.setServerAuthenticationConverter(bearerTokenConverter);
oauth2.setAuthenticationFailureHandler(new ServerAuthenticationEntryPointFailureHandler(entryPoint)); oauth2.setAuthenticationFailureHandler(new ServerAuthenticationEntryPointFailureHandler(entryPoint));
// @formatter:off
http http
.addFilterAt(oauth2, SecurityWebFiltersOrder.AUTHENTICATION); .addFilterAt(oauth2, SecurityWebFiltersOrder.AUTHENTICATION);
// @formatter:on
} }
protected ReactiveJwtDecoder getJwtDecoder() { protected ReactiveJwtDecoder getJwtDecoder() {

View File

@ -45,22 +45,22 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
private UserRepository myUserRepository; private UserRepository myUserRepository;
// @formatter:off
@Override @Override
protected void configure(AuthenticationManagerBuilder auth) { protected void configure(AuthenticationManagerBuilder auth) {
// @formatter:off
auth auth
.authenticationProvider(authenticationProvider()); .authenticationProvider(authenticationProvider());
// @formatter:on
} }
// @formatter:on
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/*").permitAll(); .antMatchers("/*").permitAll();
// @formatter:on
} }
// @formatter:on
@Bean @Bean
@Override @Override

View File

@ -96,9 +96,11 @@ public class Sec2758Tests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().access("hasAnyRole('CUSTOM')"); .anyRequest().access("hasAnyRole('CUSTOM')");
// @formatter:on
} }
@Bean @Bean

View File

@ -35,10 +35,12 @@ public class AbstractRequestMatcherRegistryAnyMatcherTests{
@EnableWebSecurity @EnableWebSecurity
static class AntMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter { static class AntMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.antMatchers("/demo/**").permitAll(); .antMatchers("/demo/**").permitAll();
// @formatter:on
} }
} }
@ -51,10 +53,12 @@ public class AbstractRequestMatcherRegistryAnyMatcherTests{
@EnableWebSecurity @EnableWebSecurity
static class MvcMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter { static class MvcMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.mvcMatchers("/demo/**").permitAll(); .mvcMatchers("/demo/**").permitAll();
// @formatter:on
} }
} }
@ -67,10 +71,12 @@ public class AbstractRequestMatcherRegistryAnyMatcherTests{
@EnableWebSecurity @EnableWebSecurity
static class RegexMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter { static class RegexMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.regexMatchers(".*").permitAll(); .regexMatchers(".*").permitAll();
// @formatter:on
} }
} }
@ -83,10 +89,12 @@ public class AbstractRequestMatcherRegistryAnyMatcherTests{
@EnableWebSecurity @EnableWebSecurity
static class AnyRequestAfterItselfConfig extends WebSecurityConfigurerAdapter { static class AnyRequestAfterItselfConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.anyRequest().permitAll(); .anyRequest().permitAll();
// @formatter:on
} }
} }
@ -99,10 +107,12 @@ public class AbstractRequestMatcherRegistryAnyMatcherTests{
@EnableWebSecurity @EnableWebSecurity
static class RequestMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter { static class RequestMatchersAfterAnyRequestConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.requestMatchers(new AntPathRequestMatcher("/**")).permitAll(); .requestMatchers(new AntPathRequestMatcher("/**")).permitAll();
// @formatter:on
} }
} }

View File

@ -218,6 +218,7 @@ public class SampleWebSecurityConfigurerAdapterTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/signup", "/about").permitAll() .antMatchers("/signup", "/about").permitAll()
@ -227,6 +228,7 @@ public class SampleWebSecurityConfigurerAdapterTests {
.loginPage("/login") .loginPage("/login")
// set permitAll for all URLs associated with Form Login // set permitAll for all URLs associated with Form Login
.permitAll(); .permitAll();
// @formatter:on
} }
@Override @Override
@ -354,6 +356,7 @@ public class SampleWebSecurityConfigurerAdapterTests {
@Order(1) @Order(1)
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.antMatcher("/api/**") .antMatcher("/api/**")
.authorizeRequests() .authorizeRequests()
@ -361,6 +364,7 @@ public class SampleWebSecurityConfigurerAdapterTests {
.antMatchers("/api/**").hasRole("USER") .antMatchers("/api/**").hasRole("USER")
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
} }
@ -375,6 +379,7 @@ public class SampleWebSecurityConfigurerAdapterTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/signup", "/about").permitAll() .antMatchers("/signup", "/about").permitAll()
@ -383,6 +388,7 @@ public class SampleWebSecurityConfigurerAdapterTests {
.formLogin() .formLogin()
.loginPage("/login") .loginPage("/login")
.permitAll(); .permitAll();
// @formatter:on
} }
} }
} }

View File

@ -68,8 +68,10 @@ public class HttpConfigurationTests {
static class UnregisteredFilterConfig extends WebSecurityConfigurerAdapter { static class UnregisteredFilterConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
.addFilter(new UnregisteredFilter()); .addFilter(new UnregisteredFilter());
// @formatter:on
} }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {
@ -105,8 +107,10 @@ public class HttpConfigurationTests {
static CasAuthenticationFilter CAS_AUTHENTICATION_FILTER; static CasAuthenticationFilter CAS_AUTHENTICATION_FILTER;
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
.addFilter(CAS_AUTHENTICATION_FILTER); .addFilter(CAS_AUTHENTICATION_FILTER);
// @formatter:on
} }
} }
@ -124,6 +128,7 @@ public class HttpConfigurationTests {
static class RequestMatcherRegistryConfigs extends WebSecurityConfigurerAdapter { static class RequestMatcherRegistryConfigs extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.requestMatchers() .requestMatchers()
.antMatchers("/api/**") .antMatchers("/api/**")
@ -133,6 +138,7 @@ public class HttpConfigurationTests {
.antMatchers("/**").hasRole("USER") .antMatchers("/**").hasRole("USER")
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
} }
} }

View File

@ -94,10 +94,12 @@ public class NamespaceHttpTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().permitAll() .anyRequest().permitAll()
.accessDecisionManager(ACCESS_DECISION_MANAGER); .accessDecisionManager(ACCESS_DECISION_MANAGER);
// @formatter:on
} }
} }
@ -114,6 +116,7 @@ public class NamespaceHttpTests {
static class AccessDeniedPageConfig extends WebSecurityConfigurerAdapter { static class AccessDeniedPageConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin").hasRole("ADMIN") .antMatchers("/admin").hasRole("ADMIN")
@ -121,6 +124,7 @@ public class NamespaceHttpTests {
.and() .and()
.exceptionHandling() .exceptionHandling()
.accessDeniedPage("/AccessDeniedPage"); .accessDeniedPage("/AccessDeniedPage");
// @formatter:on
} }
} }
@ -145,11 +149,13 @@ public class NamespaceHttpTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
} }
@ -168,12 +174,14 @@ public class NamespaceHttpTests {
static class CreateSessionAlwaysConfig extends WebSecurityConfigurerAdapter { static class CreateSessionAlwaysConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().permitAll() .anyRequest().permitAll()
.and() .and()
.sessionManagement() .sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.ALWAYS); .sessionCreationPolicy(SessionCreationPolicy.ALWAYS);
// @formatter:on
} }
} }
@ -191,12 +199,14 @@ public class NamespaceHttpTests {
static class CreateSessionStatelessConfig extends WebSecurityConfigurerAdapter { static class CreateSessionStatelessConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().permitAll() .anyRequest().permitAll()
.and() .and()
.sessionManagement() .sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// @formatter:on
} }
} }
@ -220,6 +230,7 @@ public class NamespaceHttpTests {
static class IfRequiredConfig extends WebSecurityConfigurerAdapter { static class IfRequiredConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/unsecure").permitAll() .antMatchers("/unsecure").permitAll()
@ -229,6 +240,7 @@ public class NamespaceHttpTests {
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
} }
@ -246,12 +258,14 @@ public class NamespaceHttpTests {
static class CreateSessionNeverConfig extends WebSecurityConfigurerAdapter { static class CreateSessionNeverConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().anonymous() .anyRequest().anonymous()
.and() .and()
.sessionManagement() .sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.NEVER); .sessionCreationPolicy(SessionCreationPolicy.NEVER);
// @formatter:on
} }
} }
@ -268,6 +282,7 @@ public class NamespaceHttpTests {
static class EntryPointRefConfig extends WebSecurityConfigurerAdapter { static class EntryPointRefConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -276,6 +291,7 @@ public class NamespaceHttpTests {
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/entry-point")) .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/entry-point"))
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
} }
@ -299,8 +315,10 @@ public class NamespaceHttpTests {
static class JaasApiProvisionConfig extends WebSecurityConfigurerAdapter { static class JaasApiProvisionConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
.addFilter(new JaasApiIntegrationFilter()); .addFilter(new JaasApiIntegrationFilter());
// @formatter:on
} }
} }
@ -317,12 +335,14 @@ public class NamespaceHttpTests {
static class RealmConfig extends WebSecurityConfigurerAdapter { static class RealmConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.httpBasic() .httpBasic()
.realmName("RealmConfig"); .realmName("RealmConfig");
// @formatter:on
} }
} }
@ -341,8 +361,10 @@ public class NamespaceHttpTests {
static class RequestMatcherAntConfig extends WebSecurityConfigurerAdapter { static class RequestMatcherAntConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
.antMatcher("/api/**"); .antMatcher("/api/**");
// @formatter:on
} }
} }
@ -361,8 +383,10 @@ public class NamespaceHttpTests {
static class RequestMatcherRegexConfig extends WebSecurityConfigurerAdapter { static class RequestMatcherRegexConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
.regexMatcher("/regex/.*"); .regexMatcher("/regex/.*");
// @formatter:on
} }
} }
@ -381,8 +405,10 @@ public class NamespaceHttpTests {
static class RequestMatcherRefConfig extends WebSecurityConfigurerAdapter { static class RequestMatcherRefConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
.requestMatcher(new MyRequestMatcher()); .requestMatcher(new MyRequestMatcher());
// @formatter:on
} }
static class MyRequestMatcher implements RequestMatcher { static class MyRequestMatcher implements RequestMatcher {
@ -439,6 +465,7 @@ public class NamespaceHttpTests {
static class SecurityContextRepoConfig extends WebSecurityConfigurerAdapter { static class SecurityContextRepoConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -447,6 +474,7 @@ public class NamespaceHttpTests {
.securityContextRepository(new NullSecurityContextRepository()) .securityContextRepository(new NullSecurityContextRepository())
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
@Override @Override
@ -470,12 +498,14 @@ public class NamespaceHttpTests {
static class ServletApiProvisionConfig extends WebSecurityConfigurerAdapter { static class ServletApiProvisionConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().permitAll() .anyRequest().permitAll()
.and() .and()
.servletApi() .servletApi()
.disable(); .disable();
// @formatter:on
} }
} }
@ -492,9 +522,11 @@ public class NamespaceHttpTests {
static class ServletApiProvisionDefaultsConfig extends WebSecurityConfigurerAdapter { static class ServletApiProvisionDefaultsConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().permitAll(); .anyRequest().permitAll();
// @formatter:on
} }
} }
@ -525,11 +557,13 @@ public class NamespaceHttpTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/users**", "/sessions/**").hasRole("USER") .antMatchers("/users**", "/sessions/**").hasRole("USER")
.antMatchers("/signup").permitAll() .antMatchers("/signup").permitAll()
.anyRequest().hasRole("USER"); .anyRequest().hasRole("USER");
// @formatter:on
} }
@Override @Override
@ -560,11 +594,13 @@ public class NamespaceHttpTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.apply(new UrlAuthorizationConfigurer<>(getApplicationContext())).getRegistry() .apply(new UrlAuthorizationConfigurer<>(getApplicationContext())).getRegistry()
.antMatchers("/users**", "/sessions/**").hasRole("USER") .antMatchers("/users**", "/sessions/**").hasRole("USER")
.antMatchers("/signup").hasRole("ANONYMOUS") .antMatchers("/signup").hasRole("ANONYMOUS")
.anyRequest().hasRole("USER"); .anyRequest().hasRole("USER");
// @formatter:on
} }
@Override @Override

View File

@ -77,11 +77,13 @@ public class EnableWebSecurityTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/*").hasRole("USER") .antMatchers("/*").hasRole("USER")
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
} }

View File

@ -127,10 +127,12 @@ public class WebSecurityConfigurationTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.antMatcher("/role1/**") .antMatcher("/role1/**")
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("1"); .anyRequest().hasRole("1");
// @formatter:on
} }
} }
@ -139,10 +141,12 @@ public class WebSecurityConfigurationTests {
static class WebConfigurer2 extends WebSecurityConfigurerAdapter { static class WebConfigurer2 extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.antMatcher("/role2/**") .antMatcher("/role2/**")
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("2"); .anyRequest().hasRole("2");
// @formatter:on
} }
} }
@ -151,10 +155,12 @@ public class WebSecurityConfigurationTests {
static class WebConfigurer3 extends WebSecurityConfigurerAdapter { static class WebConfigurer3 extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.antMatcher("/role3/**") .antMatcher("/role3/**")
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("3"); .anyRequest().hasRole("3");
// @formatter:on
} }
} }
@ -163,9 +169,11 @@ public class WebSecurityConfigurationTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("4"); .anyRequest().hasRole("4");
// @formatter:on
} }
} }
} }
@ -258,10 +266,12 @@ public class WebSecurityConfigurationTests {
static class WebConfigurer1 extends WebSecurityConfigurerAdapter { static class WebConfigurer1 extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.antMatcher("/role1/**") .antMatcher("/role1/**")
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("1"); .anyRequest().hasRole("1");
// @formatter:on
} }
} }
@ -269,10 +279,12 @@ public class WebSecurityConfigurationTests {
static class WebConfigurer2 extends WebSecurityConfigurerAdapter { static class WebConfigurer2 extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.antMatcher("/role2/**") .antMatcher("/role2/**")
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("2"); .anyRequest().hasRole("2");
// @formatter:on
} }
} }
} }
@ -319,10 +331,12 @@ public class WebSecurityConfigurationTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.expressionHandler(EXPRESSION_HANDLER); .expressionHandler(EXPRESSION_HANDLER);
// @formatter:on
} }
} }
@ -357,9 +371,11 @@ public class WebSecurityConfigurationTests {
static class WebSecurityExpressionHandlerDefaultsConfig extends WebSecurityConfigurerAdapter { static class WebSecurityExpressionHandlerDefaultsConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated(); .anyRequest().authenticated();
// @formatter:on
} }
} }
@ -436,9 +452,11 @@ public class WebSecurityConfigurationTests {
static class WebInvocationPrivilegeEvaluatorDefaultsConfig extends WebSecurityConfigurerAdapter { static class WebInvocationPrivilegeEvaluatorDefaultsConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated(); .anyRequest().authenticated();
// @formatter:on
} }
} }
@ -475,9 +493,11 @@ public class WebSecurityConfigurationTests {
static class DefaultExpressionHandlerSetsBeanResolverConfig extends WebSecurityConfigurerAdapter { static class DefaultExpressionHandlerSetsBeanResolverConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().access("request.method == 'GET' ? @b.grant() : @b.deny()"); .anyRequest().access("request.method == 'GET' ? @b.grant() : @b.deny()");
// @formatter:on
} }
@RestController @RestController
@ -571,10 +591,12 @@ public class WebSecurityConfigurationTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.antMatcher("/anonymous/**") .antMatcher("/anonymous/**")
.authorizeRequests() .authorizeRequests()
.anyRequest().anonymous(); .anyRequest().anonymous();
// @formatter:on
} }
} }
@ -583,9 +605,11 @@ public class WebSecurityConfigurationTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated(); .anyRequest().authenticated();
// @formatter:on
} }
} }
} }

View File

@ -60,12 +60,14 @@ public class AnonymousConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.anonymous() .anonymous()
.key("key") .key("key")
.principal("principal") .principal("principal")
.and() .and()
.anonymous(); .anonymous();
// @formatter:on
} }
} }

View File

@ -83,10 +83,12 @@ public class FormLoginConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.formLogin().and() .formLogin().and()
.requestCache() .requestCache()
.requestCache(this.requestCache); .requestCache(this.requestCache);
// @formatter:on
} }
} }

View File

@ -78,12 +78,14 @@ public class HttpSecurityAntMatchersTests {
@Configuration @Configuration
static class AntMatchersNoPatternsConfig extends WebSecurityConfigurerAdapter { static class AntMatchersNoPatternsConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.requestMatchers() .requestMatchers()
.antMatchers(HttpMethod.POST) .antMatchers(HttpMethod.POST)
.and() .and()
.authorizeRequests() .authorizeRequests()
.anyRequest().denyAll(); .anyRequest().denyAll();
// @formatter:on
} }
@Override @Override
@ -108,6 +110,7 @@ public class HttpSecurityAntMatchersTests {
@Configuration @Configuration
static class AntMatchersEmptyPatternsConfig extends WebSecurityConfigurerAdapter { static class AntMatchersEmptyPatternsConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.requestMatchers() .requestMatchers()
.antMatchers("/never/") .antMatchers("/never/")
@ -115,6 +118,7 @@ public class HttpSecurityAntMatchersTests {
.and() .and()
.authorizeRequests() .authorizeRequests()
.anyRequest().denyAll(); .anyRequest().denyAll();
// @formatter:on
} }
@Override @Override

View File

@ -85,10 +85,12 @@ public class HttpSecurityLogoutTests {
@Configuration @Configuration
static class ClearAuthenticationFalseConfig extends WebSecurityConfigurerAdapter { static class ClearAuthenticationFalseConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.csrf().disable() .csrf().disable()
.logout() .logout()
.clearAuthentication(false); .clearAuthentication(false);
// @formatter:on
} }
@Override @Override

View File

@ -97,9 +97,11 @@ public class LogoutConfigurerClearSiteDataTests {
static class HttpLogoutConfig extends WebSecurityConfigurerAdapter { static class HttpLogoutConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.logout() .logout()
.addLogoutHandler(new HeaderWriterLogoutHandler(new ClearSiteDataHeaderWriter(SOURCE))); .addLogoutHandler(new HeaderWriterLogoutHandler(new ClearSiteDataHeaderWriter(SOURCE)));
// @formatter:on
} }
} }
} }

View File

@ -95,11 +95,13 @@ public class NamespaceHttpBasicTests {
@EnableWebSecurity @EnableWebSecurity
static class HttpBasicConfig extends WebSecurityConfigurerAdapter { static class HttpBasicConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
} }
@ -151,11 +153,13 @@ public class NamespaceHttpBasicTests {
static class CustomHttpBasicConfig extends WebSecurityConfigurerAdapter { static class CustomHttpBasicConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.httpBasic().realmName("Custom Realm"); .httpBasic().realmName("Custom Realm");
// @formatter:on
} }
} }
@ -207,9 +211,11 @@ public class NamespaceHttpBasicTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.httpBasic() .httpBasic()
.authenticationDetailsSource(this.authenticationDetailsSource); .authenticationDetailsSource(this.authenticationDetailsSource);
// @formatter:on
} }
@Bean @Bean
@ -278,12 +284,14 @@ public class NamespaceHttpBasicTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.httpBasic() .httpBasic()
.authenticationEntryPoint(this.authenticationEntryPoint); .authenticationEntryPoint(this.authenticationEntryPoint);
// @formatter:on
} }
} }

View File

@ -67,9 +67,11 @@ public class NamespaceHttpCustomFilterTests {
@EnableWebSecurity @EnableWebSecurity
static class CustomFilterBeforeConfig extends WebSecurityConfigurerAdapter { static class CustomFilterBeforeConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.addFilterBefore(new CustomFilter(), UsernamePasswordAuthenticationFilter.class) .addFilterBefore(new CustomFilter(), UsernamePasswordAuthenticationFilter.class)
.formLogin(); .formLogin();
// @formatter:on
} }
} }
@ -82,9 +84,11 @@ public class NamespaceHttpCustomFilterTests {
@EnableWebSecurity @EnableWebSecurity
static class CustomFilterAfterConfig extends WebSecurityConfigurerAdapter { static class CustomFilterAfterConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.addFilterAfter(new CustomFilter(), UsernamePasswordAuthenticationFilter.class) .addFilterAfter(new CustomFilter(), UsernamePasswordAuthenticationFilter.class)
.formLogin(); .formLogin();
// @formatter:on
} }
} }
@ -102,10 +106,12 @@ public class NamespaceHttpCustomFilterTests {
} }
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
// this works so long as the CustomFilter extends one of the standard filters // this works so long as the CustomFilter extends one of the standard filters
// if not, use addFilterBefore or addFilterAfter // if not, use addFilterBefore or addFilterAfter
.addFilter(new CustomFilter()); .addFilter(new CustomFilter());
// @formatter:on
} }
} }
@ -124,8 +130,10 @@ public class NamespaceHttpCustomFilterTests {
} }
protected void configure(HttpSecurity http) { protected void configure(HttpSecurity http) {
// @formatter:off
http http
.addFilterAt(new OtherCustomFilter(), UsernamePasswordAuthenticationFilter.class); .addFilterAt(new OtherCustomFilter(), UsernamePasswordAuthenticationFilter.class);
// @formatter:on
} }
} }
@ -147,11 +155,13 @@ public class NamespaceHttpCustomFilterTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.addFilterBefore(new CustomFilter(), UsernamePasswordAuthenticationFilter.class); .addFilterBefore(new CustomFilter(), UsernamePasswordAuthenticationFilter.class);
// @formatter:on
} }
} }

View File

@ -86,11 +86,12 @@ public class NamespaceHttpExpressionHandlerTests {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler(); DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
handler.setExpressionParser(expressionParser()); handler.setExpressionParser(expressionParser());
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.expressionHandler(handler) .expressionHandler(handler)
.anyRequest().access("hasRole('USER')"); .anyRequest().access("hasRole('USER')");
// @formatter:on
} }
@Bean @Bean

View File

@ -90,11 +90,13 @@ public class NamespaceHttpFormLoginTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
} }
@ -120,6 +122,7 @@ public class NamespaceHttpFormLoginTests {
static class FormLoginCustomConfig extends WebSecurityConfigurerAdapter { static class FormLoginCustomConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
boolean alwaysUseDefaultSuccess = true; boolean alwaysUseDefaultSuccess = true;
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
@ -131,6 +134,7 @@ public class NamespaceHttpFormLoginTests {
.failureUrl("/authentication/login?failed") // form-login@authentication-failure-url .failureUrl("/authentication/login?failed") // form-login@authentication-failure-url
.loginProcessingUrl("/authentication/login/process") // form-login@login-processing-url .loginProcessingUrl("/authentication/login/process") // form-login@login-processing-url
.defaultSuccessUrl("/default", alwaysUseDefaultSuccess); // form-login@default-target-url / form-login@always-use-default-target .defaultSuccessUrl("/default", alwaysUseDefaultSuccess); // form-login@default-target-url / form-login@always-use-default-target
// @formatter:on
} }
} }
@ -159,7 +163,7 @@ public class NamespaceHttpFormLoginTests {
SavedRequestAwareAuthenticationSuccessHandler successHandler = SavedRequestAwareAuthenticationSuccessHandler successHandler =
new SavedRequestAwareAuthenticationSuccessHandler(); new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setDefaultTargetUrl("/custom/targetUrl"); successHandler.setDefaultTargetUrl("/custom/targetUrl");
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
@ -170,6 +174,7 @@ public class NamespaceHttpFormLoginTests {
.successHandler(successHandler) // form-login@authentication-success-handler-ref .successHandler(successHandler) // form-login@authentication-success-handler-ref
.authenticationDetailsSource(authenticationDetailsSource()) // form-login@authentication-details-source-ref .authenticationDetailsSource(authenticationDetailsSource()) // form-login@authentication-details-source-ref
.and(); .and();
// @formatter:on
} }
@Bean @Bean

View File

@ -77,8 +77,10 @@ public class NamespaceHttpHeadersTests {
static class HeadersDefaultConfig extends WebSecurityConfigurerAdapter { static class HeadersDefaultConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers(); .headers();
// @formatter:on
} }
} }
@ -94,10 +96,12 @@ public class NamespaceHttpHeadersTests {
static class HeadersCacheControlConfig extends WebSecurityConfigurerAdapter { static class HeadersCacheControlConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
.defaultsDisabled() .defaultsDisabled()
.cacheControl(); .cacheControl();
// @formatter:on
} }
} }
@ -113,10 +117,12 @@ public class NamespaceHttpHeadersTests {
static class HstsConfig extends WebSecurityConfigurerAdapter { static class HstsConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
.defaultsDisabled() .defaultsDisabled()
.httpStrictTransportSecurity(); .httpStrictTransportSecurity();
// @formatter:on
} }
} }
@ -132,6 +138,7 @@ public class NamespaceHttpHeadersTests {
static class HstsCustomConfig extends WebSecurityConfigurerAdapter { static class HstsCustomConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
// hsts@request-matcher-ref, hsts@max-age-seconds, hsts@include-subdomains // hsts@request-matcher-ref, hsts@max-age-seconds, hsts@include-subdomains
@ -140,6 +147,7 @@ public class NamespaceHttpHeadersTests {
.requestMatcher(AnyRequestMatcher.INSTANCE) .requestMatcher(AnyRequestMatcher.INSTANCE)
.maxAgeInSeconds(15768000) .maxAgeInSeconds(15768000)
.includeSubDomains(false); .includeSubDomains(false);
// @formatter:on
} }
} }
@ -155,12 +163,14 @@ public class NamespaceHttpHeadersTests {
static class FrameOptionsSameOriginConfig extends WebSecurityConfigurerAdapter { static class FrameOptionsSameOriginConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
// frame-options@policy=SAMEORIGIN // frame-options@policy=SAMEORIGIN
.defaultsDisabled() .defaultsDisabled()
.frameOptions() .frameOptions()
.sameOrigin(); .sameOrigin();
// @formatter:on
} }
} }
@ -178,12 +188,14 @@ public class NamespaceHttpHeadersTests {
static class FrameOptionsAllowFromConfig extends WebSecurityConfigurerAdapter { static class FrameOptionsAllowFromConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
// frame-options@ref // frame-options@ref
.defaultsDisabled() .defaultsDisabled()
.addHeaderWriter(new XFrameOptionsHeaderWriter( .addHeaderWriter(new XFrameOptionsHeaderWriter(
new StaticAllowFromStrategy(URI.create("https://example.com")))); new StaticAllowFromStrategy(URI.create("https://example.com"))));
// @formatter:on
} }
} }
@ -199,11 +211,13 @@ public class NamespaceHttpHeadersTests {
static class XssProtectionConfig extends WebSecurityConfigurerAdapter { static class XssProtectionConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
// xss-protection // xss-protection
.defaultsDisabled() .defaultsDisabled()
.xssProtection(); .xssProtection();
// @formatter:on
} }
} }
@ -219,6 +233,7 @@ public class NamespaceHttpHeadersTests {
static class XssProtectionCustomConfig extends WebSecurityConfigurerAdapter { static class XssProtectionCustomConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
// xss-protection@enabled and xss-protection@block // xss-protection@enabled and xss-protection@block
@ -226,6 +241,7 @@ public class NamespaceHttpHeadersTests {
.xssProtection() .xssProtection()
.xssProtectionEnabled(true) .xssProtectionEnabled(true)
.block(false); .block(false);
// @formatter:on
} }
} }
@ -241,11 +257,13 @@ public class NamespaceHttpHeadersTests {
static class ContentTypeOptionsConfig extends WebSecurityConfigurerAdapter { static class ContentTypeOptionsConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
// content-type-options // content-type-options
.defaultsDisabled() .defaultsDisabled()
.contentTypeOptions(); .contentTypeOptions();
// @formatter:on
} }
} }
@ -263,10 +281,12 @@ public class NamespaceHttpHeadersTests {
static class HeaderRefConfig extends WebSecurityConfigurerAdapter { static class HeaderRefConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.headers() .headers()
.defaultsDisabled() .defaultsDisabled()
.addHeaderWriter(new StaticHeadersWriter("customHeaderName", "customHeaderValue")); .addHeaderWriter(new StaticHeadersWriter("customHeaderName", "customHeaderValue"));
// @formatter:on
} }
} }

View File

@ -120,6 +120,7 @@ public class NamespaceHttpInterceptUrlTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
// the line below is similar to intercept-url@pattern: // the line below is similar to intercept-url@pattern:
@ -142,6 +143,7 @@ public class NamespaceHttpInterceptUrlTests {
// the line below is similar to intercept-url@requires-channel="http": // the line below is similar to intercept-url@requires-channel="http":
// <intercept-url pattern="/**" requires-channel="http"/> // <intercept-url pattern="/**" requires-channel="http"/>
.anyRequest().requiresInsecure(); .anyRequest().requiresInsecure();
// @formatter:on
} }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {

View File

@ -83,12 +83,14 @@ public class NamespaceHttpJeeTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("user") .anyRequest().hasRole("user")
.and() .and()
.jee() .jee()
.mappableRoles("user", "admin"); .mappableRoles("user", "admin");
// @formatter:on
} }
} }
@ -120,6 +122,7 @@ public class NamespaceHttpJeeTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("user") .anyRequest().hasRole("user")
@ -127,6 +130,7 @@ public class NamespaceHttpJeeTests {
.jee() .jee()
.mappableAuthorities("ROLE_user", "ROLE_admin") .mappableAuthorities("ROLE_user", "ROLE_admin")
.authenticatedUserDetailsService(this.authenticationUserDetailsService); .authenticatedUserDetailsService(this.authenticationUserDetailsService);
// @formatter:on
} }
@Bean @Bean

View File

@ -122,12 +122,14 @@ public class NamespaceHttpLogoutTests {
static class CustomHttpLogoutConfig extends WebSecurityConfigurerAdapter { static class CustomHttpLogoutConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.logout() .logout()
.deleteCookies("remove") // logout@delete-cookies .deleteCookies("remove") // logout@delete-cookies
.invalidateHttpSession(false) // logout@invalidate-session=false (default is true) .invalidateHttpSession(false) // logout@invalidate-session=false (default is true)
.logoutUrl("/custom-logout") // logout@logout-url (default is /logout) .logoutUrl("/custom-logout") // logout@logout-url (default is /logout)
.logoutSuccessUrl("/logout-success"); // logout@success-url (default is /login?logout) .logoutSuccessUrl("/logout-success"); // logout@success-url (default is /login?logout)
// @formatter:on
} }
} }
@ -182,10 +184,11 @@ public class NamespaceHttpLogoutTests {
SimpleUrlLogoutSuccessHandler logoutSuccessHandler = SimpleUrlLogoutSuccessHandler logoutSuccessHandler =
new SimpleUrlLogoutSuccessHandler(); new SimpleUrlLogoutSuccessHandler();
logoutSuccessHandler.setDefaultTargetUrl("/SuccessHandlerRefHttpLogoutConfig"); logoutSuccessHandler.setDefaultTargetUrl("/SuccessHandlerRefHttpLogoutConfig");
// @formatter:off
http http
.logout() .logout()
.logoutSuccessHandler(logoutSuccessHandler); .logoutSuccessHandler(logoutSuccessHandler);
// @formatter:on
} }
} }

View File

@ -97,12 +97,14 @@ public class NamespaceHttpOpenIDLoginTests {
static class OpenIDLoginConfig extends WebSecurityConfigurerAdapter { static class OpenIDLoginConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.openidLogin() .openidLogin()
.permitAll(); .permitAll();
// @formatter:on
} }
} }
@ -159,6 +161,7 @@ public class NamespaceHttpOpenIDLoginTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
@ -191,6 +194,7 @@ public class NamespaceHttpOpenIDLoginTests {
.and() .and()
.and() .and()
.permitAll(); .permitAll();
// @formatter:on
} }
} }
@ -209,6 +213,7 @@ public class NamespaceHttpOpenIDLoginTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
boolean alwaysUseDefaultSuccess = true; boolean alwaysUseDefaultSuccess = true;
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
@ -219,6 +224,7 @@ public class NamespaceHttpOpenIDLoginTests {
.failureUrl("/authentication/login?failed") // openid-login@authentication-failure-url .failureUrl("/authentication/login?failed") // openid-login@authentication-failure-url
.loginProcessingUrl("/authentication/login/process") // openid-login@login-processing-url .loginProcessingUrl("/authentication/login/process") // openid-login@login-processing-url
.defaultSuccessUrl("/default", alwaysUseDefaultSuccess); // openid-login@default-target-url / openid-login@always-use-default-target .defaultSuccessUrl("/default", alwaysUseDefaultSuccess); // openid-login@default-target-url / openid-login@always-use-default-target
// @formatter:on
} }
} }
@ -267,7 +273,7 @@ public class NamespaceHttpOpenIDLoginTests {
SavedRequestAwareAuthenticationSuccessHandler handler = SavedRequestAwareAuthenticationSuccessHandler handler =
new SavedRequestAwareAuthenticationSuccessHandler(); new SavedRequestAwareAuthenticationSuccessHandler();
handler.setDefaultTargetUrl("/custom/targetUrl"); handler.setDefaultTargetUrl("/custom/targetUrl");
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
@ -285,7 +291,7 @@ public class NamespaceHttpOpenIDLoginTests {
return filter; return filter;
} }
}); });
// @formatter:on
} }
} }

View File

@ -64,6 +64,7 @@ public class NamespaceHttpPortMappingsTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
@ -74,6 +75,7 @@ public class NamespaceHttpPortMappingsTests {
.requiresChannel() .requiresChannel()
.antMatchers("/login", "/secured/**").requiresSecure() .antMatchers("/login", "/secured/**").requiresSecure()
.anyRequest().requiresInsecure(); .anyRequest().requiresInsecure();
// @formatter:on
} }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {

View File

@ -67,12 +67,14 @@ public class NamespaceHttpRequestCacheTests {
@EnableWebSecurity @EnableWebSecurity
static class RequestCacheRefConfig extends WebSecurityConfigurerAdapter { static class RequestCacheRefConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.requestCache() .requestCache()
.requestCache(requestCache()); .requestCache(requestCache());
// @formatter:on
} }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {
@ -104,9 +106,11 @@ public class NamespaceHttpRequestCacheTests {
@EnableWebSecurity @EnableWebSecurity
static class DefaultRequestCacheRefConfig extends WebSecurityConfigurerAdapter { static class DefaultRequestCacheRefConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated(); .anyRequest().authenticated();
// @formatter:on
} }
protected void configure(AuthenticationManagerBuilder auth) throws Exception { protected void configure(AuthenticationManagerBuilder auth) throws Exception {

View File

@ -70,12 +70,14 @@ public class NamespaceHttpServerAccessDeniedHandlerTests {
@EnableWebSecurity @EnableWebSecurity
static class AccessDeniedPageConfig extends WebSecurityConfigurerAdapter { static class AccessDeniedPageConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().denyAll() .anyRequest().denyAll()
.and() .and()
.exceptionHandling() .exceptionHandling()
.accessDeniedPage("/AccessDeniedPageConfig"); .accessDeniedPage("/AccessDeniedPageConfig");
// @formatter:on
} }
} }
@ -121,12 +123,14 @@ public class NamespaceHttpServerAccessDeniedHandlerTests {
@EnableWebSecurity @EnableWebSecurity
static class AccessDeniedHandlerRefConfig extends WebSecurityConfigurerAdapter { static class AccessDeniedHandlerRefConfig extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().denyAll() .anyRequest().denyAll()
.and() .and()
.exceptionHandling() .exceptionHandling()
.accessDeniedHandler(accessDeniedHandler()); .accessDeniedHandler(accessDeniedHandler());
// @formatter:on
} }
@Bean @Bean

View File

@ -88,11 +88,13 @@ public class NamespaceHttpX509Tests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.x509(); .x509();
// @formatter:on
} }
} }
@ -119,12 +121,14 @@ public class NamespaceHttpX509Tests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.x509() .x509()
.authenticationDetailsSource(authenticationDetailsSource()); .authenticationDetailsSource(authenticationDetailsSource());
// @formatter:on
} }
@Bean @Bean
@ -155,12 +159,14 @@ public class NamespaceHttpX509Tests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.x509() .x509()
.subjectPrincipalRegex("CN=(.*?)@example.com(?:,|$)"); .subjectPrincipalRegex("CN=(.*?)@example.com(?:,|$)");
// @formatter:on
} }
} }
@ -184,12 +190,14 @@ public class NamespaceHttpX509Tests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.x509() .x509()
.x509PrincipalExtractor(this::extractCommonName); .x509PrincipalExtractor(this::extractCommonName);
// @formatter:on
} }
private String extractCommonName(X509Certificate certificate) { private String extractCommonName(X509Certificate certificate) {
@ -221,12 +229,14 @@ public class NamespaceHttpX509Tests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.x509() .x509()
.userDetailsService(username -> USER); .userDetailsService(username -> USER);
// @formatter:on
} }
} }
@ -248,12 +258,14 @@ public class NamespaceHttpX509Tests {
} }
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().hasRole("USER") .anyRequest().hasRole("USER")
.and() .and()
.x509() .x509()
.authenticationUserDetailsService(authentication -> USER); .authenticationUserDetailsService(authentication -> USER);
// @formatter:on
} }
} }

View File

@ -174,6 +174,7 @@ public class NamespaceSessionManagementTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -187,6 +188,7 @@ public class NamespaceSessionManagementTests {
.maxSessionsPreventsLogin(true) // session-management/concurrency-control@error-if-maximum-exceeded .maxSessionsPreventsLogin(true) // session-management/concurrency-control@error-if-maximum-exceeded
.expiredUrl("/expired-session") // session-management/concurrency-control@expired-url .expiredUrl("/expired-session") // session-management/concurrency-control@expired-url
.sessionRegistry(sessionRegistry()); // session-management/concurrency-control@session-registry-ref .sessionRegistry(sessionRegistry()); // session-management/concurrency-control@session-registry-ref
// @formatter:on
} }
@Bean @Bean
@ -219,9 +221,11 @@ public class NamespaceSessionManagementTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.invalidSessionStrategy(invalidSessionStrategy()); .invalidSessionStrategy(invalidSessionStrategy());
// @formatter:on
} }
@Bean @Bean
@ -250,11 +254,13 @@ public class NamespaceSessionManagementTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.sessionAuthenticationStrategy(sessionAuthenticationStrategy()) // session-management@session-authentication-strategy-ref .sessionAuthenticationStrategy(sessionAuthenticationStrategy()) // session-management@session-authentication-strategy-ref
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
@Bean @Bean
@ -283,11 +289,13 @@ public class NamespaceSessionManagementTests {
static class SFPNoneSessionManagementConfig extends WebSecurityConfigurerAdapter { static class SFPNoneSessionManagementConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.sessionAuthenticationStrategy(new NullAuthenticatedSessionStrategy()) .sessionAuthenticationStrategy(new NullAuthenticatedSessionStrategy())
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
} }
@ -314,10 +322,12 @@ public class NamespaceSessionManagementTests {
static class SFPMigrateSessionManagementConfig extends WebSecurityConfigurerAdapter { static class SFPMigrateSessionManagementConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
} }
@ -338,10 +348,12 @@ public class NamespaceSessionManagementTests {
static class SFPPostProcessedConfig extends WebSecurityConfigurerAdapter { static class SFPPostProcessedConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
@Bean @Bean
@ -373,11 +385,13 @@ public class NamespaceSessionManagementTests {
static class SFPNewSessionSessionManagementConfig extends WebSecurityConfigurerAdapter { static class SFPNewSessionSessionManagementConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.sessionFixation().newSession() .sessionFixation().newSession()
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
} }

View File

@ -63,6 +63,7 @@ public class PermitAllSupportTests {
static class PermitAllConfig extends WebSecurityConfigurerAdapter { static class PermitAllConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -70,6 +71,7 @@ public class PermitAllSupportTests {
.formLogin() .formLogin()
.loginPage("/xyz").permitAll() .loginPage("/xyz").permitAll()
.loginProcessingUrl("/abc?def").permitAll(); .loginProcessingUrl("/abc?def").permitAll();
// @formatter:on
} }
} }
@ -85,9 +87,11 @@ public class PermitAllSupportTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.formLogin() .formLogin()
.permitAll(); .permitAll();
// @formatter:on
} }
} }
} }

View File

@ -54,6 +54,7 @@ public class PortMapperConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.requiresChannel() .requiresChannel()
.anyRequest().requiresSecure() .anyRequest().requiresSecure()
@ -62,6 +63,7 @@ public class PortMapperConfigurerTests {
.http(543).mapsTo(123) .http(543).mapsTo(123)
.and() .and()
.portMapper(); .portMapper();
// @formatter:on
} }
} }

View File

@ -260,11 +260,13 @@ public class RequestCacheConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
} }

View File

@ -103,15 +103,15 @@ public class SessionManagementConfigurerServlet31Tests {
@EnableWebSecurity @EnableWebSecurity
static class SessionManagementDefaultSessionFixationServlet31Config extends static class SessionManagementDefaultSessionFixationServlet31Config extends
WebSecurityConfigurerAdapter { WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.formLogin() .formLogin()
.and() .and()
.sessionManagement(); .sessionManagement();
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Override @Override

View File

@ -60,16 +60,16 @@ public class SessionManagementConfigurerSessionAuthenticationStrategyTests {
static class CustomSessionAuthenticationStrategyConfig extends WebSecurityConfigurerAdapter { static class CustomSessionAuthenticationStrategyConfig extends WebSecurityConfigurerAdapter {
static SessionAuthenticationStrategy customSessionAuthenticationStrategy = mock(SessionAuthenticationStrategy.class); static SessionAuthenticationStrategy customSessionAuthenticationStrategy = mock(SessionAuthenticationStrategy.class);
// @formatter:off
@Override @Override
public void configure(HttpSecurity http) throws Exception { public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.formLogin() .formLogin()
.and() .and()
.sessionManagement() .sessionManagement()
.sessionAuthenticationStrategy(customSessionAuthenticationStrategy); .sessionAuthenticationStrategy(customSessionAuthenticationStrategy);
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Override @Override

View File

@ -80,8 +80,10 @@ public class SessionManagementConfigurerSessionCreationPolicyTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
super.configure(http); super.configure(http);
// @formatter:off
http http
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// @formatter:on
http.setSharedObject(SessionCreationPolicy.class, SessionCreationPolicy.ALWAYS); http.setSharedObject(SessionCreationPolicy.class, SessionCreationPolicy.ALWAYS);
} }

View File

@ -70,9 +70,10 @@ public class SessionManagementConfigurerTransientAuthenticationTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
super.configure(http); super.configure(http);
// @formatter:off
http http
.csrf().disable(); .csrf().disable();
// @formatter:on
} }
@Override @Override
@ -86,8 +87,10 @@ public class SessionManagementConfigurerTransientAuthenticationTests {
static class AlwaysCreateSessionConfig extends WithTransientAuthenticationConfig { static class AlwaysCreateSessionConfig extends WithTransientAuthenticationConfig {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS); .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.ALWAYS);
// @formatter:on
} }
} }

View File

@ -268,6 +268,7 @@ public class OAuth2ClientConfigurerTests {
static class OAuth2ClientConfig extends WebSecurityConfigurerAdapter { static class OAuth2ClientConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -279,6 +280,7 @@ public class OAuth2ClientConfigurerTests {
.authorizationCodeGrant() .authorizationCodeGrant()
.authorizationRequestResolver(authorizationRequestResolver) .authorizationRequestResolver(authorizationRequestResolver)
.accessTokenResponseClient(accessTokenResponseClient); .accessTokenResponseClient(accessTokenResponseClient);
// @formatter:on
} }
@Bean @Bean

View File

@ -617,10 +617,12 @@ public class OAuth2LoginConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login() .oauth2Login()
.clientRegistrationRepository( .clientRegistrationRepository(
new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION)); new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION));
// @formatter:on
super.configure(http); super.configure(http);
} }
@ -658,12 +660,14 @@ public class OAuth2LoginConfigurerTests {
static class OAuth2LoginConfigCustomWithConfigurer extends CommonWebSecurityConfigurerAdapter { static class OAuth2LoginConfigCustomWithConfigurer extends CommonWebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login() .oauth2Login()
.clientRegistrationRepository( .clientRegistrationRepository(
new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION)) new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION))
.userInfoEndpoint() .userInfoEndpoint()
.userAuthoritiesMapper(createGrantedAuthoritiesMapper()); .userAuthoritiesMapper(createGrantedAuthoritiesMapper());
// @formatter:on
super.configure(http); super.configure(http);
} }
} }
@ -672,8 +676,10 @@ public class OAuth2LoginConfigurerTests {
static class OAuth2LoginConfigCustomWithBeanRegistration extends CommonWebSecurityConfigurerAdapter { static class OAuth2LoginConfigCustomWithBeanRegistration extends CommonWebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login(); .oauth2Login();
// @formatter:on
super.configure(http); super.configure(http);
} }
@ -692,6 +698,7 @@ public class OAuth2LoginConfigurerTests {
static class OAuth2LoginConfigCustomUserServiceBeanRegistration extends WebSecurityConfigurerAdapter { static class OAuth2LoginConfigCustomUserServiceBeanRegistration extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -702,6 +709,7 @@ public class OAuth2LoginConfigurerTests {
.oauth2Login() .oauth2Login()
.tokenEndpoint() .tokenEndpoint()
.accessTokenResponseClient(createOauth2AccessTokenResponseClient()); .accessTokenResponseClient(createOauth2AccessTokenResponseClient());
// @formatter:on
} }
@Bean @Bean
@ -739,11 +747,13 @@ public class OAuth2LoginConfigurerTests {
static class OAuth2LoginConfigLoginProcessingUrl extends CommonWebSecurityConfigurerAdapter { static class OAuth2LoginConfigLoginProcessingUrl extends CommonWebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login() .oauth2Login()
.clientRegistrationRepository( .clientRegistrationRepository(
new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION)) new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION))
.loginProcessingUrl("/login/oauth2/*"); .loginProcessingUrl("/login/oauth2/*");
// @formatter:on
super.configure(http); super.configure(http);
} }
} }
@ -757,11 +767,13 @@ public class OAuth2LoginConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login() .oauth2Login()
.clientRegistrationRepository(this.clientRegistrationRepository) .clientRegistrationRepository(this.clientRegistrationRepository)
.authorizationEndpoint() .authorizationEndpoint()
.authorizationRequestResolver(this.resolver); .authorizationRequestResolver(this.resolver);
// @formatter:on
super.configure(http); super.configure(http);
} }
} }
@ -775,6 +787,7 @@ public class OAuth2LoginConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login(oauth2Login -> .oauth2Login(oauth2Login ->
oauth2Login oauth2Login
@ -784,6 +797,7 @@ public class OAuth2LoginConfigurerTests {
.authorizationRequestResolver(this.resolver) .authorizationRequestResolver(this.resolver)
) )
); );
// @formatter:on
super.configure(http); super.configure(http);
} }
} }
@ -792,11 +806,13 @@ public class OAuth2LoginConfigurerTests {
static class OAuth2LoginConfigMultipleClients extends CommonWebSecurityConfigurerAdapter { static class OAuth2LoginConfigMultipleClients extends CommonWebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login() .oauth2Login()
.clientRegistrationRepository( .clientRegistrationRepository(
new InMemoryClientRegistrationRepository( new InMemoryClientRegistrationRepository(
GOOGLE_CLIENT_REGISTRATION, GITHUB_CLIENT_REGISTRATION)); GOOGLE_CLIENT_REGISTRATION, GITHUB_CLIENT_REGISTRATION));
// @formatter:on
super.configure(http); super.configure(http);
} }
} }
@ -805,11 +821,13 @@ public class OAuth2LoginConfigurerTests {
static class OAuth2LoginConfigCustomLoginPage extends CommonWebSecurityConfigurerAdapter { static class OAuth2LoginConfigCustomLoginPage extends CommonWebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.oauth2Login() .oauth2Login()
.clientRegistrationRepository( .clientRegistrationRepository(
new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION)) new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION))
.loginPage("/custom-login"); .loginPage("/custom-login");
// @formatter:on
super.configure(http); super.configure(http);
} }
} }
@ -835,9 +853,11 @@ public class OAuth2LoginConfigurerTests {
static class OAuth2LoginConfigWithOidcLogoutSuccessHandler extends CommonWebSecurityConfigurerAdapter { static class OAuth2LoginConfigWithOidcLogoutSuccessHandler extends CommonWebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.logout() .logout()
.logoutSuccessHandler(oidcLogoutSuccessHandler()); .logoutSuccessHandler(oidcLogoutSuccessHandler());
// @formatter:on
super.configure(http); super.configure(http);
} }
@ -859,6 +879,7 @@ public class OAuth2LoginConfigurerTests {
private static abstract class CommonWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { private static abstract class CommonWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -873,6 +894,7 @@ public class OAuth2LoginConfigurerTests {
.userInfoEndpoint() .userInfoEndpoint()
.userService(createOauth2UserService()) .userService(createOauth2UserService())
.oidcUserService(createOidcUserService()); .oidcUserService(createOidcUserService());
// @formatter:on
} }
@Bean @Bean

View File

@ -1761,7 +1761,6 @@ public class OAuth2ResourceServerConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -1769,7 +1768,6 @@ public class OAuth2ResourceServerConfigurerTests {
.oauth2ResourceServer() .oauth2ResourceServer()
.jwt() .jwt()
.jwtAuthenticationConverter(getJwtAuthenticationConverter()); .jwtAuthenticationConverter(getJwtAuthenticationConverter());
// @formatter:on // @formatter:on
} }
@ -1783,7 +1781,6 @@ public class OAuth2ResourceServerConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/requires-read-scope").access("hasAuthority('message:read')") .antMatchers("/requires-read-scope").access("hasAuthority('message:read')")
@ -1791,7 +1788,6 @@ public class OAuth2ResourceServerConfigurerTests {
.oauth2ResourceServer() .oauth2ResourceServer()
.jwt() .jwt()
.jwtAuthenticationConverter(getJwtAuthenticationConverter()); .jwtAuthenticationConverter(getJwtAuthenticationConverter());
// @formatter:on // @formatter:on
} }
@ -2255,6 +2251,7 @@ public class OAuth2ResourceServerConfigurerTests {
.jwt() .jwt()
.and() .and()
.opaqueToken(); .opaqueToken();
// @formatter:on
} }
} }
@ -2306,6 +2303,7 @@ public class OAuth2ResourceServerConfigurerTests {
.oauth2ResourceServer() .oauth2ResourceServer()
.authenticationManagerResolver(mock(AuthenticationManagerResolver.class)) .authenticationManagerResolver(mock(AuthenticationManagerResolver.class))
.opaqueToken(); .opaqueToken();
// @formatter:on
} }
} }

View File

@ -300,11 +300,13 @@ public class Saml2LoginConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests(authz -> authz .authorizeRequests(authz -> authz
.anyRequest().authenticated() .anyRequest().authenticated()
) )
.saml2Login(withDefaults()); .saml2Login(withDefaults());
// @formatter:on
} }
@Bean @Bean
@ -319,11 +321,13 @@ public class Saml2LoginConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests(authz -> authz .authorizeRequests(authz -> authz
.anyRequest().authenticated() .anyRequest().authenticated()
) )
.saml2Login(saml2 -> {}); .saml2Login(saml2 -> {});
// @formatter:on
} }
@Bean @Bean

View File

@ -165,9 +165,11 @@ public class GrantedAuthorityDefaultsJcTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().access("hasRole('USER')"); .anyRequest().access("hasRole('USER')");
// @formatter:on
} }
@Bean @Bean

View File

@ -42,17 +42,19 @@ public class CustomConfigurer extends SecurityConfigurerAdapter<DefaultSecurityF
// autowire this bean // autowire this bean
ApplicationContext context = http.getSharedObject(ApplicationContext.class); ApplicationContext context = http.getSharedObject(ApplicationContext.class);
context.getAutowireCapableBeanFactory().autowireBean(this); context.getAutowireCapableBeanFactory().autowireBean(this);
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers(permitAllPattern).permitAll() .antMatchers(permitAllPattern).permitAll()
.anyRequest().authenticated(); .anyRequest().authenticated();
// @formatter:on
if (http.getConfigurer(FormLoginConfigurer.class) == null) { if (http.getConfigurer(FormLoginConfigurer.class) == null) {
// only apply if formLogin() was not invoked by the user // only apply if formLogin() was not invoked by the user
// @formatter:off
http http
.formLogin() .formLogin()
.loginPage(loginPage); .loginPage(loginPage);
// @formatter:on
} }
} }

View File

@ -120,9 +120,11 @@ public class CustomHttpSecurityConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.apply(customConfigurer()) .apply(customConfigurer())
.loginPage("/custom"); .loginPage("/custom");
// @formatter:on
} }
@Bean @Bean
@ -142,12 +144,14 @@ public class CustomHttpSecurityConfigurerTests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.apply(customConfigurer()) .apply(customConfigurer())
.and() .and()
.csrf().disable() .csrf().disable()
.formLogin() .formLogin()
.loginPage("/other"); .loginPage("/other");
// @formatter:on
} }
@Bean @Bean

View File

@ -117,8 +117,10 @@ public class OAuth2ClientSpecTests {
static class Config { static class Config {
@Bean @Bean
SecurityWebFilterChain springSecurity(ServerHttpSecurity http) { SecurityWebFilterChain springSecurity(ServerHttpSecurity http) {
// @formatter:off
http http
.oauth2Client(); .oauth2Client();
// @formatter:on
return http.build(); return http.build();
} }
@ -208,6 +210,7 @@ public class OAuth2ClientSpecTests {
@Bean @Bean
public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) {
// @formatter:off
http http
.oauth2Client() .oauth2Client()
.authenticationConverter(this.authenticationConverter) .authenticationConverter(this.authenticationConverter)
@ -215,6 +218,7 @@ public class OAuth2ClientSpecTests {
.authorizationRequestRepository(this.authorizationRequestRepository) .authorizationRequestRepository(this.authorizationRequestRepository)
.and() .and()
.requestCache(c -> c.requestCache(this.requestCache)); .requestCache(c -> c.requestCache(this.requestCache));
// @formatter:on
return http.build(); return http.build();
} }
} }
@ -274,6 +278,7 @@ public class OAuth2ClientSpecTests {
@Bean @Bean
public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) {
// @formatter:off
http http
.oauth2Client(oauth2Client -> .oauth2Client(oauth2Client ->
oauth2Client oauth2Client
@ -281,6 +286,7 @@ public class OAuth2ClientSpecTests {
.authenticationManager(this.manager) .authenticationManager(this.manager)
.authorizationRequestRepository(this.authorizationRequestRepository)) .authorizationRequestRepository(this.authorizationRequestRepository))
.requestCache(c -> c.requestCache(this.requestCache)); .requestCache(c -> c.requestCache(this.requestCache));
// @formatter:on
return http.build(); return http.build();
} }
} }

View File

@ -253,12 +253,14 @@ public class OAuth2LoginTests {
@Bean @Bean
SecurityWebFilterChain springSecurity(ServerHttpSecurity http) { SecurityWebFilterChain springSecurity(ServerHttpSecurity http) {
// @formatter:off
http http
.requestCache() .requestCache()
.requestCache(this.requestCache) .requestCache(this.requestCache)
.and() .and()
.oauth2Login() .oauth2Login()
.authorizationRequestRepository(this.authorizationRequestRepository); .authorizationRequestRepository(this.authorizationRequestRepository);
// @formatter:on
return http.build(); return http.build();
} }
@ -395,6 +397,7 @@ public class OAuth2LoginTests {
@Bean @Bean
public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) {
// @formatter:off
http http
.authorizeExchange() .authorizeExchange()
.anyExchange().authenticated() .anyExchange().authenticated()
@ -406,6 +409,7 @@ public class OAuth2LoginTests {
.authorizationRequestResolver(resolver) .authorizationRequestResolver(resolver)
.authenticationSuccessHandler(successHandler) .authenticationSuccessHandler(successHandler)
.authenticationFailureHandler(failureHandler); .authenticationFailureHandler(failureHandler);
// @formatter:on
return http.build(); return http.build();
} }
} }
@ -474,6 +478,7 @@ public class OAuth2LoginTests {
@Bean @Bean
public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) {
// @formatter:off
http http
.authorizeExchange(exchanges -> .authorizeExchange(exchanges ->
exchanges exchanges
@ -487,6 +492,7 @@ public class OAuth2LoginTests {
.authorizationRequestResolver(resolver) .authorizationRequestResolver(resolver)
.authenticationSuccessHandler(successHandler) .authenticationSuccessHandler(successHandler)
); );
// @formatter:on
return http.build(); return http.build();
} }
} }
@ -715,7 +721,7 @@ public class OAuth2LoginTests {
@Bean @Bean
public SecurityWebFilterChain springSecurity(ServerHttpSecurity http) { public SecurityWebFilterChain springSecurity(ServerHttpSecurity http) {
// @formatter:off
http http
.csrf().disable() .csrf().disable()
.logout() .logout()
@ -726,7 +732,7 @@ public class OAuth2LoginTests {
new InMemoryReactiveClientRegistrationRepository(this.withLogout))) new InMemoryReactiveClientRegistrationRepository(this.withLogout)))
.and() .and()
.securityContextRepository(this.repository); .securityContextRepository(this.repository);
// @formatter:on
return http.build(); return http.build();
} }

View File

@ -486,8 +486,6 @@ public class OAuth2ResourceServerSpecTests {
.jwt() .jwt()
.publicKey(publicKey()); .publicKey(publicKey());
// @formatter:on // @formatter:on
return http.build(); return http.build();
} }
} }
@ -511,7 +509,6 @@ public class OAuth2ResourceServerSpecTests {
) )
); );
// @formatter:on // @formatter:on
return http.build(); return http.build();
} }
} }
@ -533,8 +530,6 @@ public class OAuth2ResourceServerSpecTests {
.jwt() .jwt()
.publicKey(this.key); .publicKey(this.key);
// @formatter:on // @formatter:on
return http.build(); return http.build();
} }
} }
@ -877,6 +872,7 @@ public class OAuth2ResourceServerSpecTests {
.oauth2ResourceServer() .oauth2ResourceServer()
.authenticationManagerResolver(mock(ReactiveAuthenticationManagerResolver.class)) .authenticationManagerResolver(mock(ReactiveAuthenticationManagerResolver.class))
.opaqueToken(); .opaqueToken();
// @formatter:on
return http.build(); return http.build();
} }

View File

@ -148,12 +148,14 @@ public class Sec2935Tests {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
@Autowired @Autowired

View File

@ -72,16 +72,15 @@ public class SecurityMockMvcRequestPostProcessorsAuthenticationStatelessTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
super.configure(http); super.configure(http);
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Autowired @Autowired

View File

@ -165,11 +165,13 @@ public class SecurityMockMvcRequestPostProcessorsOAuth2ClientTests {
static class OAuth2ClientConfig extends WebSecurityConfigurerAdapter { static class OAuth2ClientConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests(authz -> authz .authorizeRequests(authz -> authz
.anyRequest().permitAll() .anyRequest().permitAll()
) )
.oauth2Client(); .oauth2Client();
// @formatter:on
} }
@Bean @Bean

View File

@ -167,11 +167,13 @@ public class SecurityMockMvcRequestPostProcessorsOAuth2LoginTests {
static class OAuth2LoginConfig extends WebSecurityConfigurerAdapter { static class OAuth2LoginConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests(authorize -> authorize .authorizeRequests(authorize -> authorize
.mvcMatchers("/admin/**").hasAuthority("SCOPE_admin") .mvcMatchers("/admin/**").hasAuthority("SCOPE_admin")
.anyRequest().hasAuthority("SCOPE_read") .anyRequest().hasAuthority("SCOPE_read")
).oauth2Login(); ).oauth2Login();
// @formatter:on
} }
@Bean @Bean

View File

@ -173,12 +173,14 @@ public class SecurityMockMvcRequestPostProcessorsOidcLoginTests {
static class OAuth2LoginConfig extends WebSecurityConfigurerAdapter { static class OAuth2LoginConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.mvcMatchers("/admin/**").hasAuthority("SCOPE_admin") .mvcMatchers("/admin/**").hasAuthority("SCOPE_admin")
.anyRequest().hasAuthority("SCOPE_read") .anyRequest().hasAuthority("SCOPE_read")
.and() .and()
.oauth2Login(); .oauth2Login();
// @formatter:on
} }
@Bean @Bean

View File

@ -130,6 +130,7 @@ public class SecurityMockMvcRequestPostProcessorsOpaqueTokenTests {
static class OAuth2LoginConfig extends WebSecurityConfigurerAdapter { static class OAuth2LoginConfig extends WebSecurityConfigurerAdapter {
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.mvcMatchers("/admin/**").hasAuthority("SCOPE_admin") .mvcMatchers("/admin/**").hasAuthority("SCOPE_admin")
@ -138,6 +139,7 @@ public class SecurityMockMvcRequestPostProcessorsOpaqueTokenTests {
.oauth2ResourceServer() .oauth2ResourceServer()
.opaqueToken() .opaqueToken()
.introspector(mock(OpaqueTokenIntrospector.class)); .introspector(mock(OpaqueTokenIntrospector.class));
// @formatter:on
} }
@RestController @RestController

View File

@ -72,16 +72,15 @@ public class SecurityMockMvcRequestPostProcessorsTestSecurityContextStatelessTes
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
super.configure(http); super.configure(http);
// @formatter:off
http http
.sessionManagement() .sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Autowired @Autowired

View File

@ -74,14 +74,14 @@ public class CustomCsrfShowcaseTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.csrf() .csrf()
.csrfTokenRepository(repo()); .csrfTokenRepository(repo());
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Autowired @Autowired

View File

@ -91,9 +91,9 @@ public class CustomConfigAuthenticationTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -105,8 +105,8 @@ public class CustomConfigAuthenticationTests {
.usernameParameter("user") .usernameParameter("user")
.passwordParameter("pass") .passwordParameter("pass")
.loginPage("/authenticate"); .loginPage("/authenticate");
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Bean @Bean

View File

@ -81,9 +81,9 @@ public class CustomLoginRequestBuilderAuthenticationTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.anyRequest().authenticated() .anyRequest().authenticated()
@ -92,8 +92,8 @@ public class CustomLoginRequestBuilderAuthenticationTests {
.usernameParameter("user") .usernameParameter("user")
.passwordParameter("pass") .passwordParameter("pass")
.loginPage("/authenticate"); .loginPage("/authenticate");
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Bean @Bean

View File

@ -85,17 +85,17 @@ public class DefaultfSecurityRequestsTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Autowired @Autowired

View File

@ -103,17 +103,17 @@ public class SecurityRequestsTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Autowired @Autowired

View File

@ -87,17 +87,17 @@ public class WithUserAuthenticationTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Autowired @Autowired

View File

@ -87,17 +87,17 @@ public class WithUserClassLevelAuthenticationTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.httpBasic(); .httpBasic();
// @formatter:on
} }
// @formatter:on
// @formatter:off // @formatter:off
@Autowired @Autowired

View File

@ -79,17 +79,17 @@ public class WithUserDetailsAuthenticationTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
// @formatter:on
@Bean @Bean
@Override @Override

View File

@ -79,17 +79,17 @@ public class WithUserDetailsClassLevelAuthenticationTests {
@EnableWebMvc @EnableWebMvc
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.authorizeRequests() .authorizeRequests()
.antMatchers("/admin/**").hasRole("ADMIN") .antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated() .anyRequest().authenticated()
.and() .and()
.formLogin(); .formLogin();
// @formatter:on
} }
// @formatter:on
@Bean @Bean
@Override @Override

View File

@ -189,29 +189,29 @@ public class WebTestUtilsTests {
static CsrfTokenRepository CSRF_REPO; static CsrfTokenRepository CSRF_REPO;
static SecurityContextRepository CONTEXT_REPO; static SecurityContextRepository CONTEXT_REPO;
// @formatter:off
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http http
.csrf() .csrf()
.csrfTokenRepository(CSRF_REPO) .csrfTokenRepository(CSRF_REPO)
.and() .and()
.securityContext() .securityContext()
.securityContextRepository(CONTEXT_REPO); .securityContextRepository(CONTEXT_REPO);
// @formatter:on
} }
// @formatter:on
} }
@EnableWebSecurity @EnableWebSecurity
static class PartialSecurityConfig extends WebSecurityConfigurerAdapter { static class PartialSecurityConfig extends WebSecurityConfigurerAdapter {
// @formatter:off
@Override @Override
public void configure(HttpSecurity http) { public void configure(HttpSecurity http) {
// @formatter:off
http http
.antMatcher("/willnotmatchthis"); .antMatcher("/willnotmatchthis");
// @formatter:on
} }
// @formatter:on
} }
@Configuration @Configuration