@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
CsrfTokenRequestAttributeHandler csrfRequestHandler = new CsrfTokenRequestAttributeHandler();
csrfRequestHandler.setCsrfRequestAttributeName("_csrf");
return http
.cors(Customizer.withDefaults())
.csrf(csrf -> csrf
.csrfTokenRequestHandler(csrfRequestHandler)
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
.authorizeHttpRequests(requests -> requests
.requestMatchers("auth/**").permitAll()
.anyRequest().authenticated())
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(jwt -> jwt
.jwtAuthenticationConverter(grantedAuthoritiesExtractor())))
.build();
}
< /code>
У меня также есть эта конфигурация, указывающая на мой KeyCloak для проверки токена.
security: oauth2: resourceserver: jwt: issuer-uri: 'http://localhost:8080/realms/core-creare'
Я пытаюсь обойти аутентификацию в пути "/auth", но .permitall () он не работает. Когда я делаю запрос на сообщение в «/auth», вернуться как 401 несанкционированный.
Я строю API с использованием Java 21, Spring Boot 3 и Spring Security 6 Authentication в KeyCloak 22. [code]@Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { CsrfTokenRequestAttributeHandler csrfRequestHandler = new CsrfTokenRequestAttributeHandler(); csrfRequestHandler.setCsrfRequestAttributeName("_csrf");
.build(); } < /code> У меня также есть эта конфигурация, указывающая на мой KeyCloak для проверки токена. security: oauth2: resourceserver: jwt: issuer-uri: 'http://localhost:8080/realms/core-creare'[/code] Я пытаюсь обойти аутентификацию в пути "/auth", но .permitall () он не работает. Когда я делаю запрос на сообщение в «/auth», вернуться как 401 несанкционированный.