feat(creator-admin): 댓글 관리 공통 계약과 인증 경계를 추가한다
This commit is contained in:
@@ -10,9 +10,14 @@ import kr.co.vividnext.sodalive.jwt.TokenProvider
|
||||
import kr.co.vividnext.sodalive.v2.api.admin.aicharacter.error.AiCharacterAdminErrorResponseWriter
|
||||
import kr.co.vividnext.sodalive.v2.api.admin.aicharacter.error.AiCharacterAdminExceptionHandler
|
||||
import kr.co.vividnext.sodalive.v2.api.admin.aicharacter.security.AiCharacterAdminSecurityErrorHandler
|
||||
import kr.co.vividnext.sodalive.v2.creator.admin.commentmanagement.adapter.`in`.web.CREATOR_ADMIN_COMMENT_MANAGEMENT_BASE_PATH
|
||||
import kr.co.vividnext.sodalive.v2.creator.admin.commentmanagement.adapter.`in`.web.CreatorAdminCommentErrorResponseWriter
|
||||
import kr.co.vividnext.sodalive.v2.creator.admin.commentmanagement.adapter.`in`.web.CreatorAdminCommentExceptionHandler
|
||||
import kr.co.vividnext.sodalive.v2.creator.admin.commentmanagement.adapter.`in`.web.CreatorAdminCommentSecurityErrorHandler
|
||||
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.core.Ordered
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.http.HttpStatus
|
||||
@@ -31,13 +36,20 @@ import org.springframework.security.web.access.RequestMatcherDelegatingAccessDen
|
||||
import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.OrRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher
|
||||
import org.springframework.web.HttpRequestHandler
|
||||
import org.springframework.web.servlet.handler.HandlerExceptionResolverComposite
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
@Import(
|
||||
CreatorAdminCommentErrorResponseWriter::class,
|
||||
CreatorAdminCommentSecurityErrorHandler::class,
|
||||
CreatorAdminCommentExceptionHandler::class
|
||||
)
|
||||
class SecurityConfig(
|
||||
private val objectMapper: ObjectMapper,
|
||||
private val tokenProvider: TokenProvider,
|
||||
@@ -113,18 +125,23 @@ class SecurityConfig(
|
||||
fun filterChain(
|
||||
http: HttpSecurity,
|
||||
aiCharacterAdminSecurityErrorHandler: AiCharacterAdminSecurityErrorHandler,
|
||||
aiCharacterAdminExceptionHandler: AiCharacterAdminExceptionHandler
|
||||
aiCharacterAdminExceptionHandler: AiCharacterAdminExceptionHandler,
|
||||
creatorAdminCommentSecurityErrorHandler: CreatorAdminCommentSecurityErrorHandler,
|
||||
creatorAdminCommentExceptionHandler: CreatorAdminCommentExceptionHandler
|
||||
): SecurityFilterChain {
|
||||
val jwtFilter = JwtFilter(tokenProvider)
|
||||
val aiCharacterAdminRequestMatcher = AntPathRequestMatcher(AI_CHARACTER_ADMIN_PATH)
|
||||
val creatorAdminCommentRequestMatcher = AntPathRequestMatcher("$CREATOR_ADMIN_COMMENT_MANAGEMENT_BASE_PATH/**")
|
||||
val authenticationEntryPoints = linkedMapOf<RequestMatcher, AuthenticationEntryPoint>(
|
||||
aiCharacterAdminRequestMatcher to aiCharacterAdminSecurityErrorHandler
|
||||
aiCharacterAdminRequestMatcher to aiCharacterAdminSecurityErrorHandler,
|
||||
creatorAdminCommentRequestMatcher to creatorAdminCommentSecurityErrorHandler
|
||||
)
|
||||
val delegatingAuthenticationEntryPoint = DelegatingAuthenticationEntryPoint(authenticationEntryPoints).apply {
|
||||
setDefaultEntryPoint(authenticationEntryPoint)
|
||||
}
|
||||
val accessDeniedHandlers = linkedMapOf<RequestMatcher, AccessDeniedHandler>(
|
||||
aiCharacterAdminRequestMatcher to aiCharacterAdminSecurityErrorHandler
|
||||
aiCharacterAdminRequestMatcher to aiCharacterAdminSecurityErrorHandler,
|
||||
creatorAdminCommentRequestMatcher to creatorAdminCommentSecurityErrorHandler
|
||||
)
|
||||
val delegatingAccessDeniedHandler = RequestMatcherDelegatingAccessDeniedHandler(
|
||||
accessDeniedHandlers,
|
||||
@@ -150,9 +167,11 @@ class SecurityConfig(
|
||||
.addFilterBefore(
|
||||
ExceptionHandlerFilter(
|
||||
objectMapper,
|
||||
aiCharacterAdminRequestMatcher,
|
||||
aiCharacterAdminSecurityErrorHandler,
|
||||
aiCharacterAdminExceptionHandler
|
||||
OrRequestMatcher(aiCharacterAdminRequestMatcher, creatorAdminCommentRequestMatcher),
|
||||
delegatingAuthenticationEntryPoint,
|
||||
HandlerExceptionResolverComposite().apply {
|
||||
setExceptionResolvers(listOf(aiCharacterAdminExceptionHandler, creatorAdminCommentExceptionHandler))
|
||||
}
|
||||
),
|
||||
JwtFilter::class.java
|
||||
)
|
||||
@@ -217,6 +236,13 @@ class SecurityConfig(
|
||||
"principal instanceof T(kr.co.vividnext.sodalive.member.MemberAdapter) and " +
|
||||
"principal.member.role == T(kr.co.vividnext.sodalive.member.MemberRole).ADMIN"
|
||||
)
|
||||
.antMatchers("$CREATOR_ADMIN_COMMENT_MANAGEMENT_BASE_PATH/**")
|
||||
.access(
|
||||
"hasRole('CREATOR') and " +
|
||||
"principal instanceof T(kr.co.vividnext.sodalive.member.MemberAdapter) and " +
|
||||
"principal.member.role == T(kr.co.vividnext.sodalive.member.MemberRole).CREATOR and " +
|
||||
"principal.member.isActive"
|
||||
)
|
||||
// 페이지네이션 하위 경로(/lives, /debut-creators 등)는 인증 필수
|
||||
.antMatchers(HttpMethod.GET, "/api/v2/home/recommendations/**").authenticated()
|
||||
.anyRequest().authenticated()
|
||||
|
||||
Reference in New Issue
Block a user