feat(ai-character): 관리자 기능 기반을 추가한다
This commit is contained in:
@@ -6,6 +6,9 @@ import kr.co.vividnext.sodalive.jwt.JwtAccessDeniedHandler
|
||||
import kr.co.vividnext.sodalive.jwt.JwtAuthenticationEntryPoint
|
||||
import kr.co.vividnext.sodalive.jwt.JwtFilter
|
||||
import kr.co.vividnext.sodalive.jwt.TokenProvider
|
||||
import kr.co.vividnext.sodalive.v2.admin.aicharacter.adapter.`in`.security.AiCharacterAdminAccessDeniedHandler
|
||||
import kr.co.vividnext.sodalive.v2.admin.aicharacter.adapter.`in`.security.AiCharacterAdminAuthenticationEntryPoint
|
||||
import org.springframework.beans.factory.ObjectProvider
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.http.HttpMethod
|
||||
@@ -27,7 +30,9 @@ class SecurityConfig(
|
||||
private val objectMapper: ObjectMapper,
|
||||
private val tokenProvider: TokenProvider,
|
||||
private val accessDeniedHandler: JwtAccessDeniedHandler,
|
||||
private val authenticationEntryPoint: JwtAuthenticationEntryPoint
|
||||
private val authenticationEntryPoint: JwtAuthenticationEntryPoint,
|
||||
private val aiCharacterAdminAuthenticationEntryPoint: ObjectProvider<AiCharacterAdminAuthenticationEntryPoint>,
|
||||
private val aiCharacterAdminAccessDeniedHandler: ObjectProvider<AiCharacterAdminAccessDeniedHandler>
|
||||
) {
|
||||
@Bean
|
||||
fun passwordEncoder(): PasswordEncoder {
|
||||
@@ -52,8 +57,22 @@ class SecurityConfig(
|
||||
.and()
|
||||
.csrf().disable()
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint(authenticationEntryPoint)
|
||||
.accessDeniedHandler(accessDeniedHandler)
|
||||
.authenticationEntryPoint { request, response, authException ->
|
||||
val adminEntryPoint = aiCharacterAdminAuthenticationEntryPoint.getIfAvailable()
|
||||
if (isAiCharacterAdminPath(request.requestURI) && adminEntryPoint != null) {
|
||||
adminEntryPoint.commence(request, response, authException)
|
||||
} else {
|
||||
authenticationEntryPoint.commence(request, response, authException)
|
||||
}
|
||||
}
|
||||
.accessDeniedHandler { request, response, accessDeniedException ->
|
||||
val adminAccessDeniedHandler = aiCharacterAdminAccessDeniedHandler.getIfAvailable()
|
||||
if (isAiCharacterAdminPath(request.requestURI) && adminAccessDeniedHandler != null) {
|
||||
adminAccessDeniedHandler.handle(request, response, accessDeniedException)
|
||||
} else {
|
||||
accessDeniedHandler.handle(request, response, accessDeniedException)
|
||||
}
|
||||
}
|
||||
.and()
|
||||
.headers()
|
||||
.frameOptions()
|
||||
@@ -100,6 +119,7 @@ class SecurityConfig(
|
||||
.antMatchers(HttpMethod.GET, "/api/chat/character/main").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/chat/room/list").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/chat/original/list").permitAll()
|
||||
.antMatchers(HttpMethod.PUT, "/audio-content/upload-complete").hasAnyRole("ADMIN", "BOT")
|
||||
.antMatchers(HttpMethod.POST, "/charge/payverse/webhook").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations").permitAll()
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/audio/recommendations").permitAll()
|
||||
@@ -110,8 +130,17 @@ class SecurityConfig(
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/home/on-air-lives").authenticated()
|
||||
// 페이지네이션 하위 경로(/lives, /debut-creators 등)는 인증 필수
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations/**").authenticated()
|
||||
.antMatchers(AI_CHARACTER_ADMIN_PATH_PREFIX, "$AI_CHARACTER_ADMIN_PATH_PREFIX/**").hasRole("ADMIN")
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun isAiCharacterAdminPath(requestUri: String): Boolean {
|
||||
return requestUri == AI_CHARACTER_ADMIN_PATH_PREFIX || requestUri.startsWith("$AI_CHARACTER_ADMIN_PATH_PREFIX/")
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val AI_CHARACTER_ADMIN_PATH_PREFIX = "/admin/ai-characters"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user