-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2349 from constantine2nd/develop
Dynamic Registration of Consumer
- Loading branch information
Showing
8 changed files
with
196 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2667,6 +2667,31 @@ object SwaggerDefinitionsJSON { | |
enabled = true, | ||
created = DateWithDayExampleObject | ||
) | ||
lazy val pem = "-----BEGIN CERTIFICATE-----\nMIIFIjCCBAqgAwIBAgIIX3qsz7QQxngwDQYJKoZIhvcNAQELBQAwgZ8xCzAJBgNV\r\nBAYTAkRFMQ8wDQYDVQQIEwZCZXJsaW4xDzANBgNVBAcTBkJlcmxpbjEPMA0GA1UE\r\nChMGVEVTT0JFMRowGAYDVQQLExFURVNPQkUgT3BlcmF0aW9uczESMBAGA1UEAxMJ\r\nVEVTT0JFIENBMR8wHQYJKoZIhvcNAQkBFhBhZG1pbkB0ZXNvYmUuY29tMQwwCgYD\r\nVQQpEwNWUE4wHhcNMjMwNzE3MDg0MDAwWhcNMjQwNzE3MDg0MDAwWjCBizELMAkG\r\nA1UEBhMCREUxDzANBgNVBAgTBkJlcmxpbjEPMA0GA1UEBxMGQmVybGluMRQwEgYD\r\nVQQKEwtUZXNvYmUgR21iSDEPMA0GA1UECxMGc3lzb3BzMRIwEAYDVQQDEwlsb2Nh\r\nbGhvc3QxHzAdBgkqhkiG9w0BCQEWEGFkbWluQHRlc29iZS5jb20wggEiMA0GCSqG\r\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCwxGuWUN1H0d0IeYPYWdLA0I/5BXx4DLO6\r\nzfi1GGJlF8BIXRN0VTJckIY9C3J1RnXDs6p6ufA01iHe1PQdL6VzfcaC3j+jUSgV\r\n1z9ybEUPyUwq3PCCxqoVI9n8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51+fFOmBqCqpmwfAADNgDsLJiA/741eBflVd/ZUeAzgOjMCMIaDGlwiwZlePKT7\r\n553GtfsGxZMf05oqfUrQEQfJaU+/+Q==\n-----END CERTIFICATE-----\n" | ||
lazy val certificateInfoJsonV510 = CertificateInfoJsonV510( | ||
subject_domain_name = "OID.2.5.4.41=VPN, [email protected], CN=TESOBE CA, OU=TESOBE Operations, O=TESOBE, L=Berlin, ST=Berlin, C=DE", | ||
issuer_domain_name = "CN=localhost, O=TESOBE GmbH, ST=Berlin, C=DE", | ||
not_before = "2022-04-01T10:13:00.000Z", | ||
not_after = "2032-04-01T10:13:00.000Z", | ||
roles = None, | ||
roles_info = Some("PEM Encoded Certificate does not contain PSD2 roles.") | ||
) | ||
lazy val consumerJsonV510: ConsumerJsonV510 = ConsumerJsonV510( | ||
consumer_id = "d0d7b08c-f0ec-4e57-ac99-7d9eafe99225", | ||
consumer_key = "d0d7b08c-f0ec-4e57-ac99-7d9eafe99225", | ||
consumer_secret = "d0d7b08c-f0ec-4e57-ac99-7d9eafe99225", | ||
app_name = "SOFI", | ||
app_type = "Web", | ||
description = "Account Management", | ||
developer_email = ExampleValue.emailExample.value, | ||
company = ExampleValue.companyExample.value, | ||
redirect_url = "www.openbankproject.com", | ||
certificate_pem = pem, | ||
certificate_info = Some(certificateInfoJsonV510), | ||
created_by_user = resourceUserJSON, | ||
enabled = true, | ||
created = DateWithDayExampleObject | ||
) | ||
|
||
val consumersJson = ConsumersJson( | ||
list = List(consumerJSON) | ||
|
@@ -4200,15 +4225,6 @@ object SwaggerDefinitionsJSON { | |
val oAuth2ServerJWKURIJson = OAuth2ServerJWKURIJson("https://www.googleapis.com/oauth2/v3/certs") | ||
|
||
val oAuth2ServerJwksUrisJson = OAuth2ServerJwksUrisJson(List(oAuth2ServerJWKURIJson)) | ||
|
||
val certificateInfoJsonV510 = CertificateInfoJsonV510( | ||
subject_domain_name = "OID.2.5.4.41=VPN, [email protected], CN=TESOBE CA, OU=TESOBE Operations, O=TESOBE, L=Berlin, ST=Berlin, C=DE", | ||
issuer_domain_name = "CN=localhost, O=TESOBE GmbH, ST=Berlin, C=DE", | ||
not_before = "2022-04-01T10:13:00.000Z", | ||
not_after = "2032-04-01T10:13:00.000Z", | ||
roles = None, | ||
roles_info = Some("PEM Encoded Certificate does not contain PSD2 roles.") | ||
) | ||
|
||
val updateAccountRequestJsonV310 = UpdateAccountRequestJsonV310( | ||
label = "Label", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,11 @@ import code.api.util.ApiRole._ | |
import code.api.util.ApiTag._ | ||
import code.api.util.ErrorMessages.{$UserNotLoggedIn, BankNotFound, ConsentNotFound, InvalidJsonFormat, UnknownError, UserNotFoundByUserId, UserNotLoggedIn, _} | ||
import code.api.util.FutureUtil.{EndpointContext, EndpointTimeout} | ||
import code.api.util.JwtUtil.{getSignedPayloadAsJson, verifyJwt} | ||
import code.api.util.NewStyle.HttpCode | ||
import code.api.util.X509.{getCommonName, getEmailAddress, getOrganization} | ||
import code.api.util._ | ||
import code.api.util.newstyle.Consumer.createConsumerNewStyle | ||
import code.api.util.newstyle.RegulatedEntityNewStyle.{createRegulatedEntityNewStyle, deleteRegulatedEntityNewStyle, getRegulatedEntitiesNewStyle, getRegulatedEntityByEntityIdNewStyle} | ||
import code.api.v2_1_0.{ConsumerRedirectUrlJSON, JSONFactory210} | ||
import code.api.v3_0_0.JSONFactory300 | ||
|
@@ -23,6 +26,7 @@ import code.bankconnectors.Connector | |
import code.consent.Consents | ||
import code.loginattempts.LoginAttempt | ||
import code.metrics.APIMetrics | ||
import code.model.AppType | ||
import code.model.dataAccess.MappedBankAccount | ||
import code.regulatedentities.MappedRegulatedEntityProvider | ||
import code.transactionrequests.TransactionRequests.TransactionRequestTypes.{apply => _} | ||
|
@@ -39,8 +43,9 @@ import com.openbankproject.commons.model._ | |
import com.openbankproject.commons.util.{ApiVersion, ScannedApiVersion} | ||
import net.liftweb.common.Full | ||
import net.liftweb.http.rest.RestHelper | ||
import net.liftweb.json.parse | ||
import net.liftweb.json.{compactRender, parse} | ||
import net.liftweb.mapper.By | ||
import net.liftweb.util.Helpers | ||
import net.liftweb.util.Helpers.tryo | ||
|
||
import scala.collection.immutable.{List, Nil} | ||
|
@@ -1772,6 +1777,93 @@ trait APIMethods510 { | |
} | ||
|
||
|
||
staticResourceDocs += ResourceDoc( | ||
createConsumer, | ||
implementedInApiVersion, | ||
"createConsumer", | ||
"POST", | ||
"/dynamic-registration/consumers", | ||
"Create a Consumer", | ||
s"""Create a Consumer (mTLS access). | ||
| | ||
| JWT payload: | ||
| - minimal | ||
| { "description":"Description" } | ||
| - full | ||
| { | ||
| "description": "Description", | ||
| "app_name": "Tesobe GmbH", | ||
| "app_type": "Sofit", | ||
| "developer_email": "[email protected]", | ||
| "redirect_url": "http://localhost:8082" | ||
| } | ||
| Please note that JWT must be signed with the counterpart private kew of the public key used to establish mTLS | ||
| | ||
|""", | ||
ConsumerJwtPostJsonV510("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkZXNjcmlwdGlvbiI6IkRlc2NyaXB0aW9uIn0.qDnzk1dGK8akdLFRl8fmJV_SeoDjRTDG_eMogCIzZ7M"), | ||
consumerJsonV510, | ||
List( | ||
InvalidJsonFormat, | ||
UnknownError | ||
), | ||
List(apiTagDirectory, apiTagConsumer), | ||
Some(Nil)) | ||
|
||
|
||
lazy val createConsumer: OBPEndpoint = { | ||
case "dynamic-registration" :: "consumers" :: Nil JsonPost json -> _ => { | ||
cc => | ||
implicit val ec = EndpointContext(Some(cc)) | ||
for { | ||
postedJwt <- NewStyle.function.tryons(InvalidJsonFormat, 400, cc.callContext) { | ||
json.extract[ConsumerJwtPostJsonV510] | ||
} | ||
pem = APIUtil.`getPSD2-CERT`(cc.requestHeaders) | ||
_ <- Helper.booleanToFuture(PostJsonIsNotSigned, 400, cc.callContext) { | ||
verifyJwt(postedJwt.jwt, pem.getOrElse("")) | ||
} | ||
postedJson <- NewStyle.function.tryons(InvalidJsonFormat, 400, cc.callContext) { | ||
parse(getSignedPayloadAsJson(postedJwt.jwt).getOrElse("{}")).extract[ConsumerPostJsonV510] | ||
} | ||
certificateInfo: CertificateInfoJsonV510 <- Future(X509.getCertificateInfo(pem)) map { | ||
unboxFullOrFail(_, cc.callContext, X509GeneralError) | ||
} | ||
_ <- Helper.booleanToFuture(RegulatedEntityNotFoundByCertificate, 400, cc.callContext) { | ||
MappedRegulatedEntityProvider.getRegulatedEntities() | ||
.exists(_.entityCertificatePublicKey.replace("""\n""", "") == pem.getOrElse("").replace("""\n""", "")) | ||
} | ||
(consumer, callContext) <- createConsumerNewStyle( | ||
key = Some(Helpers.randomString(40).toLowerCase), | ||
secret = Some(Helpers.randomString(40).toLowerCase), | ||
isActive = Some(true), | ||
name = getCommonName(pem).or(postedJson.app_name) , | ||
appType = postedJson.app_type.map(AppType.valueOf).orElse(Some(AppType.valueOf("Confidential"))), | ||
description = Some(postedJson.description), | ||
developerEmail = getEmailAddress(pem).or(postedJson.developer_email), | ||
company = getOrganization(pem), | ||
redirectURL = postedJson.redirect_url, | ||
createdByUserId = None, | ||
clientCertificate = pem, | ||
cc.callContext | ||
) | ||
} yield { | ||
// Format the data as json | ||
val json = JSONFactory510.createConsumerJSON(consumer, Some(certificateInfo)) | ||
// Return | ||
(json, HttpCode.`201`(callContext)) | ||
} | ||
} | ||
} | ||
|
||
|
||
private def consumerDisabledText() = { | ||
if(APIUtil.getPropsAsBoolValue("consumers_enabled_by_default", false) == false) { | ||
"Please note: Your consumer may be disabled as a result of this action." | ||
} else { | ||
"" | ||
} | ||
} | ||
|
||
staticResourceDocs += ResourceDoc( | ||
updateConsumerRedirectUrl, | ||
implementedInApiVersion, | ||
|
@@ -1780,6 +1872,8 @@ trait APIMethods510 { | |
"/management/consumers/CONSUMER_ID/consumer/redirect_url", | ||
"Update Consumer RedirectUrl", | ||
s"""Update an existing redirectUrl for a Consumer specified by CONSUMER_ID. | ||
| | ||
| ${consumerDisabledText()} | ||
| | ||
| CONSUMER_ID can be obtained after you register the application. | ||
| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters