Skip to content

Instantly share code, notes, and snippets.

@sandeeppagatur
Created February 8, 2023 13:51
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 sandeeppagatur/323cf9680320491de016a67e3b5d924f to your computer and use it in GitHub Desktop.
Save sandeeppagatur/323cf9680320491de016a67e3b5d924f to your computer and use it in GitHub Desktop.
@Configuration
public class BasicAuthSecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeHttpRequests((authorize) -> authorize.requestMatchers(new AntPathRequestMatcher("/url")).hasRole(ROLE).anyRequest().authenticated())
.httpBasic(Customizer.withDefaults()).exceptionHandling()
.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED));
return http.build();
}
spring.security.user.name=
spring.security.user.password=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment