fix security configuration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -13,7 +13,6 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority
|
|||||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter
|
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter
|
||||||
import org.springframework.security.web.SecurityFilterChain
|
import org.springframework.security.web.SecurityFilterChain
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@EnableMethodSecurity(
|
@EnableMethodSecurity(
|
||||||
@@ -46,30 +45,6 @@ class WebSecurityConfig () {
|
|||||||
|
|
||||||
return http.build()
|
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 {
|
private fun jwtAuthenticationConverter(): JwtAuthenticationConverter {
|
||||||
val converter = JwtAuthenticationConverter()
|
val converter = JwtAuthenticationConverter()
|
||||||
@@ -100,4 +75,28 @@ class WebSecurityConfig () {
|
|||||||
return converter
|
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
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController
|
|||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
class TestController {
|
open class TestController {
|
||||||
|
|
||||||
@PreAuthorize("hasRole('ADMIN')")
|
@PreAuthorize("hasRole('ADMIN')")
|
||||||
@GetMapping("/test")
|
@GetMapping("/test")
|
||||||
|
|||||||
Reference in New Issue
Block a user