Skip to content

Commit e9ad7ac

Browse files
committed
cleanups
1 parent 4c387e5 commit e9ad7ac

File tree

7 files changed

+26
-54
lines changed

7 files changed

+26
-54
lines changed

examples/spring-datadog-statsd/src/main/java/com/commercetools/sdk/examples/springmvc/config/CtpSecurityConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
77
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
88
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9-
import org.springframework.security.config.web.server.ServerHttpSecurity;
109
import org.springframework.security.web.SecurityFilterChain;
11-
import org.springframework.security.web.server.SecurityWebFilterChain;
12-
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
13-
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;
1410

1511
@Configuration
1612
@EnableWebSecurity
@@ -19,8 +15,7 @@ public class CtpSecurityConfig {
1915
@Bean
2016
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
2117
http
22-
.anonymous()
23-
.and()
18+
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
2419
.authorizeHttpRequests((requests) -> requests
2520
.requestMatchers("**").permitAll()
2621
.requestMatchers("/resources/**").permitAll()

examples/spring-dynatrace-oneagent/src/main/java/com/commercetools/sdk/examples/springmvc/config/CtpSecurityConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
77
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
88
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9-
import org.springframework.security.config.web.server.ServerHttpSecurity;
109
import org.springframework.security.web.SecurityFilterChain;
11-
import org.springframework.security.web.server.SecurityWebFilterChain;
12-
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
13-
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;
1410

1511
@Configuration
1612
@EnableWebSecurity
@@ -19,8 +15,7 @@ public class CtpSecurityConfig {
1915
@Bean
2016
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
2117
http
22-
.anonymous()
23-
.and()
18+
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
2419
.authorizeHttpRequests((requests) -> requests
2520
.requestMatchers("**").permitAll()
2621
.requestMatchers("/resources/**").permitAll()

examples/spring-newrelic/src/main/java/com/commercetools/sdk/examples/springmvc/SpringmvcApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.springframework.context.annotation.ComponentScan;
66

77
@SpringBootApplication
8-
@ComponentScan
98
public class SpringmvcApplication {
109

1110
public static void main(String[] args) {

examples/spring-newrelic/src/main/java/com/commercetools/sdk/examples/springmvc/config/CtpSecurityConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public class CtpSecurityConfig {
1919
@Bean
2020
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
2121
http
22-
.anonymous()
23-
.and()
22+
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
2423
.authorizeHttpRequests((requests) -> requests
2524
.requestMatchers("**").permitAll()
2625
.requestMatchers("/resources/**").permitAll()

examples/spring-otel/src/main/java/com/commercetools/sdk/examples/springmvc/config/CtpSecurityConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
77
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
88
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9-
import org.springframework.security.config.web.server.ServerHttpSecurity;
109
import org.springframework.security.web.SecurityFilterChain;
11-
import org.springframework.security.web.server.SecurityWebFilterChain;
12-
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
13-
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;
1410

1511
@Configuration
1612
@EnableWebSecurity
@@ -19,8 +15,7 @@ public class CtpSecurityConfig {
1915
@Bean
2016
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
2117
http
22-
.anonymous()
23-
.and()
18+
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
2419
.authorizeHttpRequests((requests) -> requests
2520
.requestMatchers("**").permitAll()
2621
.requestMatchers("/resources/**").permitAll()

examples/spring/src/main/java/com/commercetools/sdk/examples/spring/Application.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import reactor.netty.http.server.HttpServer;
1717

1818
@SpringBootApplication
19-
@ComponentScan
2019
@PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true)
2120
public class Application {
2221
@Value("${server.port:8080}")

examples/spring/src/main/java/com/commercetools/sdk/examples/spring/config/CtpSecurityConfig.java

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,30 @@ public CtpSecurityConfig(
5353
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
5454
ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository();
5555
return http.securityContextRepository(securityContextRepository)
56-
.anonymous()
57-
.and()
56+
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
5857
.addFilterBefore(new LoginWebFilter(authenticationManagerResolver, securityContextRepository),
5958
SecurityWebFiltersOrder.FORM_LOGIN)
60-
.logout()
61-
.logoutUrl("/logout")
62-
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))
63-
.logoutHandler(new DelegatingServerLogoutHandler(new WebSessionServerLogoutHandler(),
64-
new SecurityContextServerLogoutHandler()))
65-
.logoutSuccessHandler(new RedirectServerLogoutSuccessHandler())
66-
.and()
67-
.formLogin()
68-
.loginPage("/login")
69-
.requiresAuthenticationMatcher(ServerWebExchangeMatchers.pathMatchers("none"))
70-
.authenticationManager(Mono::just)
71-
.and()
72-
.authorizeExchange()
73-
.pathMatchers("/login")
74-
.permitAll()
75-
.pathMatchers("/")
76-
.permitAll()
77-
.pathMatchers("/resources/**")
78-
.permitAll()
79-
.pathMatchers("/home")
80-
.permitAll()
81-
.pathMatchers("/p/**")
82-
.permitAll()
83-
.pathMatchers("/cart/**")
84-
.permitAll()
85-
.pathMatchers("/me/**")
86-
.authenticated()
87-
.anyExchange()
88-
.authenticated()
89-
.and()
59+
.logout(logoutSpec -> logoutSpec
60+
.logoutUrl("/logout")
61+
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))
62+
.logoutSuccessHandler(new RedirectServerLogoutSuccessHandler())
63+
.logoutHandler(new DelegatingServerLogoutHandler(new WebSessionServerLogoutHandler(), new SecurityContextServerLogoutHandler()))
64+
)
65+
.formLogin(formLoginSpec -> formLoginSpec
66+
.loginPage("/login")
67+
.requiresAuthenticationMatcher(ServerWebExchangeMatchers.pathMatchers("none"))
68+
.authenticationManager(Mono::just)
69+
)
70+
.authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec
71+
.pathMatchers("/login").permitAll()
72+
.pathMatchers("/").permitAll()
73+
.pathMatchers("/resources/**").permitAll()
74+
.pathMatchers("/home").permitAll()
75+
.pathMatchers("/p/**").permitAll()
76+
.pathMatchers("/cart/**").permitAll()
77+
.pathMatchers("/me/**").authenticated()
78+
.anyExchange().authenticated()
79+
)
9080
.build();
9181
}
9282

0 commit comments

Comments
 (0)