Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.jwt)
implementation(projects.infra)
implementation(projects.exception)
implementation(libs.maskIt)
implementation("org.springframework.boot:spring-boot-starter-security")
compileOnly(libs.bundles.kotlinLogging)
compileOnly(libs.bundles.kotlinxCoroutines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package com.inner.circle.core.service

import com.inner.circle.core.service.dto.UserCardDto
import com.inner.circle.core.usecase.UserCardUseCase
import com.inner.circle.exception.UserPaymentMethodException
import com.inner.circle.infra.port.UserCardPort
import net.gentledot.maskit.DataMasking
import net.gentledot.maskit.applications.modules.MaskingModule
import net.gentledot.maskit.models.DataTypes
import org.springframework.stereotype.Service
import com.inner.circle.infra.adaptor.dto.UserCardDto as InfraUserCardDto

Expand All @@ -26,20 +30,37 @@ internal class UserCardService(
}

override fun findByAccountId(accountId: Long): List<UserCardDto> {
val dataMasking = DataMasking.builder().build()
val cardMaskingModule = dataMasking.getModule(DataTypes.CREDIT_CARD)
val nameMaskingModule = dataMasking.getModule(DataTypes.NAME)
val infraUserCardDtoList = userCardPort.findByAccountId(accountId)

return infraUserCardDtoList
.map { infraUserCardDto ->
val maskedCardNumber = maskingCardNumber(cardMaskingModule, infraUserCardDto)
UserCardDto(
id = infraUserCardDto.id,
accountId = infraUserCardDto.accountId,
isRepresentative = infraUserCardDto.isRepresentative,
cardNumber = infraUserCardDto.cardNumber,
cardNumber = maskedCardNumber,
expirationPeriod = infraUserCardDto.expirationPeriod,
cvc = infraUserCardDto.cvc
cvc = nameMaskingModule.mask(infraUserCardDto.cvc, 1, 2)
)
}.toList()
}

private fun maskingCardNumber(
cardMaskingModule: MaskingModule,
infraUserCardDto: com.inner.circle.infra.adaptor.dto.UserCardDto
): String {
val cardNumber = infraUserCardDto.cardNumber
val split = cardNumber.split("-")
val masked = cardMaskingModule.mask(cardNumber)
if (split.size != 4) throw UserPaymentMethodException.InvalidCardNumberException(masked)
val firstNumberPart = split[0]
return """$firstNumberPart${masked.substring(4)}"""
Copy link
Copy Markdown
Contributor Author

@GentleDot GentleDot Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

차후에 maskIt version up 해서
1-2-3-4 <- 중에 원하는 구간을 마스킹하도록 변경해보겠습니다.

}

override fun findAll(): List<UserCardDto> {
val infraUserCardDtoList = userCardPort.findAll()
return infraUserCardDtoList
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.inner.circle.exception

sealed class UserPaymentMethodException(
status: HttpStatus,
override val message: String,
override val cause: Throwable? = null
) : AppException(status, message, cause) {
data class InvalidCardNumberException(
val cardNumber: String,
override val message: String = "Invalid card number: $cardNumber",
override val cause: Throwable? = null
) : UserPaymentMethodException(HttpStatus.BAD_REQUEST, message, cause)

data class InvalidCVCException(
override val message: String = "Invalid CVC value.",
override val cause: Throwable? = null
) : UserPaymentMethodException(HttpStatus.BAD_REQUEST, message, cause)

data class InvalidExpirationDateException(
val expirationDate: String,
override val message: String = "Invalid expiration date: $expirationDate",
override val cause: Throwable? = null
) : UserPaymentMethodException(HttpStatus.BAD_REQUEST, message, cause)
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ jwt = {module = "io.jsonwebtoken:jjwt", version = "0.12.6"}
logbackDiscordAppender = { module = "com.github.napstr:logback-discord-appender", version = "1.0.0" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version = "2.9.0" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version = "3.14.9" }
# maskit (beta)
maskIt = {module ="com.github.GentleDot:maskIt", version = "0.1.1"}

[bundles]
boms = ["kotlinxSerializationBom", "kotlinxCoroutinesBom", "kotestBom"]
Expand Down