Update HttpSecurity Formatting

This commit is contained in:
Josh Cummings 2021-11-10 09:42:09 -07:00
parent 3a4eec6eda
commit 3a58daf55d
27 changed files with 98 additions and 100 deletions

View File

@ -53,7 +53,7 @@ public class WebfluxFormSecurityConfiguration {
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
// @formatter:off
http
.authorizeExchange((exchanges) -> exchanges
.authorizeExchange((authorize) -> authorize
.pathMatchers("/login").permitAll()
.anyExchange().authenticated()
)

View File

@ -53,7 +53,7 @@ public class WebfluxX509Application {
// @formatter:off
http
.x509(withDefaults())
.authorizeExchange((exchanges) -> exchanges
.authorizeExchange((authorize) -> authorize
.anyExchange().authenticated()
);
// @formatter:on

View File

@ -39,7 +39,7 @@ public class SecurityConfiguration {
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
// @formatter:off
http
.authorizeExchange((exchanges) -> exchanges
.authorizeExchange((authorize) -> authorize
.anyExchange().authenticated()
)
.formLogin(withDefaults());

View File

@ -45,7 +45,7 @@ public class SecurityConfiguration {
http
// Demonstrate that method security works
// Best practice to use both for defense in depth
.authorizeExchange((exchanges) -> exchanges
.authorizeExchange((authorize) -> authorize
.anyExchange().permitAll()
)
.httpBasic(withDefaults());

View File

@ -37,7 +37,7 @@ public class SecurityConfiguration {
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
// @formatter:off
http
.authorizeExchange((exchanges) -> exchanges
.authorizeExchange((authorize) -> authorize
.pathMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
.pathMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
.anyExchange().authenticated()

View File

@ -37,7 +37,7 @@ public class SecurityConfiguration {
SecurityWebFilterChain configure(ServerHttpSecurity http) {
// @formatter:off
http
.authorizeExchange((exchanges) -> exchanges
.authorizeExchange((authorize) -> authorize
.pathMatchers("/", "/public/**").permitAll()
.anyExchange().authenticated()
)

View File

@ -31,15 +31,11 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.authorizeRequests((authorize) -> authorize
.antMatchers("/login", "/resources/**").permitAll()
.anyRequest().authenticated()
)
.jee((jee) ->
jee
.mappableRoles("USER", "ADMIN")
);
.jee((jee) -> jee.mappableRoles("USER", "ADMIN"));
}
// @formatter:on

View File

@ -33,7 +33,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.formLogin((form) -> form

View File

@ -31,7 +31,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.formLogin((form) -> form

View File

@ -33,8 +33,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((authorizeRequests) ->
authorizeRequests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.x509(withDefaults());

View File

@ -33,7 +33,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.httpBasic(withDefaults())

View File

@ -33,7 +33,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.httpBasic(withDefaults())

View File

@ -48,7 +48,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.formLogin(withDefaults())

View File

@ -44,10 +44,16 @@ public class SecurityConfig {
SecurityFilterChain web(HttpSecurity http,
AuthorizationManager<RequestAuthorizationContext> mfaAuthorizationManager) throws Exception {
MfaAuthenticationHandler mfaAuthenticationHandler = new MfaAuthenticationHandler("/second-factor");
http.authorizeHttpRequests((authz) -> authz.mvcMatchers("/second-factor", "/third-factor")
.access(mfaAuthorizationManager).anyRequest().authenticated())
.formLogin((form) -> form.successHandler(mfaAuthenticationHandler)
.failureHandler(mfaAuthenticationHandler))
// @formatter:off
http
.authorizeHttpRequests((authorize) -> authorize
.mvcMatchers("/second-factor", "/third-factor").access(mfaAuthorizationManager)
.anyRequest().authenticated()
)
.formLogin((form) -> form
.successHandler(mfaAuthenticationHandler)
.failureHandler(mfaAuthenticationHandler)
)
.exceptionHandling((exceptions) -> exceptions
.withObjectPostProcessor(new ObjectPostProcessor<ExceptionTranslationFilter>() {
@Override
@ -55,8 +61,9 @@ public class SecurityConfig {
filter.setAuthenticationTrustResolver(new MfaTrustResolver());
return filter;
}
}));
})
);
// @formatter:on
return http.build();
}

View File

@ -40,7 +40,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// @formatter:off
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.httpBasic(withDefaults())

View File

@ -61,7 +61,10 @@ public class RestConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.authorizeRequests((authz) -> authz.anyRequest().authenticated())
http
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.csrf((csrf) -> csrf.ignoringAntMatchers("/token"))
.httpBasic(Customizer.withDefaults())
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)

View File

@ -72,7 +72,9 @@ public class OAuth2AuthorizationServerSecurityConfiguration {
public SecurityFilterChain standardSecurityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests((requests) -> requests.anyRequest().authenticated())
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.formLogin(Customizer.withDefaults());
// @formatter:on

View File

@ -334,16 +334,12 @@ public class OAuth2LoginApplicationTests {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.oauth2Login((oauth2) -> oauth2
.tokenEndpoint((tokens) -> tokens
.accessTokenResponseClient(this.mockAccessTokenResponseClient())
)
.userInfoEndpoint((userInfo) -> userInfo
.userService(this.mockUserService())
)
.tokenEndpoint((token) -> token.accessTokenResponseClient(mockAccessTokenResponseClient()))
.userInfoEndpoint((userInfo) -> userInfo.userService(mockUserService()))
);
}
// @formatter:on

View File

@ -40,8 +40,7 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests((requests) ->
requests
.authorizeRequests((authorize) -> authorize
.antMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
.antMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
.anyRequest().authenticated()

View File

@ -72,15 +72,11 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests((requests) ->
requests
.authorizeRequests((authorize) -> authorize
.antMatchers("/message/**").hasAuthority("SCOPE_message:read")
.anyRequest().authenticated()
)
.oauth2ResourceServer((resourceServer) ->
resourceServer
.jwt(withDefaults())
);
.oauth2ResourceServer((oauth2) -> oauth2.jwt(withDefaults()));
// @formatter:on
}

View File

@ -47,11 +47,11 @@ public class OAuth2ResourceServerSecurityConfiguration {
AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver) throws Exception {
// @formatter:off
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.mvcMatchers("/**/message/**").hasAuthority("SCOPE_message:read")
.anyRequest().authenticated()
)
.oauth2ResourceServer((resourceServer) -> resourceServer
.oauth2ResourceServer((oauth2) -> oauth2
.authenticationManagerResolver(authenticationManagerResolver)
);
// @formatter:on

View File

@ -42,13 +42,13 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.mvcMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
.mvcMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
.anyRequest().authenticated()
)
.oauth2ResourceServer((resourceServer) -> resourceServer
.opaqueToken((opaqueToken) -> opaqueToken
.oauth2ResourceServer((oauth2) -> oauth2
.opaqueToken((opaque) -> opaque
.introspectionUri(this.introspectionUri)
.introspectionClientCredentials(this.clientId, this.clientSecret)
)

View File

@ -40,14 +40,12 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.mvcMatchers("/message/**").hasAuthority("SCOPE_message:read")
.anyRequest().authenticated()
)
.oauth2ResourceServer((resourceServer) -> resourceServer
.jwt((jwt) -> jwt
.decoder(jwtDecoder())
)
.oauth2ResourceServer((oauth2) -> oauth2
.jwt((jwt) -> jwt.decoder(jwtDecoder()))
);
// @formatter:on
}

View File

@ -38,7 +38,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests((requests) -> requests
.authorizeRequests((authorize) -> authorize
.mvcMatchers("/", "/public/**").permitAll()
.anyRequest().authenticated()
)

View File

@ -30,7 +30,9 @@ public class SecurityConfiguration {
SecurityFilterChain app(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeRequests((authorize) -> authorize.anyRequest().authenticated())
.authorizeRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.saml2Login(withDefaults())
.saml2Logout(withDefaults());
// @formatter:on