From 0258f8d1a0baf74c3edba409d5cf06099e0cf16a Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Tue, 3 Dec 2024 06:25:18 +0900 Subject: [PATCH] =?UTF-8?q?fingerprint=20=EA=B4=80=EB=A0=A8=20=EB=8F=99?= =?UTF-8?q?=EC=9E=91=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../sulmun2yong/ai/service/GenerateService.kt | 5 +- .../global/util/FakeFingerprintApi.kt | 30 ----------- .../sulmun2yong/global/util/FingerprintApi.kt | 54 ------------------- .../FakeSurveyResponseController.kt | 27 ---------- .../doc/FakeSurveyResponseApiDoc.kt | 22 -------- .../service/FakeSurveyResponseService.kt | 49 ----------------- .../survey/service/SurveyResponseService.kt | 5 +- 8 files changed, 5 insertions(+), 189 deletions(-) delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt delete mode 100644 src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt diff --git a/build.gradle.kts b/build.gradle.kts index 52bfdbfa..0dab27c4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -36,7 +36,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-actuator") // fingerprint - implementation("com.github.fingerprintjs:fingerprint-pro-server-api-java-sdk:v6.0.0") + // implementation("com.github.fingerprintjs:fingerprint-pro-server-api-java-sdk:v6.0.0") // security implementation("org.springframework.boot:spring-boot-starter-security") diff --git a/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt b/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt index 2f33fa25..29cbc5b3 100644 --- a/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt +++ b/src/main/kotlin/com/sbl/sulmun2yong/ai/service/GenerateService.kt @@ -7,7 +7,6 @@ import com.sbl.sulmun2yong.ai.domain.AIGenerateLog import com.sbl.sulmun2yong.ai.dto.request.DemoSurveyGenerationWithFileUrlRequest import com.sbl.sulmun2yong.ai.dto.request.SurveyGenerationWithFileUrlRequest import com.sbl.sulmun2yong.ai.dto.response.AISurveyGenerationResponse -import com.sbl.sulmun2yong.global.fingerprint.FingerprintApi import com.sbl.sulmun2yong.global.util.validator.FileUrlValidator import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter import com.sbl.sulmun2yong.survey.domain.Survey @@ -21,7 +20,7 @@ class GenerateService( private val surveyAdapter: SurveyAdapter, private val aiDemoCountRedisAdapter: AIDemoCountRedisAdapter, private val aiGenerateLogAdapter: AIGenerateLogAdapter, - val fingerprintApi: FingerprintApi, + // val fingerprintApi: FingerprintApi, ) { fun generateSurveyWithFileUrl( surveyGenerationWithFileUrlRequest: SurveyGenerationWithFileUrlRequest, @@ -74,7 +73,7 @@ class GenerateService( val userPrompt = demoSurveyGenerationWithFileUrlRequest.userPrompt validateFileUrl(fileUrl) - fingerprintApi.validateVisitorId(visitorId) + // fingerprintApi.validateVisitorId(visitorId) aiDemoCountRedisAdapter.incrementOrCreate(visitorId) val surveyId = UUID.randomUUID() diff --git a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt b/src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt deleted file mode 100644 index 551aa80e..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FakeFingerprintApi.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.sbl.sulmun2yong.global.util - -import jakarta.ws.rs.client.Client -import jakarta.ws.rs.client.ClientBuilder -import jakarta.ws.rs.client.Invocation -import jakarta.ws.rs.core.MediaType -import jakarta.ws.rs.core.Response -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Component - -@ConditionalOnProperty(prefix = "fingerprint", name = ["mocking-server-url"], matchIfMissing = false) -@Component -class FakeFingerprintApi( - @Value("\${fingerprint.mocking-server-url}") - private val mockingServerUrl: String, -) { - private val url = "$mockingServerUrl/finger-print" - private val client: Client = ClientBuilder.newClient() - - fun callFingerPrintApi(visitorId: String) { - val target = client.target(url) - val invocationBuilder: Invocation.Builder = target.request(MediaType.APPLICATION_JSON_TYPE) - val response: Response = invocationBuilder.get() - - if (response.status != Response.Status.OK.statusCode) { - throw IllegalStateException("Fake 핑거프린트 API를 호출할 수 없습니다.") - } - } -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt b/src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt deleted file mode 100644 index 014aa85a..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/global/util/FingerprintApi.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.sbl.sulmun2yong.global.fingerprint - -import com.fingerprint.api.FingerprintApi -import com.fingerprint.model.BotdDetectionResult -import com.fingerprint.model.EventResponse -import com.fingerprint.model.ProductsResponse -import com.fingerprint.model.Response -import com.fingerprint.model.ResponseVisits -import com.fingerprint.sdk.ApiClient -import com.fingerprint.sdk.Configuration -import com.fingerprint.sdk.Region -import com.sbl.sulmun2yong.global.util.exception.UncleanVisitorException -import org.springframework.beans.factory.annotation.Value -import org.springframework.stereotype.Component - -@Component -class FingerprintApi( - @Value("\${fingerprint.secret-key}") - private val secretKey: String, -) { - private val client: ApiClient = - Configuration.getDefaultApiClient( - secretKey, - Region.ASIA, - ) - val api = FingerprintApi(client) - - fun validateVisitorId(visitorId: String) { - val visits = getVisits(visitorId) - if (visits.isNullOrEmpty()) { - throw Exception("Invalid visitorId") - } - checkIsVisitorClean(visits) - } - - private fun getVisits(visitorId: String): MutableList? { - val response: Response = api.getVisits(visitorId, null, null, 1, null, null) - return response.visits - } - - private fun getEvent(requestId: String): ProductsResponse { - val response: EventResponse = api.getEvent(requestId) - return response.products - } - - private fun checkIsVisitorClean(visits: MutableList) { - val product = getEvent(visits[0].requestId) - if (product.tampering.data.result == true || - product.botd.data.bot.result !== BotdDetectionResult.ResultEnum.NOT_DETECTED - ) { - throw UncleanVisitorException() - } - } -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt deleted file mode 100644 index 8cbdf52a..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/FakeSurveyResponseController.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.sbl.sulmun2yong.survey.controller - -import com.sbl.sulmun2yong.survey.controller.doc.FakeSurveyResponseApiDoc -import com.sbl.sulmun2yong.survey.dto.request.SurveyResponseRequest -import com.sbl.sulmun2yong.survey.service.FakeSurveyResponseService -import jakarta.validation.Valid -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController -import java.util.UUID - -@ConditionalOnProperty(prefix = "fingerprint", name = ["mocking-server-url"], matchIfMissing = false) -@RestController -@RequestMapping("/api/v1/surveys/response/fake") -class FakeSurveyResponseController( - private val fakeSurveyResponseService: FakeSurveyResponseService, -) : FakeSurveyResponseApiDoc { - @PostMapping("/{survey-id}") - override fun fakeResponseToSurvey( - @PathVariable("survey-id") surveyId: UUID, - @Valid @RequestBody surveyResponseRequest: SurveyResponseRequest, - ) = ResponseEntity.ok(fakeSurveyResponseService.fakeResponseToSurvey(surveyId, surveyResponseRequest)) -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt deleted file mode 100644 index d23f5869..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/controller/doc/FakeSurveyResponseApiDoc.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.sbl.sulmun2yong.survey.controller.doc - -import com.sbl.sulmun2yong.survey.dto.request.SurveyResponseRequest -import com.sbl.sulmun2yong.survey.dto.response.SurveyParticipantResponse -import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.tags.Tag -import jakarta.validation.Valid -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.PathVariable -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import java.util.UUID - -@Tag(name = "FakeSurveyResponse", description = "테스트용 설문 응답 관련 API") -interface FakeSurveyResponseApiDoc { - @Operation(summary = "Fingerprint Mocking 서버를 사용하는 설문 응답 API") - @PostMapping - fun fakeResponseToSurvey( - @PathVariable("survey-id") surveyId: UUID, - @Valid @RequestBody surveyResponseRequest: SurveyResponseRequest, - ): ResponseEntity -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt deleted file mode 100644 index 62720e24..00000000 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/FakeSurveyResponseService.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.sbl.sulmun2yong.survey.service - -import com.sbl.sulmun2yong.global.util.FakeFingerprintApi -import com.sbl.sulmun2yong.survey.adapter.ParticipantAdapter -import com.sbl.sulmun2yong.survey.adapter.ResponseAdapter -import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter -import com.sbl.sulmun2yong.survey.domain.Participant -import com.sbl.sulmun2yong.survey.dto.request.SurveyResponseRequest -import com.sbl.sulmun2yong.survey.dto.response.SurveyParticipantResponse -import com.sbl.sulmun2yong.survey.exception.AlreadyParticipatedException -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.stereotype.Service -import java.util.UUID - -@ConditionalOnProperty(prefix = "fingerprint", name = ["mocking-server-url"], matchIfMissing = false) -@Service -class FakeSurveyResponseService( - val surveyAdapter: SurveyAdapter, - val participantAdapter: ParticipantAdapter, - val responseAdapter: ResponseAdapter, - val fakeFingerprintApi: FakeFingerprintApi, -) { - fun fakeResponseToSurvey( - surveyId: UUID, - surveyResponseRequest: SurveyResponseRequest, - ): SurveyParticipantResponse { - validateIsAlreadyParticipated(surveyId, surveyResponseRequest.visitorId) - // 가짜 Fingerprint API를 호출하는 부분을 제외하고는 SurveyResponseService responseToSurvey 동일 - fakeFingerprintApi.callFingerPrintApi(surveyResponseRequest.visitorId) - val visitorId = surveyResponseRequest.visitorId - val survey = surveyAdapter.getSurvey(surveyId) - val surveyResponse = surveyResponseRequest.toDomain(surveyId) - survey.validateResponse(surveyResponse) - val participant = Participant.create(visitorId, surveyId, null) - participantAdapter.insert(participant) - responseAdapter.insertSurveyResponse(surveyResponse, participant.id) - return SurveyParticipantResponse(participant.id, survey.isImmediateDraw()) - } - - private fun validateIsAlreadyParticipated( - surveyId: UUID, - visitorId: String, - ) { - val participant = participantAdapter.findBySurveyIdAndVisitorId(surveyId, visitorId) - participant?.let { - throw AlreadyParticipatedException() - } - } -} diff --git a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt b/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt index 975e5158..52da5442 100644 --- a/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt +++ b/src/main/kotlin/com/sbl/sulmun2yong/survey/service/SurveyResponseService.kt @@ -1,6 +1,5 @@ package com.sbl.sulmun2yong.survey.service -import com.sbl.sulmun2yong.global.fingerprint.FingerprintApi import com.sbl.sulmun2yong.survey.adapter.ParticipantAdapter import com.sbl.sulmun2yong.survey.adapter.ResponseAdapter import com.sbl.sulmun2yong.survey.adapter.SurveyAdapter @@ -16,7 +15,7 @@ class SurveyResponseService( val surveyAdapter: SurveyAdapter, val participantAdapter: ParticipantAdapter, val responseAdapter: ResponseAdapter, - val fingerprintApi: FingerprintApi, + // val fingerprintApi: FingerprintApi, ) { // TODO: 트랜잭션 처리 추가하기 fun responseToSurvey( @@ -24,7 +23,7 @@ class SurveyResponseService( surveyResponseRequest: SurveyResponseRequest, ): SurveyParticipantResponse { validateIsAlreadyParticipated(surveyId, surveyResponseRequest.visitorId) - fingerprintApi.validateVisitorId(surveyResponseRequest.visitorId) + // fingerprintApi.validateVisitorId(surveyResponseRequest.visitorId) val visitorId = surveyResponseRequest.visitorId val survey = surveyAdapter.getSurvey(surveyId) val surveyResponse = surveyResponseRequest.toDomain(surveyId)