fix security configuration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dmitriy.churmeev
2026-03-29 14:35:58 +03:00
parent d6cd2139f6
commit fe085d2146
2 changed files with 26 additions and 27 deletions

View File

@@ -13,7 +13,6 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter
import org.springframework.security.web.SecurityFilterChain
@Configuration
@EnableWebSecurity
@EnableMethodSecurity(
@@ -46,30 +45,6 @@ class WebSecurityConfig () {
return http.build()
}
//
// // Конвертер JWT Authentication (извлекает роли из токена)
// private fun jwtAuthenticationConverter(): JwtAuthenticationConverter {
// val converter = JwtAuthenticationConverter()
//
// // Извлекаем роли из поля resource_access.test_client.roles
// val authoritiesExtractor = JwtGrantedAuthoritiesConverter()
// authoritiesExtractor.setAuthoritiesClaimName("resource_access.test_client.roles") // где лежат роли
// authoritiesExtractor.setAuthorityPrefix("ROLE_") // добавляем префикс ROLE_
//
// converter.setJwtGrantedAuthoritiesConverter(authoritiesExtractor)
//
//// // Дополнительно: проверяем, что роли не пустые
//// converter.setJwtGrantedAuthoritiesConverter { jwt ->
//// val authorities = authoritiesExtractor.convert(jwt)
//// if (authorities.isEmpty()) {
//// throw IllegalArgumentException("User has no roles assigned in token")
//// }
//// authorities
//// }
//
// return converter
// }
private fun jwtAuthenticationConverter(): JwtAuthenticationConverter {
val converter = JwtAuthenticationConverter()
@@ -100,4 +75,28 @@ class WebSecurityConfig () {
return converter
}
// // Конвертер JWT Authentication (извлекает роли из токена)
// private fun jwtAuthenticationConverter(): JwtAuthenticationConverter {
// val converter = JwtAuthenticationConverter()
//
// // Извлекаем роли из поля resource_access.test_client.roles
// val authoritiesExtractor = JwtGrantedAuthoritiesConverter()
// authoritiesExtractor.setAuthoritiesClaimName("resource_access.test_client.roles") // где лежат роли
// authoritiesExtractor.setAuthorityPrefix("ROLE_") // добавляем префикс ROLE_
//
// converter.setJwtGrantedAuthoritiesConverter(authoritiesExtractor)
//
//// // Дополнительно: проверяем, что роли не пустые
//// converter.setJwtGrantedAuthoritiesConverter { jwt ->
//// val authorities = authoritiesExtractor.convert(jwt)
//// if (authorities.isEmpty()) {
//// throw IllegalArgumentException("User has no roles assigned in token")
//// }
//// authorities
//// }
//
// return converter
// }
}

View File

@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
class TestController {
open class TestController {
@PreAuthorize("hasRole('ADMIN')")
@GetMapping("/test")