Skip to content

Commit

Permalink
chore: Remove User field default value
Browse files Browse the repository at this point in the history
  • Loading branch information
210-reverof committed Jun 15, 2024
1 parent 80f6ed8 commit 4e4ae0e
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 22 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("io.spring.dependency-management") version "1.1.5"
kotlin("jvm") version "1.9.24"
kotlin("plugin.spring") version "1.9.24"
kotlin("plugin.jpa") version "1.9.24"
}

java.sourceCompatibility = JavaVersion.VERSION_21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mashup.pic.auth.applicationService
import com.mashup.pic.auth.applicationService.dto.LoginServiceRequest
import com.mashup.pic.auth.controller.dto.LoginResponse
import com.mashup.pic.domain.user.User
import com.mashup.pic.security.jwt.JwtTokenUtil
import com.mashup.pic.security.jwt.JwtManager
import com.mashup.pic.domain.user.UserService
import com.mashup.pic.security.authentication.UserInfo
import com.mashup.pic.security.oidc.KakaoIdTokenValidator
Expand All @@ -13,9 +13,9 @@ import org.springframework.transaction.annotation.Transactional
@Service
@Transactional(readOnly = true)
class AuthApplicationService(
private val userService: UserService,
private val jwtTokenUtil: JwtTokenUtil,
private val idTokenValidator: KakaoIdTokenValidator
private val userService: UserService,
private val jwtTokenUtil: JwtManager,
private val idTokenValidator: KakaoIdTokenValidator
) {

@Transactional
Expand Down
10 changes: 5 additions & 5 deletions pic-api/src/main/kotlin/com/mashup/pic/config/SecurityConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.mashup.pic.config
import com.fasterxml.jackson.databind.ObjectMapper
import com.mashup.pic.security.handler.HttpStatusAccessDeniedHandler
import com.mashup.pic.security.handler.HttpStatusAuthenticationEntryPoint
import com.mashup.pic.security.jwt.JwtTokenFilter
import com.mashup.pic.security.jwt.JwtTokenUtil
import com.mashup.pic.security.jwt.JwtFilter
import com.mashup.pic.security.jwt.JwtManager
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
Expand All @@ -15,8 +15,8 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
@Configuration
@EnableWebSecurity
class SecurityConfig(
private val jwtTokenUtil: JwtTokenUtil,
private val objectMapper: ObjectMapper,
private val jwtTokenUtil: JwtManager,
private val objectMapper: ObjectMapper,
) {

@Bean
Expand All @@ -32,7 +32,7 @@ class SecurityConfig(
.requestMatchers(ADMIN_ENDPOINT_PATTERN).hasRole(ADMIN_ROLE)
.anyRequest().hasRole(MEMBER_ROLE)
}
.addFilterBefore(JwtTokenFilter(jwtTokenUtil, objectMapper), UsernamePasswordAuthenticationFilter::class.java)
.addFilterBefore(JwtFilter(jwtTokenUtil, objectMapper), UsernamePasswordAuthenticationFilter::class.java)
.exceptionHandling {
it.authenticationEntryPoint(HttpStatusAuthenticationEntryPoint())
it.accessDeniedHandler(HttpStatusAccessDeniedHandler())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import org.springframework.http.HttpHeaders
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.filter.OncePerRequestFilter

class JwtTokenFilter(
private val jwtTokenUtil: JwtTokenUtil,
private val objectMapper: ObjectMapper
class JwtFilter(
private val jwtTokenUtil: JwtManager,
private val objectMapper: ObjectMapper
) : OncePerRequestFilter() {

override fun doFilterInternal(request: HttpServletRequest, response: HttpServletResponse, filterChain: FilterChain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.security.Key
import java.util.Date

@Component
class JwtTokenUtil(
class JwtManager(
@Value("\${jwt.secret-key}") private val secretKey: String,
private val objectMapper: ObjectMapper
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class KakaoIdTokenValidator(

private fun extractKid(idToken: String): String {
val header = decodeHeader(idToken)
return header[KID_KEY] as String? ?: throw PicException.of(PicExceptionType.ARGUMENT_NOT_VALID,"Can't extract KID")
return header[KID_KEY] as? String ?: throw PicException.of(PicExceptionType.ARGUMENT_NOT_VALID,"Can't extract KID")
}

private fun getPublicKey(kid: String): Key {
Expand All @@ -70,7 +70,7 @@ class KakaoIdTokenValidator(
private fun getJwkByKid(kid: String): JwkKey {
return kakaoJwksClient.getJwks().getJwkKeyByKid(kid)
?: kakaoJwksClient.refreshAndGetJwks().getJwkKeyByKid(kid)
?: throw PicException.of(PicExceptionType.ARGUMENT_NOT_VALID,"Can't find the Jwk matching the KID")
?: throw PicException.of(PicExceptionType.ARGUMENT_NOT_VALID, "Can't find the Jwk matching the KID")
}

private fun decodePayload(idToken: String): Map<String, Any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ enum class PicExceptionType(
INVALID_USER_AUTH_TOKEN("Invalid JWT Token", "U002_INVALID_TOKEN", 400),
INVALID_TOKEN_BEARER("Invalid Token Bearer", "U003_INVALID_TOKEN", 400),


// COMMON
NOT_EXIST("존재하지 않습니다.", "C001_NOT_EXIST", 404),
INVALID_ACCESS("Invalid Access", "C003_INVALID_ACCESS", 403),
Expand All @@ -22,5 +21,10 @@ enum class PicExceptionType(
AUTHENTICATION_FAILURE("Authentication failed. Check login.", "C008_AUTHENTICATION_FAILURE", 401),
ARGUMENT_NOT_VALID("Method Argument Not Valid. Check argument validation.", "C009_ARGUMENT_NOT_VALID", 400),
SYSTEM_FAIL("Internal Server Error.", "C002_SYSTEM_FAIL", 500),

// EXTERNAL COMMUNICATION
EXTERNAL_COMMUNICATION_FAILURE("External communication failed.", "E001_EXTERNAL_COMMUNICATION_FAILURE", 500),
EXTERNAL_SERVICE_UNAVAILABLE("External service is unavailable.", "E002_EXTERNAL_SERVICE_UNAVAILABLE", 503),
EXTERNAL_SERVICE_TIMEOUT("External service call timed out.", "E003_EXTERNAL_SERVICE_TIMEOUT", 504),
;
}
4 changes: 4 additions & 0 deletions pic-domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
val mysqlConnectorVersion: String by project.extra

plugins {
id("kotlin-jpa")
}

dependencies {
implementation(project(":pic-common"))

Expand Down
9 changes: 5 additions & 4 deletions pic-domain/src/main/kotlin/com/mashup/pic/domain/user/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import org.hibernate.annotations.SQLRestriction
class User(

@Column(name = "oauth_id", nullable = false)
val oAuthId: Long = 0,
val oAuthId: Long,

@Column(name = "nickname", nullable = false)
val nickname: String = "",
val nickname: String,

@Column(name = "profileImage", nullable = false)
val profileImage: String = "",
val profileImage: String,

@ElementCollection(targetClass = UserRole::class, fetch = FetchType.EAGER)
@CollectionTable(name = "user_roles", joinColumns = [JoinColumn(name = "user_id")])
@Enumerated(EnumType.STRING)
@Column(name = "role")
@Column(name = "role", nullable = false)
val roles: Set<UserRole> = setOf(UserRole.MEMBER)

) : BaseEntity()

2 changes: 2 additions & 0 deletions pic-external/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dependencies {
implementation(project(":pic-common"))

implementation("org.springframework:spring-webmvc")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mashup.pic.external.kakao

import com.mashup.pic.common.exception.PicException
import com.mashup.pic.common.exception.PicExceptionType
import com.mashup.pic.external.common.JwksClient
import com.mashup.pic.external.common.response.JwksResponse
import org.springframework.beans.factory.annotation.Value
Expand All @@ -9,7 +11,6 @@ import org.springframework.http.HttpStatusCode
import org.springframework.stereotype.Component
import org.springframework.web.client.RestClient
import org.springframework.web.client.body
import java.io.IOException


@Component
Expand All @@ -33,7 +34,7 @@ class KakaoJwksClient(
.uri(jwkUri)
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError) { _, response ->
throw IOException("Error fetching JWKS: ${response.statusCode}")
throw PicException.of(PicExceptionType.EXTERNAL_COMMUNICATION_FAILURE, "Error fetching JWKS: ${response.statusCode}")
}
.body<JwksResponse>()!!
}
Expand Down

0 comments on commit 4e4ae0e

Please sign in to comment.