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:
@@ -26,6 +26,8 @@ class WebSecurityConfig () {
|
|||||||
@Bean
|
@Bean
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun filterChain(http: HttpSecurity): SecurityFilterChain? {
|
fun filterChain(http: HttpSecurity): SecurityFilterChain? {
|
||||||
|
logger.info("=== INITIALIZING SECURITY FILTER CHAIN ===")
|
||||||
|
|
||||||
http
|
http
|
||||||
// .authorizeHttpRequests { auth ->
|
// .authorizeHttpRequests { auth ->
|
||||||
//
|
//
|
||||||
@@ -34,16 +36,21 @@ class WebSecurityConfig () {
|
|||||||
// //auth.anyRequest().authenticated()
|
// //auth.anyRequest().authenticated()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
.oauth2ResourceServer { oauth2 ->
|
.oauth2ResourceServer { oauth2 -> {
|
||||||
|
logger.info("=== oauth2ResourceServer ===")
|
||||||
// oauth2!!.jwt(Customizer.withDefaults())
|
// oauth2!!.jwt(Customizer.withDefaults())
|
||||||
// добавляем конвертер для извлечения ролей
|
// добавляем конвертер для извлечения ролей
|
||||||
oauth2.jwt { jwt ->
|
oauth2.jwt { jwt ->
|
||||||
|
{
|
||||||
|
logger.info("=== jwtAuthenticationConverter() ==="+jwtAuthenticationConverter())
|
||||||
jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())
|
jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())
|
||||||
}
|
}
|
||||||
} // проверка JWT токен
|
}
|
||||||
.sessionManagement { session: SessionManagementConfigurer<HttpSecurity?>? ->
|
}} // проверка JWT токен
|
||||||
|
.sessionManagement {{ session: SessionManagementConfigurer<HttpSecurity?>? ->
|
||||||
|
logger.info("=== sessionManagement ===")
|
||||||
session!!.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
session!!.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
} // без сессий
|
}} // без сессий
|
||||||
.csrf { csrf: CsrfConfigurer<HttpSecurity?>? -> csrf!!.disable() } // отключаем CSRF для API
|
.csrf { csrf: CsrfConfigurer<HttpSecurity?>? -> csrf!!.disable() } // отключаем CSRF для API
|
||||||
|
|
||||||
return http.build()
|
return http.build()
|
||||||
@@ -57,7 +64,7 @@ class WebSecurityConfig () {
|
|||||||
|
|
||||||
// Извлекаем роли из resource_access.test_client.roles
|
// Извлекаем роли из resource_access.test_client.roles
|
||||||
val resourceAccess = jwt.claims["resource_access"] as? Map<*, *>
|
val resourceAccess = jwt.claims["resource_access"] as? Map<*, *>
|
||||||
logger.info("Roles! "+resourceAccess)
|
logger.info("Roles1! "+resourceAccess)
|
||||||
val clientAccess = resourceAccess?.get("test_client") as? Map<*, *>
|
val clientAccess = resourceAccess?.get("test_client") as? Map<*, *>
|
||||||
val clientRoles = clientAccess?.get("roles") as? List<*>
|
val clientRoles = clientAccess?.get("roles") as? List<*>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user