Merge remote-tracking branch 'Simon/develop' into develop_merge_to_uk_oauth2_flow

This commit is contained in:
hongwei 2020-11-17 23:17:22 +01:00
commit 36094fc3a9
13 changed files with 744 additions and 563 deletions

View File

@ -18,7 +18,7 @@ import com.openbankproject.commons.ExecutionContext.Implicits.global
import com.openbankproject.commons.model._
import com.openbankproject.commons.model.enums.TransactionRequestStatus._
import com.openbankproject.commons.model.enums.{ChallengeType, StrongCustomerAuthenticationStatus}
import net.liftweb.common.Full
import net.liftweb.common.{Box, Full}
import net.liftweb.http.rest.RestHelper
import net.liftweb.json
import net.liftweb.json.Serialization.write
@ -103,44 +103,33 @@ or * access method is generally applicable, but further authorisation processes
}
fromAccountIban = transactionRequestBody.debtorAccount.iban
toAccountIban = transactionRequestBody.creditorAccount.iban
(fromAccount, callContext) <- NewStyle.function.getBankAccountByIban(fromAccountIban, callContext)
(_, callContext) <- NewStyle.function.getBankAccountByIban(fromAccountIban, callContext)
(_, callContext) <- NewStyle.function.validateAndCheckIbanNumber(toAccountIban, callContext)
(toAccount, callContext) <- NewStyle.function.getToBankAccountByIban(toAccountIban, callContext)
negativeAmount = - transactionRequest.body.value.amount.toDouble
currency = transactionRequest.body.value.currency
(createdTransactionRequest,callContext) <- transactionRequestTypes match {
(_, callContext) <- NewStyle.function.getToBankAccountByIban(toAccountIban, callContext)
(_, _) <- transactionRequestTypes match {
case TransactionRequestTypes.SEPA_CREDIT_TRANSFERS => {
transactionRequest.status.toUpperCase() match {
case "COMPLETED" =>
for {
(createdTransactionRequest, callContext) <- NewStyle.function.createTransactionRequestv400(
u,
ViewId("Owner"),//This is the default
fromAccount,
toAccount,
TransactionRequestType(transactionRequestTypes.toString),
TransactionRequestCommonBodyJSONCommons(
AmountOfMoneyJsonV121(amount = negativeAmount.toString, currency = currency),
""
),
"",
"",
None,
None,
None,
callContext
)
} yield (createdTransactionRequest, callContext)
case "INITIATED" =>
NewStyle.function.cancelPaymentV400(TransactionId(transactionRequest.transaction_ids), callContext) map {
x => x._1 match {
case true =>
Connector.connector.vend.saveTransactionRequestStatusImpl(transactionRequest.id, CANCELLED.toString)
(true, x._2)
case false =>
(false, x._2)
}
}
case "INITIATED" =>
Connector.connector.vend.saveTransactionRequestStatusImpl(transactionRequest.id, CANCELLED.toString)
NewStyle.function.getTransactionRequestImpl(TransactionRequestId(paymentId), callContext)
case "CANCELLED" =>
NewStyle.function.getTransactionRequestImpl(TransactionRequestId(paymentId), callContext)
Future(true, callContext)
case "CANCELLED" =>
Future(false, callContext)
}
}
}
(updatedTransactionRequest, callContext) <- NewStyle.function.getTransactionRequestImpl(TransactionRequestId(paymentId), callContext)
} yield {
(JSONFactory_BERLIN_GROUP_1_3.createCancellationTransactionRequestJson(createdTransactionRequest), HttpCode.`202`(callContext))
(JSONFactory_BERLIN_GROUP_1_3.createCancellationTransactionRequestJson(updatedTransactionRequest), HttpCode.`202`(callContext))
}
}
}

View File

@ -288,49 +288,57 @@ object OAuthHandshake extends RestHelper with MdcLoggable {
if( missingParams.size != 0 )
{
message = "the following parameters are missing : " + missingParams.mkString(", ")
logger.error(s"validator missingParams error: $message ")
httpCode = 400
}
//no parameter exists more than one times
else if (duplicatedParameters)
{
message = "Duplicated oauth protocol parameters"
logger.error(s"validator duplicatedParameters error: $message ")
httpCode = 400
}
//valid OAuth
else if(!supportedOAuthVersion(parameters.get(VersionName)))
{
message = "OAuth version not supported"
logger.error(s"validator supportedOAuthVersion error: $message ")
httpCode = 400
}
//supported signature method
else if (!supportedSignatureMethod(parameters.get(SignatureMethodName).get))
{
message = "Unsupported signature method, please use hmac-sha1 or hmac-sha256"
logger.error(s"validator supportedSignatureMethod error: $message ")
httpCode = 400
}
//check if the application is registered and active
else if(! APIUtil.registeredApplication(parameters.get("oauth_consumer_key").get))
{
logger.error("application: " + parameters.get("oauth_consumer_key").get + " not found")
message = ErrorMessages.InvalidConsumerCredentials
logger.error("application: " + parameters.get("oauth_consumer_key").get + " not found")
logger.error(s"validator registeredApplication error: $message ")
httpCode = 401
}
//valid timestamp
else if(! wrongTimestamp(parameters.get(TimestampName)).isEmpty)
{
message = wrongTimestamp(parameters.get(TimestampName)).get
logger.error(s"validator wrongTimestamp error: $message ")
httpCode = 400
}
//unused nonce
else if (alreadyUsedNonce(parameters))
{
message = "Nonce already used"
logger.error(s"validator alreadyUsedNonce error: $message ")
httpCode = 401
}
//In the case OAuth authorization token request, check if the token is still valid and the verifier is correct
else if(requestType=="authorizationToken" && !validToken(parameters.get(TokenName).get, parameters.get(VerifierName).get))
{
message = "Invalid or expired request token: " + parameters.get(TokenName).get
logger.error(s"validator validToken error: $message ")
httpCode = 401
}
//In the case protected resource access request, check if the token is still valid
@ -340,18 +348,20 @@ object OAuthHandshake extends RestHelper with MdcLoggable {
)
{
message = "Invalid or expired access token: " + parameters.get(TokenName).get
logger.error(s"validator validToken2 error: $message ")
httpCode = 401
}
//checking if the signature is correct
else if(! verifySignature(parameters, httpMethod, urlParams, sUri))
{
message = "Invalid signature"
logger.error(s"validator verifySignature error: $message ")
httpCode = 401
}
else
httpCode = 200
if(message.nonEmpty)
logger.error("error message : " + message)
logger.error("OBP oauth1.0.scala says - validator: " + message)
(httpCode, message, parameters)
}
@ -560,24 +570,28 @@ object OAuthHandshake extends RestHelper with MdcLoggable {
if(missingParams.size != 0)
{
message = "the following parameters are missing : " + missingParams.mkString(", ")
logger.error(s"validator missingParams error: $message ")
httpCode = 400
}
//no parameter exists more than one times
else if (duplicatedParameters(sRequest))
{
message = "Duplicated oauth protocol parameters"
logger.error(s"validator duplicatedParameters error: $message ")
httpCode = 400
}
//valid OAuth
else if(!supportedOAuthVersion(parameters.get(VersionName)))
{
message = "OAuth version not supported"
logger.error(s"validator supportedOAuthVersion error: $message ")
httpCode = 400
}
//supported signature method
else if (!supportedSignatureMethod(parameters.get(SignatureMethodName).get))
{
message = "Unsupported signature method, please use hmac-sha1 or hmac-sha256"
logger.error(s"validator supportedSignatureMethod error: $message ")
httpCode = 400
}
//check if the application is registered and active
@ -585,43 +599,49 @@ object OAuthHandshake extends RestHelper with MdcLoggable {
{
logger.error("application: " + parameters.get("oauth_consumer_key").get + " not found")
message = ErrorMessages.InvalidConsumerCredentials
logger.error(s"validator registeredApplication error: $message ")
httpCode = 401
}
//valid timestamp
else if(! wrongTimestamp(parameters.get(TimestampName)).isEmpty)
{
message = wrongTimestamp(parameters.get(TimestampName)).get
logger.error(s"validator wrongTimestamp error: $message ")
httpCode = 400
}
//unused nonce
else if (alreadyUsedNonce)
{
message = "Nonce already used"
logger.error(s"validator alreadyUsedNonce error: $message ")
httpCode = 401
}
//In the case OAuth authorization token request, check if the token is still valid and the verifier is correct
else if(!validToken)
{
message = "Invalid or expired request token: " + parameters.get(TokenName).get
logger.error(s"validator validToken error: $message ")
httpCode = 401
}
//In the case protected resource access request, check if the token is still valid
else if (!validToken2)
{
message = "Invalid or expired access token: " + parameters.get(TokenName).get
logger.error(s"validator validToken2 error: $message ")
httpCode = 401
}
//checking if the signature is correct
else if(! verifySignature(parameters, httpMethod, urlParams, sUri))
{
message = "Invalid signature"
logger.error(s"validator verifySignature error: $message ")
httpCode = 401
}
else
httpCode = 200
if(message.nonEmpty)
logger.error("OBP oauth1.0.scala says : " + message)
logger.error("OBP oauth1.0.scala - validatorFuture says : " + message)
(httpCode, message, parameters)
}

View File

@ -472,6 +472,7 @@ object ErrorMessages {
val InvalidConnectorResponseForMissingRequiredValues = "OBP-50214: Connector return the data, but the data has missing required values."
val InvalidConnectorResponseForCreateChallenge = "OBP-50215: Connector did not return the set of challenge we requested."
val InvalidConnectorResponseForSaveDoubleEntryBookTransaction = "OBP-50216: The Connector did not return a valid response for saving double-entry transaction."
val InvalidConnectorResponseForCancelPayment = "OBP-50217: Connector did not return the transaction we requested."
// Adapter Exceptions (OBP-6XXXX)

File diff suppressed because it is too large Load Diff

View File

@ -1027,6 +1027,12 @@ object NewStyle {
(unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponseForSaveDoubleEntryBookTransaction ", 400), i._2)
}
def cancelPaymentV400(transactionId: TransactionId, callContext: Option[CallContext]): OBPReturnType[Boolean] = {
Connector.connector.vend.cancelPaymentV400(transactionId: TransactionId, callContext) map { i =>
(unboxFullOrFail(i._1, callContext, s"$InvalidConnectorResponseForCancelPayment ",400), i._2)
}
}
def createOrUpdateProductAttribute(
bankId: BankId,
productCode: ProductCode,

View File

@ -407,11 +407,15 @@ object JSONFactory1_4_0 extends MdcLoggable{
def prepareDescription(parameter: String): String = {
val glossaryItemTitle = getGlossaryItemTitle(parameter)
val exampleFieldValue = getExampleFieldValue(parameter)
s"""
|
|* [${parameter}](/glossary#$glossaryItemTitle): $exampleFieldValue
|
|""".stripMargin
if(exampleFieldValue.contains(ExampleValue.NoExampleProvided)){
""
} else {
s"""
|
|* [${parameter}](/glossary#$glossaryItemTitle): $exampleFieldValue
|
|""".stripMargin
}
}
def prepareJsonFieldDescription(jsonBody: scala.Product, jsonType: String): String = {

View File

@ -1708,6 +1708,11 @@ trait Connector extends MdcLoggable {
callContext: Option[CallContext]): Future[Box[(TransactionId, Option[CallContext])]] = Future {
Failure(setUnimplementedError)
}
def cancelPaymentV400(transactionId: TransactionId,
callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future {
(Failure(setUnimplementedError), callContext)
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -247,6 +247,7 @@ object ConnectorBuilderUtil {
"updatePhysicalCard",
"makePaymentv210",
"makePaymentV400",
"cancelPaymentV400",
"createTransactionRequestv210",
"getTransactionRequests210",
"getTransactionRequestImpl",

View File

@ -1496,6 +1496,11 @@ object LocalMappedConnector extends Connector with MdcLoggable {
mappedTransaction.theTransactionId
}
}
override def cancelPaymentV400(transactionId: TransactionId,
callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = Future {
(Full(false), callContext)
}
/*
Transaction Requests

View File

@ -1,4 +1,4 @@
-- auto generated MS sql server procedures script, create on 2020-11-05T12:02:28Z
-- auto generated MS sql server procedures script, create on 2020-11-16T19:21:20Z
-- drop procedure obp_get_adapter_info
DROP PROCEDURE IF EXISTS obp_get_adapter_info;
@ -8865,6 +8865,122 @@ GO
-- drop procedure obp_cancel_payment_v400
DROP PROCEDURE IF EXISTS obp_cancel_payment_v400;
GO
-- create procedure obp_cancel_payment_v400
CREATE PROCEDURE obp_cancel_payment_v400
@outbound_json NVARCHAR(MAX),
@inbound_json NVARCHAR(MAX) OUT
AS
SET nocount on
-- replace the follow example to real logic
/*
this is example of parameter @outbound_json
N'{
"outboundAdapterCallContext":{
"correlationId":"1flssoftxq0cr1nssr68u0mioj",
"sessionId":"b4e0352a-9a0f-4bfa-b30b-9003aa467f50",
"consumerId":"7uy8a7e4-6d02-40e3-a129-0b2bf89de8uh",
"generalContext":[
{
"key":"CustomerNumber",
"value":"5987953"
}
],
"outboundAdapterAuthInfo":{
"userId":"9ca9a7e4-6d02-40e3-a129-0b2bf89de9b1",
"username":"felixsmith",
"linkedCustomers":[
{
"customerId":"7uy8a7e4-6d02-40e3-a129-0b2bf89de8uh",
"customerNumber":"5987953",
"legalName":"Eveline Tripman"
}
],
"userAuthContext":[
{
"key":"CustomerNumber",
"value":"5987953"
}
],
"authViews":[
{
"view":{
"id":"owner",
"name":"Owner",
"description":"This view is for the owner for the account."
},
"account":{
"id":"8ca8a7e4-6d02-40e3-a129-0b2bf89de9f0",
"accountRoutings":[
{
"scheme":"IBAN",
"address":"DE91 1000 0000 0123 4567 89"
}
],
"customerOwners":[
{
"bankId":"gh.29.uk",
"customerId":"7uy8a7e4-6d02-40e3-a129-0b2bf89de8uh",
"customerNumber":"5987953",
"legalName":"Eveline Tripman",
"dateOfBirth":"2018-03-09T00:00:00Z"
}
],
"userOwners":[
{
"userId":"9ca9a7e4-6d02-40e3-a129-0b2bf89de9b1",
"emailAddress":"felixsmith@example.com",
"name":"felixsmith"
}
]
}
}
]
}
},
"transactionId":{
"value":"2fg8a7e4-6d02-40e3-a129-0b2bf89de8ub"
}
}'
*/
-- return example value
SELECT @inbound_json = (
SELECT
N'{
"inboundAdapterCallContext":{
"correlationId":"1flssoftxq0cr1nssr68u0mioj",
"sessionId":"b4e0352a-9a0f-4bfa-b30b-9003aa467f50",
"generalContext":[
{
"key":"CustomerNumber",
"value":"5987953"
}
]
},
"status":{
"errorCode":"",
"backendMessages":[
{
"source":"String",
"status":"String",
"errorCode":"",
"text":"String"
}
]
},
"data":true
}'
);
GO
-- drop procedure obp_create_counterparty
DROP PROCEDURE IF EXISTS obp_create_counterparty;
GO

View File

@ -75,7 +75,7 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable {
val connectorName = "stored_procedure_vDec2019"
//---------------- dynamic start -------------------please don't modify this line
// ---------- created on 2020-11-05T12:59:27Z
// ---------- created on 2020-11-16T20:19:48Z
messageDocs += getAdapterInfoDoc
def getAdapterInfoDoc = MessageDoc(
@ -3508,6 +3508,32 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable {
response.map(convertToTuple[TransactionId](callContext))
}
messageDocs += cancelPaymentV400Doc
def cancelPaymentV400Doc = MessageDoc(
process = "obp.cancelPaymentV400",
messageFormat = messageFormat,
description = "Cancel Payment V400",
outboundTopic = None,
inboundTopic = None,
exampleOutboundMessage = (
OutBoundCancelPaymentV400(outboundAdapterCallContext=MessageDocsSwaggerDefinitions.outboundAdapterCallContext,
transactionId=TransactionId(transactionIdExample.value))
),
exampleInboundMessage = (
InBoundCancelPaymentV400(inboundAdapterCallContext=MessageDocsSwaggerDefinitions.inboundAdapterCallContext,
status=MessageDocsSwaggerDefinitions.inboundStatus,
data=true)
),
adapterImplementation = Some(AdapterImplementation("- Core", 1))
)
override def cancelPaymentV400(transactionId: TransactionId, callContext: Option[CallContext]): OBPReturnType[Box[Boolean]] = {
import com.openbankproject.commons.dto.{InBoundCancelPaymentV400 => InBound, OutBoundCancelPaymentV400 => OutBound}
val req = OutBound(callContext.map(_.toOutboundAdapterCallContext).orNull, transactionId)
val response: Future[Box[InBound]] = sendRequest[InBound]("obp_cancel_payment_v400", req, callContext)
response.map(convertToTuple[Boolean](callContext))
}
messageDocs += createCounterpartyDoc
def createCounterpartyDoc = MessageDoc(
process = "obp.createCounterparty",
@ -6121,8 +6147,8 @@ trait StoredProcedureConnector_vDec2019 extends Connector with MdcLoggable {
response.map(convertToTuple[Boolean](callContext))
}
// ---------- created on 2020-11-05T12:59:27Z
//---------------- dynamic end ---------------------please don't modify this line
// ---------- created on 2020-11-16T20:19:48Z
//---------------- dynamic end ---------------------please don't modify this line
private val availableOperation = DynamicEntityOperation.values.map(it => s""""$it"""").mkString("[", ", ", "]")

View File

@ -9,7 +9,7 @@
</div>
<script class="redirect-script" type="text/javascript">
$('#manualRedirect').hide(); //don't need the manual link if js is enabled
$('#manual-redirect').hide(); //don't need the manual link if js is enabled
window.location.assign($('#redirect-link').attr('href'));
</script>
</div>

View File

@ -169,6 +169,12 @@ case class OutBoundMakePaymentV400(outboundAdapterCallContext: OutboundAdapterCa
case class InBoundMakePaymentV400(inboundAdapterCallContext: InboundAdapterCallContext, status: Status, data: TransactionId) extends InBoundTrait[TransactionId]
case class OutBoundCancelPaymentV400(outboundAdapterCallContext: OutboundAdapterCallContext,
transactionId: TransactionId) extends TopicTrait
case class InBoundCancelPaymentV400(inboundAdapterCallContext:
InboundAdapterCallContext,
status: Status, data: Boolean) extends InBoundTrait[Boolean]
case class OutBoundCreateTransactionRequestv210(outboundAdapterCallContext: OutboundAdapterCallContext,
initiator: User, //TODO FIXME