Skip to content

Commit

Permalink
feat: allow to only override security filterchain
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasLohoff committed Sep 5, 2023
1 parent d368194 commit 16335f9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ default void customHttpConfiguration(HttpSecurity http) throws Exception {
.ignoringRequestMatchers("/ws/**");
}

default void configure(HttpSecurity http) throws Exception {
customHttpConfiguration(http);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void init() {
}

@Override
public void customHttpConfiguration(HttpSecurity http) throws Exception {
public void configure(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((auths) -> auths
.requestMatchers("/webhooks/keycloak/**")
Expand All @@ -58,7 +58,7 @@ public void customHttpConfiguration(HttpSecurity http) throws Exception {
))
);

DefaultWebSecurityConfig.super.customHttpConfiguration(http);
customHttpConfiguration(http);

KeycloakJwtAuthenticationConverter authConverter = new KeycloakJwtAuthenticationConverter(
keycloakProperties.getClientId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public interface WebSecurityConfig {
@Bean
@ConditionalOnMissingBean
default SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
customHttpConfiguration(http);
configure(http);
return http.getOrBuild();
}

void configure(HttpSecurity http) throws Exception;

void customHttpConfiguration(HttpSecurity http) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,29 @@ public class InterceptorWebSecurityConfig implements DefaultWebSecurityConfig {
return StringUtils.equalsIgnoreCase(refererHeader, "Shogun-Manager-Client");
};

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
@Override
public void customHttpConfiguration(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.requestMatchers(
// Allow access to swagger interface
"/swagger-ui/index.html",
"/swagger-resources/**",
"/webjars/**",
"/v2/**",
"/csrf/**"
)
.permitAll()
.requestMatchers("/interceptorrules/**")
.hasRole("INTERCEPTOR_ADMIN")
.anyRequest()
.authenticated()
.and()
.httpBasic()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(csrfRequestMatcher);
return http.build();
.requestMatchers(
// Allow access to swagger interface
"/swagger-ui/index.html",
"/swagger-resources/**",
"/webjars/**",
"/v3/**",
"/csrf/**"
)
.permitAll()
.requestMatchers("/interceptorrules/**")
.hasRole("INTERCEPTOR_ADMIN")
.anyRequest()
.authenticated()
.and()
.httpBasic()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(csrfRequestMatcher);
}

}

0 comments on commit 16335f9

Please sign in to comment.