feature/added new connector method validateChallengeAnswer2

This commit is contained in:
hongwei 2024-07-01 12:09:22 +02:00 committed by Hongwei
parent 13d2b7ae14
commit b2ee741e59
7 changed files with 38 additions and 12 deletions

View File

@ -3,7 +3,6 @@ package code.api.util
import java.util.Date
import java.util.UUID.randomUUID
import akka.http.scaladsl.model.HttpMethod
import code.DynamicEndpoint.{DynamicEndpointProvider, DynamicEndpointT}
import code.api.{APIFailureNewStyle, Constant, JsonResponseException}
@ -54,8 +53,8 @@ import net.liftweb.json.JsonDSL._
import net.liftweb.json.{JField, JInt, JNothing, JNull, JObject, JString, JValue, _}
import net.liftweb.util.Helpers.tryo
import org.apache.commons.lang3.StringUtils
import java.security.AccessControlException
import java.security.AccessControlException
import scala.collection.immutable.{List, Nil}
import scala.concurrent.Future
import scala.math.BigDecimal
@ -80,6 +79,7 @@ import code.endpointMapping.{EndpointMappingProvider, EndpointMappingT}
import code.endpointTag.EndpointTagT
import code.util.Helper.MdcLoggable
import code.views.system.AccountAccess
import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType
import net.liftweb.mapper.By
object NewStyle extends MdcLoggable{
@ -1302,9 +1302,8 @@ object NewStyle extends MdcLoggable{
}
}
def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Boolean] =
Connector.connector.vend.validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]) map { i =>
def validateChallengeAnswer(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Boolean] =
Connector.connector.vend.validateChallengeAnswerV2(challengeId, suppliedAnswer, suppliedAnswerType, callContext) map { i =>
(unboxFullOrFail(i._1, callContext, s"${
InvalidChallengeAnswer
.replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).")

View File

@ -1,7 +1,6 @@
package code.api.v2_1_0
import java.util.Date
import code.TransactionTypes.TransactionType
import code.api.util
import code.api.util.ApiTag._
@ -32,7 +31,7 @@ import code.util.Helper.booleanToBox
import code.views.Views
import code.views.system.ViewDefinition
import com.openbankproject.commons.model._
import com.openbankproject.commons.model.enums.ChallengeType
import com.openbankproject.commons.model.enums.{ChallengeType, SuppliedAnswerType}
import com.openbankproject.commons.util.ApiVersion
import net.liftweb.json.Extraction
import net.liftweb.util.Helpers.tryo
@ -681,7 +680,7 @@ trait APIMethods210 {
existingTransactionRequest.challenge.challenge_type == ChallengeType.OBP_TRANSACTION_REQUEST_CHALLENGE.toString
}
(isChallengeAnswerValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, callContext)
(isChallengeAnswerValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, SuppliedAnswerType.PLAIN_TEXT_VALUE, callContext)
_ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer
.replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).")

View File

@ -86,7 +86,7 @@ import com.openbankproject.commons.dto.GetProductsParam
import com.openbankproject.commons.model.enums.ChallengeType.OBP_TRANSACTION_REQUEST_CHALLENGE
import com.openbankproject.commons.model.enums.DynamicEntityOperation._
import com.openbankproject.commons.model.enums.{TransactionRequestStatus, _}
import com.openbankproject.commons.model.{ListResult, _}
import com.openbankproject.commons.model._
import com.openbankproject.commons.util.{ApiVersion, JsonUtils, ScannedApiVersion}
import deletion._
import net.liftweb.common._
@ -95,7 +95,7 @@ import net.liftweb.http.{JsonResponse, Req, S}
import net.liftweb.json.JsonAST.JValue
import net.liftweb.json.JsonDSL._
import net.liftweb.json.Serialization.write
import net.liftweb.json.{compactRender, prettyRender, _}
import net.liftweb.json._
import net.liftweb.mapper.By
import net.liftweb.util.Helpers.{now, tryo}
import net.liftweb.util.Mailer.{From, PlainMailBodyType, Subject, To, XHTMLMailBodyType}
@ -1637,7 +1637,7 @@ trait APIMethods400 extends MdcLoggable {
case _ =>
for {
(challengeAnswerIsValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, callContext)
(challengeAnswerIsValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, SuppliedAnswerType.PLAIN_TEXT_VALUE,callContext)
_ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer
.replace("answer may be expired.",s"answer may be expired (${transactionRequestChallengeTtl} seconds).")

View File

@ -2,7 +2,6 @@ package code.bankconnectors
import java.util.Date
import java.util.UUID.randomUUID
import _root_.akka.http.scaladsl.model.HttpMethod
import code.accountholders.{AccountHolders, MapperAccountHolders}
import code.api.Constant.{SYSTEM_ACCOUNTANT_VIEW_ID, SYSTEM_AUDITOR_VIEW_ID, SYSTEM_OWNER_VIEW_ID, localIdentityProvider}
@ -42,6 +41,7 @@ import com.openbankproject.commons.ExecutionContext.Implicits.global
import com.openbankproject.commons.dto.{CustomerAndAttribute, GetProductsParam, InBoundTrait, ProductCollectionItemsTree}
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA
import com.openbankproject.commons.model.enums.StrongCustomerAuthenticationStatus.SCAStatus
import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType
import com.openbankproject.commons.model.enums._
import com.openbankproject.commons.model.{AccountApplication, Bank, CounterpartyTrait, CustomerAddress, DirectDebitTrait, FXRate, Product, ProductCollection, ProductCollectionItem, TaxResidence, TransactionRequestStatus, TransactionRequestTypeCharge, UserAuthContext, UserAuthContextUpdate, _}
import com.openbankproject.commons.util.Functions.lazyValue
@ -435,8 +435,11 @@ trait Connector extends MdcLoggable {
callContext: Option[CallContext]) : OBPReturnType[Box[List[ChallengeTrait]]]= Future{(Failure(setUnimplementedError), callContext)}
// Validates an answer for a challenge and returns if the answer is correct or not
@deprecated("Please use @validateChallengeAnswerV2 instead ","01.07.2024")
def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Full(true), callContext)}
def validateChallengeAnswerV2(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future{(Full(true), callContext)}
def allChallengesSuccessfullyAnswered(
bankId: BankId,
accountId: AccountId,

View File

@ -80,6 +80,7 @@ import com.openbankproject.commons.model.enums.ChallengeType.OBP_TRANSACTION_REQ
import com.openbankproject.commons.model.enums.DynamicEntityOperation._
import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA
import com.openbankproject.commons.model.enums.StrongCustomerAuthenticationStatus.SCAStatus
import com.openbankproject.commons.model.enums.SuppliedAnswerType.SuppliedAnswerType
import com.openbankproject.commons.model.enums.{TransactionRequestStatus, _}
import com.openbankproject.commons.model.{AccountApplication, AccountAttribute, ConsentImplicitSCAT, DirectDebitTrait, FXRate, Product, ProductAttribute, ProductCollectionItem, TaxResidence, TransactionRequestCommonBodyJSON, _}
import com.tesobe.CacheKeyFromArguments
@ -485,6 +486,13 @@ object LocalMappedConnector extends Connector with MdcLoggable {
override def getChallenge(challengeId: String, callContext: Option[CallContext]): OBPReturnType[Box[ChallengeTrait]] =
Future {(Challenges.ChallengeProvider.vend.getChallenge(challengeId), callContext)}
override def validateChallengeAnswerV2(challengeId: String, suppliedAnswer: String, suppliedAnswerType:SuppliedAnswerType, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] =
Future {
val userId = callContext.map(_.user.map(_.userId).openOrThrowException(s"$UserNotLoggedIn Can not find the userId here."))
//In OBP, we only validateChallenge with SuppliedAnswerType.PLAN_TEXT,
(Full(Challenges.ChallengeProvider.vend.validateChallenge(challengeId, suppliedAnswer, userId).isDefined), callContext)
}
override def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] =
Future {
val userId = callContext.map(_.user.map(_.userId).openOrThrowException(s"$UserNotLoggedIn Can not find the userId here."))

View File

@ -859,6 +859,16 @@ case class InBoundValidateChallengeAnswer(inboundAdapterCallContext: InboundAdap
status: Status,
data: Boolean) extends InBoundTrait[Boolean]
case class OutBoundValidateChallengeAnswerV2(outboundAdapterCallContext: OutboundAdapterCallContext,
challengeId: String,
suppliedAnswer: String,
suppliedAnswerType: String) extends TopicTrait
case class InBoundValidateChallengeAnswerV2(inboundAdapterCallContext: InboundAdapterCallContext,
status: Status,
data: Boolean) extends InBoundTrait[Boolean]
//---------------------

View File

@ -229,6 +229,13 @@ object AttributeCategory extends OBPEnumeration[AttributeCategory]{
object TransactionRequest extends Value
}
object SuppliedAnswerType extends Enumeration {
type SuppliedAnswerType = Value
val PLAIN_TEXT_VALUE, HASH_VALUE = Value
}
object TransactionRequestStatus extends Enumeration {
type TransactionRequestStatus = Value
val INITIATED, PENDING, NEXT_CHALLENGE_PENDING, FAILED, COMPLETED, FORWARDED, REJECTED, CANCELLED, CANCELLATION_PENDING = Value