Skip to content

Commit

Permalink
refactor: security 와 comment domain 패키지 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
van1164 committed Jun 5, 2024
1 parent 7d499ab commit d771dbe
Show file tree
Hide file tree
Showing 24 changed files with 44 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.van1164.comment

import com.van1164.common.domain.Comment
import com.van1164.security.PrincipalDetails
import com.van1164.common.domain.comment.Comment
import com.van1164.common.security.PrincipalDetails
import com.van1164.user.UserService
import mu.KotlinLogging
import org.springframework.http.ResponseEntity
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.security.core.context.ReactiveSecurityContextHolder
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.van1164.comment

import com.van1164.common.domain.Comment
import com.van1164.common.dto.CommentDTO
import org.springframework.data.r2dbc.repository.Query
import org.springframework.data.r2dbc.repository.R2dbcRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.van1164.comment

import com.van1164.common.domain.Comment
import com.van1164.common.dto.CommentDTO
import org.springframework.data.r2dbc.repository.Query
import com.van1164.common.domain.comment.Comment
import org.springframework.data.r2dbc.repository.R2dbcRepository
import org.springframework.data.relational.core.sql.LockMode
import org.springframework.data.relational.repository.Lock
import org.springframework.stereotype.Repository
import reactor.core.publisher.Mono

@Repository
interface CommentRepository : R2dbcRepository<Comment,Long> {
Expand Down
6 changes: 2 additions & 4 deletions comment/src/main/kotlin/com/van1164/comment/CommentService.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.van1164.comment

import com.van1164.comment.like.CommentLikeRepository
import com.van1164.common.domain.Comment
import com.van1164.common.domain.CommentLike
import com.van1164.common.domain.comment.Comment
import com.van1164.common.domain.comment.CommentLike
import com.van1164.common.util.Utils.logger
import com.van1164.main.video.VideoReadRepository
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Transactional
import reactor.core.publisher.Mono
import io.r2dbc.spi.IsolationLevel.*
import reactor.kotlin.core.publisher.toMono

@Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.van1164.comment.like

import com.van1164.common.domain.CommentLike
import com.van1164.common.domain.comment.CommentLike
import org.springframework.data.r2dbc.repository.R2dbcRepository
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class JwtServerAuthenticationConverter(
) : ServerAuthenticationConverter {
override fun convert(exchange: ServerWebExchange?): Mono<Authentication> {
return Mono.justOrEmpty(exchange?.request?.headers?.getFirst("authorization"))
.filter { it.startsWith("Bearer ") }.map { it.substring((7)) }
.filter{ it != null}
.filter { it!!.startsWith("Bearer ") }.map { it!!.substring((7)) }
.filter { jwtTokenProvider.validateToken(it) }
.flatMap { jwt -> jwtTokenProvider.getAuthentication(jwt) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package com.van1164.security

import com.nimbusds.oauth2.sdk.Role
import com.van1164.common.redis.RedisService
import com.van1164.common.security.PrincipalDetails
import com.van1164.common.security.TokenInfo
import com.van1164.user.UserService
import com.van1164.util.JWT_PREFIX
import io.jsonwebtoken.Claims
import io.jsonwebtoken.Jwts
import io.jsonwebtoken.SignatureAlgorithm
Expand All @@ -12,15 +13,11 @@ import io.jsonwebtoken.security.Keys
import lombok.RequiredArgsConstructor
import org.springframework.beans.factory.annotation.Value
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.core.Authentication
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.stereotype.Component
import reactor.core.publisher.Mono
import java.util.*
import kotlin.collections.LinkedHashMap

@Component
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.van1164.security

import com.van1164.common.redis.RedisR2dbcService
import com.van1164.common.security.PrincipalDetails
import com.van1164.common.util.Utils.logger
import com.van1164.user.UserService
import org.springframework.http.HttpStatus
import org.springframework.security.core.Authentication
import org.springframework.security.web.server.DefaultServerRedirectStrategy
import org.springframework.security.web.server.WebFilterExchange
import org.springframework.security.web.server.authentication.ServerAuthenticationSuccessHandler
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.van1164.security

import com.van1164.common.dto.*
import com.van1164.common.domain.UserR2dbc
import com.van1164.common.security.PrincipalDetails
import com.van1164.common.util.Utils.logger
import com.van1164.user.UserService
import org.springframework.security.oauth2.client.userinfo.DefaultReactiveOAuth2UserService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.van1164.security

import com.van1164.common.security.PrincipalDetails
import com.van1164.user.UserService
import lombok.RequiredArgsConstructor
import org.springframework.context.annotation.ComponentScan
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.van1164.common.domain

import com.van1164.common.domain.comment.Comment
import jakarta.persistence.*
import lombok.ToString
import java.util.*
Expand Down
13 changes: 13 additions & 0 deletions util/src/main/kotlin/com/van1164/common/domain/UserSubscribe.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.van1164.common.domain

import org.springframework.data.annotation.Id

data class UserSubscribe(

val fromUserId : String,

val toUserId : String,

@Id
val id : Long? = null
)
2 changes: 1 addition & 1 deletion util/src/main/kotlin/com/van1164/common/domain/Video.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.van1164.common.domain

import com.van1164.common.domain.Comment
import com.van1164.common.domain.comment.Comment
import jakarta.persistence.*
import lombok.ToString
import org.springframework.data.annotation.CreatedDate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.van1164.common.domain
package com.van1164.common.domain.comment


import org.springframework.data.annotation.CreatedDate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.van1164.common.domain
package com.van1164.common.domain.comment

import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.van1164.common.domain
package com.van1164.common.domain.comment

import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.van1164.common.dto

import com.van1164.common.domain.Comment
import com.van1164.common.domain.comment.Comment


data class VideoDetailResponseDTO(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.van1164.common.exception

import java.lang.Exception

class AlreadySubscribeException : Exception()
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.van1164.common.response

import com.van1164.common.domain.Comment
import com.van1164.common.domain.VideoR2dbc
import com.van1164.common.dto.CommentDTO

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.van1164.security
package com.van1164.common.security

import com.van1164.common.domain.UserR2dbc
import com.van1164.common.dto.OAuthProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.van1164.security
package com.van1164.common.security

data class TokenInfo(
val grantType : String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.van1164.video.like

import com.van1164.common.redis.RedisR2dbcRepository
import com.van1164.security.PrincipalDetails
import com.van1164.common.security.PrincipalDetails
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.van1164.video.upload
import com.van1164.security.PrincipalDetails
import com.van1164.common.security.PrincipalDetails
import com.van1164.common.dto.UploadVideoDataDTO
import com.van1164.common.dto.UploadVideoPartDTO
import io.swagger.v3.oas.annotations.Operation
Expand Down Expand Up @@ -49,10 +49,10 @@ class VideoController(
@ResponseBody
@PostMapping("/saveVideoData")
fun saveVideoData(
@AuthenticationPrincipal user : Mono<PrincipalDetails>,
@AuthenticationPrincipal principal : Mono<PrincipalDetails>,
@RequestBody uploadVideoDataDTO: UploadVideoDataDTO
): Mono<ResponseEntity<Boolean>> {
return user.flatMap { user->
return principal.flatMap { user->
videoService.saveVideoData(uploadVideoDataDTO.title,uploadVideoDataDTO.fileUUID,user.name)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.van1164.video.view.controller

import com.van1164.security.PrincipalDetails
import com.van1164.common.security.PrincipalDetails
import com.van1164.video.view.service.VideoViewService
import org.springframework.http.ResponseEntity
import org.springframework.security.core.annotation.AuthenticationPrincipal
Expand Down

0 comments on commit d771dbe

Please sign in to comment.