JAVA-19354 Potential issue in A Quick Guide to Using Keycloak With Spring Boot article (#14537)

This commit is contained in:
anuragkumawat 2023-08-17 17:58:22 +05:30 committed by GitHub
parent e21b1e364e
commit 65159d313a
1 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package com.baeldung.keycloak;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@ -27,18 +28,30 @@ class SecurityConfig {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
@Order(1)
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
public SecurityFilterChain clientFilterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/customers*")
.hasRole("USER")
.antMatchers("/")
.permitAll()
.anyRequest()
.permitAll();
.authenticated();
http.oauth2Login()
.and()
.logout()
.addLogoutHandler(keycloakLogoutHandler)
.logoutSuccessUrl("/");
return http.build();
}
@Order(2)
@Bean
public SecurityFilterChain resourceServerFilterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/customers*")
.hasRole("USER")
.anyRequest()
.authenticated();
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt);
return http.build();
}