Skip to content

Commit

Permalink
Merge pull request #733 from LukasLohoff/spring-security-deprecations
Browse files Browse the repository at this point in the history
Use lambda DSL for security filter chain
  • Loading branch information
LukasLohoff authored Sep 6, 2023
2 parents b1b44aa + 11044a2 commit 12f4e69
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ default void customHttpConfiguration(HttpSecurity http) throws Exception {
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
.authorizeHttpRequests()
.authorizeHttpRequests(authorize -> authorize
.requestMatchers(
"/",
"/auth/**",
Expand All @@ -55,15 +55,16 @@ default void customHttpConfiguration(HttpSecurity http) throws Exception {
.hasRole("ADMIN")
.anyRequest()
.authenticated()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRequestHandler(new CsrfTokenRequestAttributeHandler())
.ignoringRequestMatchers(csrfRequestMatcher)
.ignoringRequestMatchers("/graphql")
.ignoringRequestMatchers("/actuator/**")
.ignoringRequestMatchers("/sso/**")
.ignoringRequestMatchers("/ws/**");
)
.csrf(csrf -> csrf
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRequestHandler(new CsrfTokenRequestAttributeHandler())
.ignoringRequestMatchers(csrfRequestMatcher)
.ignoringRequestMatchers("/graphql")
.ignoringRequestMatchers("/actuator/**")
.ignoringRequestMatchers("/sso/**")
.ignoringRequestMatchers("/ws/**")
);
}

default void configure(HttpSecurity http) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,12 @@ public void configure(HttpSecurity http) throws Exception {
);

http
.csrf()
.csrf(csrf -> csrf
.ignoringRequestMatchers("/webhooks/**")
.and()
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(authConverter);

)
.oauth2ResourceServer(oauth -> oauth
.jwt(jwt -> jwt.jwtAuthenticationConverter(authConverter))
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*/
package de.terrestris.shogun.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.RequestMatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

import de.terrestris.shogun.config.DefaultWebSecurityConfig;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.util.matcher.RequestMatcher;

Expand All @@ -36,7 +35,7 @@ public class InterceptorWebSecurityConfig implements DefaultWebSecurityConfig {
@Override
public void customHttpConfiguration(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.authorizeHttpRequests(authorize -> authorize
.requestMatchers(
// Allow access to swagger interface
"/swagger-ui/index.html",
Expand All @@ -50,12 +49,12 @@ public void customHttpConfiguration(HttpSecurity http) throws Exception {
.hasRole("INTERCEPTOR_ADMIN")
.anyRequest()
.authenticated()
.and()
.httpBasic()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(csrfRequestMatcher);
)
.httpBasic(Customizer.withDefaults())
.csrf(csrf -> csrf
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(csrfRequestMatcher)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
Expand Down

0 comments on commit 12f4e69

Please sign in to comment.