Skip to content

Instantly share code, notes, and snippets.

@vladdedita
Created November 29, 2023 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladdedita/8cce068d8ab107b684adc83262bf7cc8 to your computer and use it in GitHub Desktop.
Save vladdedita/8cce068d8ab107b684adc83262bf7cc8 to your computer and use it in GitHub Desktop.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authz) -> authz
.requestMatchers("/login", "/register")
.permitAll() // Login and register endpoints are accessible to allf
.anyRequest()
.authenticated() // Any other requests require authentication
)
.httpBasic(withDefaults()); // Enables basic authentication with default settings
return http.build(); // Builds and returns the security filter chain
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring()
.requestMatchers("/css/**", "/js/**", "/images/**"); // Ignores requests to static resources
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment