시큐리티 설정
유저 API - 로그인, 회원가입, 계정정보 추가
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package kr.co.vividnext.sodalive.common
|
||||
|
||||
data class ApiResponse<T>(
|
||||
val success: Boolean,
|
||||
val message: String? = null,
|
||||
val data: T? = null,
|
||||
val errorProperty: String? = null
|
||||
) {
|
||||
companion object {
|
||||
fun <T> ok(data: T? = null, message: String? = null) = ApiResponse(
|
||||
success = true,
|
||||
message = message,
|
||||
data = data
|
||||
)
|
||||
|
||||
fun error(message: String? = null, errorProperty: String? = null) = ApiResponse<Any>(
|
||||
success = false,
|
||||
message = message,
|
||||
errorProperty = errorProperty
|
||||
)
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package kr.co.vividnext.sodalive.common
|
||||
|
||||
import java.time.LocalDateTime
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.GenerationType
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.MappedSuperclass
|
||||
import javax.persistence.PrePersist
|
||||
import javax.persistence.PreUpdate
|
||||
|
||||
@MappedSuperclass
|
||||
abstract class BaseEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
var id: Long? = null
|
||||
|
||||
var createdAt: LocalDateTime? = null
|
||||
var updatedAt: LocalDateTime? = null
|
||||
|
||||
@PrePersist
|
||||
fun prePersist() {
|
||||
createdAt = LocalDateTime.now()
|
||||
updatedAt = LocalDateTime.now()
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
fun preUpdate() {
|
||||
updatedAt = LocalDateTime.now()
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
package kr.co.vividnext.sodalive.common
|
||||
|
||||
class SodaException(message: String, val errorProperty: String? = null) : RuntimeException(message)
|
@@ -0,0 +1,60 @@
|
||||
package kr.co.vividnext.sodalive.common
|
||||
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.dao.DataIntegrityViolationException
|
||||
import org.springframework.security.access.AccessDeniedException
|
||||
import org.springframework.security.authentication.BadCredentialsException
|
||||
import org.springframework.security.authentication.InternalAuthenticationServiceException
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice
|
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException
|
||||
|
||||
@RestControllerAdvice
|
||||
class SodaExceptionHandler {
|
||||
private val logger = LoggerFactory.getLogger(this::class.java)
|
||||
|
||||
@ExceptionHandler(SodaException::class)
|
||||
fun handleSudaException(e: SodaException) = run {
|
||||
logger.error("API error", e)
|
||||
ApiResponse.error(
|
||||
message = e.message,
|
||||
errorProperty = e.errorProperty
|
||||
)
|
||||
}
|
||||
|
||||
@ExceptionHandler(MaxUploadSizeExceededException::class)
|
||||
fun handleMaxUploadSizeExceededException(e: MaxUploadSizeExceededException) = run {
|
||||
logger.error("API error", e)
|
||||
ApiResponse.error(message = "파일용량은 최대 1024MB까지 저장할 수 있습니다.")
|
||||
}
|
||||
|
||||
@ExceptionHandler(AccessDeniedException::class)
|
||||
fun handleAccessDeniedException(e: AccessDeniedException) = run {
|
||||
logger.error("API error", e)
|
||||
ApiResponse.error(message = "권한이 없습니다.")
|
||||
}
|
||||
|
||||
@ExceptionHandler(InternalAuthenticationServiceException::class)
|
||||
fun handleInternalAuthenticationServiceException(e: InternalAuthenticationServiceException) = run {
|
||||
logger.error("API error", e)
|
||||
ApiResponse.error("로그인 정보를 확인해주세요.")
|
||||
}
|
||||
|
||||
@ExceptionHandler(BadCredentialsException::class)
|
||||
fun handleBadCredentialsException(e: BadCredentialsException) = run {
|
||||
logger.error("API error", e)
|
||||
ApiResponse.error("로그인 정보를 확인해주세요.")
|
||||
}
|
||||
|
||||
@ExceptionHandler(DataIntegrityViolationException::class)
|
||||
fun handleDataIntegrityViolationException(e: DataIntegrityViolationException) = run {
|
||||
logger.error("API error", e)
|
||||
ApiResponse.error("이미 등록되어 있습니다.")
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception::class)
|
||||
fun handleException(e: Exception) = run {
|
||||
logger.error("API error", e)
|
||||
ApiResponse.error("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user