Needed to add @Configuration annotation then matching started to hit to custom filterchain
@EnableWebSecurity
@ComponentScan("com.xxxx.nes.**")
@EntityScan("com.xxxx.nes.model.**")
@EnableJpaRepositories("com.xxxx.nes.model.**")
@Configuration <---
public class ResourceServeConfig {
@Bean
@Order(1)
public SecurityFilterChain actuatorEndpoints(HttpSecurity http) throws Exception {
http
.securityMatcher("/actuator/health")
.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.csrf(AbstractHttpConfigurer::disable);
return http.build();
}
@Bean
@Order(2)
public SecurityFilterChain securedEndpoints(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.ignoringRequestMatchers("/**/notifications/**"))
.authorizeHttpRequests(
auth ->
auth
.requestMatchers("/**/notifications/**")
.hasAuthority("SCOPE_notifications")
.anyRequest()
.authenticated()
)
.oauth2ResourceServer(
oauth -> oauth
.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtAuthenticationConverter()))
);
return http.build();
}
private JwtAuthenticationConverter jwtAuthenticationConverter() {
JwtGrantedAuthoritiesConverter converter = new JwtGrantedAuthoritiesConverter();
converter.setAuthorityPrefix("SCOPE_");
converter.setAuthoritiesClaimName("scope");
JwtAuthenticationConverter jwtConverter = new JwtAuthenticationConverter();
jwtConverter.setJwtGrantedAuthoritiesConverter(converter);
return jwtConverter;
}
}