Skip to content

Commit 466f54c

Browse files
authored
Selc 1576 (#165)
* fix: Adding new Token Verify API * fix: Token Verify API
1 parent ec26097 commit 466f54c

File tree

5 files changed

+91
-4
lines changed

5 files changed

+91
-4
lines changed

src/main/resources/interface-specification.yml

+52
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,48 @@ paths:
862862
application/problem+json:
863863
schema:
864864
$ref: '#/components/schemas/Problem'
865+
/tokens/{tokenId}/verify:
866+
post:
867+
security: [{}]
868+
tags:
869+
- public
870+
summary: Verify if the token is already consumed
871+
description: Return ok
872+
operationId: verifyToken
873+
parameters:
874+
- name: tokenId
875+
in: path
876+
description: The token id to verify
877+
required: true
878+
schema:
879+
description: to be defined
880+
type: string
881+
format: uuid
882+
responses:
883+
'200':
884+
description: successful operation
885+
content:
886+
application/json:
887+
schema:
888+
$ref: '#/components/schemas/TokenId'
889+
'400':
890+
description: Invalid ID supplied
891+
content:
892+
application/problem+json:
893+
schema:
894+
$ref: '#/components/schemas/Problem'
895+
'404':
896+
description: Token not found
897+
content:
898+
application/problem+json:
899+
schema:
900+
$ref: '#/components/schemas/Problem'
901+
'409':
902+
description: Token already consumed
903+
content:
904+
application/problem+json:
905+
schema:
906+
$ref: '#/components/schemas/Problem'
865907
/status:
866908
get:
867909
security:
@@ -1392,6 +1434,16 @@ components:
13921434
- zipCode
13931435
- billing
13941436
additionalProperties: false
1437+
TokenId:
1438+
type: object
1439+
properties:
1440+
id:
1441+
type: string
1442+
format: uuid
1443+
example: 97c0f418-bcb3-48d4-825a-fe8b29ae68e5
1444+
additionalProperties: false
1445+
required:
1446+
- id
13951447
securitySchemes:
13961448
bearerAuth:
13971449
type: http

src/main/scala/it/pagopa/interop/partyprocess/api/impl/PublicApiMarshallerImpl.scala

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ object PublicApiMarshallerImpl extends PublicApiMarshaller with SprayJsonSupport
1010

1111
override implicit def toEntityMarshallerProblem: ToEntityMarshaller[Problem] = sprayJsonMarshaller[Problem]
1212

13+
override implicit def toEntityMarshallerTokenId: ToEntityMarshaller[TokenId] = sprayJsonMarshaller[TokenId]
1314
}

src/main/scala/it/pagopa/interop/partyprocess/api/impl/PublicApiServiceImpl.scala

+33-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import it.pagopa.interop.commons.files.service.FileManager
1010
import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog}
1111
import it.pagopa.interop.commons.mail.model.PersistedTemplate
1212
import it.pagopa.interop.commons.utils.TypeConversions._
13-
import it.pagopa.interop.commons.utils.errors.GenericComponentErrors.ResourceConflictError
13+
import it.pagopa.interop.commons.utils.errors.GenericComponentErrors.{ResourceConflictError, ResourceNotFoundError}
1414
import it.pagopa.interop.partymanagement.client.model.{PartyRole => PartyMgmtRole, Problem => _}
1515
import it.pagopa.interop.partyprocess.api.PublicApiService
1616
import it.pagopa.interop.partyprocess.common.system.ApplicationConfiguration
@@ -82,16 +82,16 @@ class PublicApiServiceImpl(
8282

8383
validator <- signatureService.createDocumentValidator(Files.readAllBytes(contract._2.toPath))
8484
_ <- SignatureValidationService.validateSignature(signatureValidationService.isDocumentSigned(validator))
85-
_ <- SignatureValidationService.validateSignature(signatureValidationService.verifyOriginalDocument(validator))
85+
_ <- SignatureValidationService.validateSignature(signatureValidationService.verifyOriginalDocument(validator))
8686
reports <- signatureValidationService.validateDocument(validator)
8787
_ <- SignatureValidationService.validateSignature(
8888
signatureValidationService.verifySignatureForm(validator),
8989
signatureValidationService.verifySignature(reports),
9090
signatureValidationService.verifyDigest(validator, token.checksum),
9191
signatureValidationService.verifyManagerTaxCode(reports, legalUsers)
9292
)
93-
logo <- getLogoFile(ApplicationConfiguration.emailLogoPath)
94-
product <- productManagementService.getProductById(institutionId.head.product)
93+
logo <- getLogoFile(ApplicationConfiguration.emailLogoPath)
94+
product <- productManagementService.getProductById(institutionId.head.product)
9595
onboardingMailParameters <- getOnboardingMailParameters(product.name)
9696
emails = legalEmails ++ institutionEmail.toSeq
9797
_ <- sendOnboardingCompleteEmail(emails, onboardingMailParameters, logo)
@@ -153,7 +153,36 @@ class PublicApiServiceImpl(
153153
logger.error("Error while invalidating onboarding for token identified with {}", tokenId, ex)
154154
val errorResponse: Problem = problemOf(StatusCodes.BadRequest, InvalidateOnboardingError)
155155
invalidateOnboarding400(errorResponse)
156+
}
157+
}
158+
159+
/**
160+
* Code: 200, Message: successful operation, DataType: TokenId
161+
* Code: 400, Message: Invalid ID supplied, DataType: Problem
162+
* Code: 404, Message: Token not found, DataType: Problem
163+
* Code: 409, Message: Token already consumed, DataType: Problem
164+
*/
165+
override def verifyToken(tokenId: String)(implicit
166+
toEntityMarshallerTokenId: ToEntityMarshaller[TokenId],
167+
toEntityMarshallerProblem: ToEntityMarshaller[Problem],
168+
contexts: Seq[(String, String)]
169+
): Route = {
170+
val result: Future[TokenId] = for {
171+
tokenIdUUID <- tokenId.toFutureUUID
172+
token <- partyManagementService.verifyToken(tokenIdUUID)
173+
} yield TokenId(id = token.id)
156174

175+
onComplete(result) {
176+
case Success(tokenId) => verifyToken200(tokenId)
177+
case Failure(ex: ResourceNotFoundError) =>
178+
logger.error(s"Token not found", ex)
179+
verifyToken404(problemOf(StatusCodes.NotFound, ex))
180+
case Failure(ex: ResourceConflictError) =>
181+
logger.error(s"Token already consumed", ex)
182+
verifyToken409(problemOf(StatusCodes.Conflict, ex))
183+
case Failure(ex) =>
184+
logger.error(s"Verifying token failed", ex)
185+
verifyToken400(problemOf(StatusCodes.InternalServerError, TokenVerificationFatalError(tokenId, ex.getMessage)))
157186
}
158187
}
159188

src/main/scala/it/pagopa/interop/partyprocess/api/impl/package.scala

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ package object impl extends DefaultJsonProtocol {
3737
implicit val productsFormat: RootJsonFormat[Products] = jsonFormat1(Products)
3838
implicit val billingDataFormat: RootJsonFormat[BillingData] = jsonFormat12(BillingData)
3939

40+
implicit val tokenIdFormat: RootJsonFormat[TokenId] = jsonFormat1(TokenId)
41+
4042
final val serviceErrorCodePrefix: String = "002"
4143
final val defaultProblemType: String = "about:blank"
4244
final val uidClaim: String = "uid"

src/main/scala/it/pagopa/interop/partyprocess/error/PartyProcessErrors.scala

+3
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,7 @@ object PartyProcessErrors {
131131

132132
final case class OnboardingInvalidUpdates(externalId: String)
133133
extends ComponentError("0046", s"Cannot perform data overrides on institution having external id $externalId")
134+
135+
final case class TokenVerificationFatalError(tokenId: String, error: String)
136+
extends ComponentError("0048", s"Error on retrieve $tokenId: $error")
134137
}

0 commit comments

Comments
 (0)