Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Feb 24, 2025
1 parent 4c387e5 commit e9ad7ac
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;

@Configuration
@EnableWebSecurity
Expand All @@ -19,8 +15,7 @@ public class CtpSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.anonymous()
.and()
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
.authorizeHttpRequests((requests) -> requests
.requestMatchers("**").permitAll()
.requestMatchers("/resources/**").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;

@Configuration
@EnableWebSecurity
Expand All @@ -19,8 +15,7 @@ public class CtpSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.anonymous()
.and()
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
.authorizeHttpRequests((requests) -> requests
.requestMatchers("**").permitAll()
.requestMatchers("/resources/**").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan
public class SpringmvcApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class CtpSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.anonymous()
.and()
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
.authorizeHttpRequests((requests) -> requests
.requestMatchers("**").permitAll()
.requestMatchers("/resources/**").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;

@Configuration
@EnableWebSecurity
Expand All @@ -19,8 +15,7 @@ public class CtpSecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.anonymous()
.and()
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
.authorizeHttpRequests((requests) -> requests
.requestMatchers("**").permitAll()
.requestMatchers("/resources/**").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import reactor.netty.http.server.HttpServer;

@SpringBootApplication
@ComponentScan
@PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true)
public class Application {
@Value("${server.port:8080}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,30 @@ public CtpSecurityConfig(
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository();
return http.securityContextRepository(securityContextRepository)
.anonymous()
.and()
.anonymous(anonymous -> anonymous.authorities("ROLE_ANON"))
.addFilterBefore(new LoginWebFilter(authenticationManagerResolver, securityContextRepository),
SecurityWebFiltersOrder.FORM_LOGIN)
.logout()
.logoutUrl("/logout")
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))
.logoutHandler(new DelegatingServerLogoutHandler(new WebSessionServerLogoutHandler(),
new SecurityContextServerLogoutHandler()))
.logoutSuccessHandler(new RedirectServerLogoutSuccessHandler())
.and()
.formLogin()
.loginPage("/login")
.requiresAuthenticationMatcher(ServerWebExchangeMatchers.pathMatchers("none"))
.authenticationManager(Mono::just)
.and()
.authorizeExchange()
.pathMatchers("/login")
.permitAll()
.pathMatchers("/")
.permitAll()
.pathMatchers("/resources/**")
.permitAll()
.pathMatchers("/home")
.permitAll()
.pathMatchers("/p/**")
.permitAll()
.pathMatchers("/cart/**")
.permitAll()
.pathMatchers("/me/**")
.authenticated()
.anyExchange()
.authenticated()
.and()
.logout(logoutSpec -> logoutSpec
.logoutUrl("/logout")
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, "/logout"))
.logoutSuccessHandler(new RedirectServerLogoutSuccessHandler())
.logoutHandler(new DelegatingServerLogoutHandler(new WebSessionServerLogoutHandler(), new SecurityContextServerLogoutHandler()))
)
.formLogin(formLoginSpec -> formLoginSpec
.loginPage("/login")
.requiresAuthenticationMatcher(ServerWebExchangeMatchers.pathMatchers("none"))
.authenticationManager(Mono::just)
)
.authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec
.pathMatchers("/login").permitAll()
.pathMatchers("/").permitAll()
.pathMatchers("/resources/**").permitAll()
.pathMatchers("/home").permitAll()
.pathMatchers("/p/**").permitAll()
.pathMatchers("/cart/**").permitAll()
.pathMatchers("/me/**").authenticated()
.anyExchange().authenticated()
)
.build();
}

Expand Down

0 comments on commit e9ad7ac

Please sign in to comment.