use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class RCSVrpPaymentDetailsApi method consentDetails.
@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
log.debug("Received a VRP consent request with consent_request='{}'", remoteConsentRequest);
log.debug("=> The VRP payment consent id '{}'", consentId);
log.debug("Populate the model with the VRP payment and consent data");
FRDomesticVRPConsent vrpConsent = consentService.getVrpPaymentConsent(consentId);
if (vrpConsent == null) {
log.error("VRP Consent ID '{}' not found", consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_INVALID, String.format("Consent ID '%s' not found.", consentId));
}
Optional<Tpp> isTpp = tppStoreService.findById(vrpConsent.getPispId());
if (isTpp.isEmpty()) {
log.error("The TPP '{}' (Client ID {}) that created this vrp consent id '{}' doesn't exist anymore.", vrpConsent.getPispId(), clientId, consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
}
Tpp tpp = isTpp.get();
// Verify the pisp is the same than the one that created this payment ^
verifyTppCreatedPayment(clientId, tpp.getClientId(), consentId);
// Associate the vrp payment to this user
vrpConsent.setUserId(username);
consentService.updateVrpPaymentConsent(vrpConsent);
FRDomesticVRPConsentDetailsData data = vrpConsent.getVrpDetails().getData();
return ResponseEntity.ok(DomesticVrpPaymentConsentDetails.builder().username(username).pispName(tpp.getOfficialName()).aspspName(platformConfiguration.getAspspName()).merchantName(vrpConsent.getPispName()).logo(tpp.getLogo()).clientId(clientId).creditorAccount(Optional.ofNullable(data.getInitiation().getCreditorAccount()).orElse(null)).debtorAccount(Optional.ofNullable(data.getInitiation().getDebtorAccount()).orElse(null)).controlParameters(Optional.ofNullable(data.getControlParameters()).orElse(null)).paymentReference(Optional.ofNullable(data.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse(null)).debtorReference(Optional.ofNullable(data.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getUnstructured).orElse(null)).build());
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class RCSDomesticPaymentDetailsApi method consentDetails.
@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
log.debug("=> The payment id '{}'", consentId);
log.debug("Populate the model with the payment and consent data");
FRDomesticConsent domesticConsent = paymentService.getPayment(consentId);
// Only show the debtor account if specified in consent
if (domesticConsent.getInitiation().getDebtorAccount() != null) {
Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(domesticConsent.getInitiation().getDebtorAccount().getIdentification(), accounts);
if (matchingUserAccount.isEmpty()) {
log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", domesticConsent.getPispId(), consentId, domesticConsent.getInitiation().getDebtorAccount(), accounts);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, domesticConsent.getPispId(), consentId, accounts);
}
accounts = Collections.singletonList(matchingUserAccount.get());
}
Optional<Tpp> isTpp = tppStoreService.findById(domesticConsent.getPispId());
if (isTpp.isEmpty()) {
log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", domesticConsent.getPispId(), clientId, consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
}
Tpp tpp = isTpp.get();
// Verify the pisp is the same than the one that created this payment ^
verifyTppCreatedPayment(clientId, tpp.getClientId(), consentId);
// Associate the payment to this user
domesticConsent.setUserId(username);
paymentService.updatePayment(domesticConsent);
return ResponseEntity.ok(DomesticPaymentConsentDetails.builder().instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(domesticConsent.getInitiation().getInstructedAmount())).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(domesticConsent.getPispName()).clientId(clientId).paymentReference(Optional.ofNullable(domesticConsent.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class RCSDomesticSchedulePaymentDetailsApi method consentDetails.
@Override
public ResponseEntity consentDetails(String remoteConsentRequest, List<AccountWithBalance> accounts, String username, String consentId, String clientId) throws OBErrorException {
log.debug("Received a consent request with consent_request='{}'", remoteConsentRequest);
log.debug("=> The payment id '{}'", consentId);
log.debug("Populate the model with the payment and consent data");
FRDomesticScheduledConsent domesticConsent = paymentService.getPayment(consentId);
// Only show the debtor account if specified in consent
if (domesticConsent.getInitiation().getDebtorAccount() != null) {
Optional<AccountWithBalance> matchingUserAccount = accountService.findAccountByIdentification(domesticConsent.getInitiation().getDebtorAccount().getIdentification(), accounts);
if (!matchingUserAccount.isPresent()) {
log.error("The PISP '{}' created the payment request '{}' but the debtor account: {} on the payment consent " + " is not one of the user's accounts: {}.", domesticConsent.getPispId(), consentId, domesticConsent.getInitiation().getDebtorAccount(), accounts);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_DEBTOR_ACCOUNT_NOT_FOUND, domesticConsent.getPispId(), consentId, accounts);
}
accounts = Collections.singletonList(matchingUserAccount.get());
}
Optional<Tpp> isTpp = tppStoreService.findById(domesticConsent.getPispId());
if (!isTpp.isPresent()) {
log.error("The TPP '{}' (Client ID {}) that created this consent id '{}' doesn't exist anymore.", domesticConsent.getPispId(), clientId, consentId);
return rcsErrorService.invalidConsentError(remoteConsentRequest, OBRIErrorType.RCS_CONSENT_REQUEST_NOT_FOUND_TPP, clientId, consentId);
}
Tpp tpp = isTpp.get();
// Verify the pisp is the same than the one that created this payment ^
verifyTppCreatedPayment(clientId, isTpp.get().getClientId(), consentId);
// Associate the payment to this user
domesticConsent.setUserId(username);
paymentService.updatePayment(domesticConsent);
FRWriteDomesticScheduledDataInitiation domesticScheduled = domesticConsent.getInitiation();
OBScheduledPayment1 obScheduledPayment1 = new OBScheduledPayment1().accountId(domesticConsent.getAccountId()).scheduledPaymentId(domesticScheduled.getInstructionIdentification()).scheduledPaymentDateTime(domesticScheduled.getRequestedExecutionDateTime()).creditorAccount(toOBCashAccount3(domesticScheduled.getCreditorAccount())).instructedAmount(toOBActiveOrHistoricCurrencyAndAmount(domesticScheduled.getInstructedAmount())).reference(domesticScheduled.getRemittanceInformation().getReference());
return ResponseEntity.ok(DomesticSchedulePaymentConsentDetails.builder().scheduledPayment(obScheduledPayment1).accounts(accounts).username(username).logo(tpp.getLogo()).merchantName(domesticConsent.getPispName()).clientId(clientId).paymentReference(Optional.ofNullable(domesticConsent.getInitiation().getRemittanceInformation()).map(FRRemittanceInformation::getReference).orElse("")).build());
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class RCSFilePaymentDetailsApiTest method givenTppExists.
private void givenTppExists() {
Tpp tpp = new Tpp();
tpp.setClientId(CLIENT_ID);
given(tppStoreService.findById(eq(PISP_ID))).willReturn(Optional.of(tpp));
}
use of com.forgerock.openbanking.model.Tpp in project openbanking-aspsp by OpenBankingToolkit.
the class RCSConsentDecisionApiControllerTest method setUp.
@Before
public void setUp() throws Exception {
this.consentDecisionApiController = new RCSConsentDecisionApiController(cryptoApiClient, rcsService, rcsConfiguration, amOpenBankingConfiguration, rcsErrorService, objectMapper, userProfileService, intentTypeService, tppStoreService, jwtOverridingService);
SinglePaymentConsentDecisionDelegate singlePaymentConsentDecisionDelegate = mock(SinglePaymentConsentDecisionDelegate.class);
given(intentTypeService.getConsentDecision(anyString())).willReturn(singlePaymentConsentDecisionDelegate);
given(singlePaymentConsentDecisionDelegate.getTppIdBehindConsent()).willReturn("TppId");
given(singlePaymentConsentDecisionDelegate.getUserIDBehindConsent()).willReturn("username");
Tpp tpp = mock(Tpp.class);
Optional<Tpp> isTpp = Optional.of(tpp);
given(this.tppStoreService.findById(anyString())).willReturn(isTpp);
given(tpp.getClientId()).willReturn("98311305-1c4f-4ffb-8af4-90c9b220e365");
amOpenBankingConfiguration.userProfileId = "username";
amOpenBankingConfiguration.endpointUserProfile = "endpointUserProfile";
amOpenBankingConfiguration.cookieName = "cookieName";
Map<String, String> profile = new HashMap<String, String>();
profile.put(amOpenBankingConfiguration.userProfileId, "username");
given(this.userProfileService.getProfile(anyString(), anyString(), anyString())).willReturn(profile);
HttpHeaders headers = new HttpHeaders();
headers.add("Location", "https://www.google.com#code=oq62Wr-V0E7cnuIl5rDSwscCyVo&id_token" + "=eyJ0eXAiOiJKV1QiLCJraWQiOiJzUUhYOHlnT3JGcHBsZ09ZZkxpQUNTNzJOMG89IiwiYWxnIjoiUFMyNTYifQ.eyJzdWIiOiJ" + "BQUNfM2ZkODYwYjktOGZlYS00NWMwLThiNTItNDJkNjM1YWRjYzRjIiwiYXVkaXRUcmFja2luZ0lkIjoiZmRhYmM2MWEtYmZjOS" + "00OWNlLThmZTUtODczOGQzMGExMmY5LTIyNTczNDgiLCJpc3MiOiJodHRwczovL2FzLmFzcHNwLnNhbmRib3gubGxveWRzYmFua" + "2luZy5jb20vb2F1dGgyIiwidG9rZW5OYW1lIjoiaWRfdG9rZW4iLCJub25jZSI6IjEwZDI2MGJmLWE3ZDktNDQ0YS05MmQ5LTdi" + "N2E1ZjA4ODIwOCIsImF1ZCI6IjE3ZTI5NmYyLTNkMDctNDMxMS05ZDAwLTk4ZDY3YjUyNTk4MCIsImNfaGFzaCI6IjB4UDJseGh" + "qek1GOTlmakhmel92dWciLCJhY3IiOiJ1cm46b3BlbmJhbmtpbmc6cHNkMjpzY2EiLCJvcGVuYmFua2luZ19pbnRlbnRfaWQiOi" + "JBQUNfM2ZkODYwYjktOGZlYS00NWMwLThiNTItNDJkNjM1YWRjYzRjIiwic19oYXNoIjoiWE5TdVJac0pVb1pjdjdZOTBoNFpfU" + "SIsImF6cCI6IjE3ZTI5NmYyLTNkMDctNDMxMS05ZDAwLTk4ZDY3YjUyNTk4MCIsImF1dGhfdGltZSI6MTYyMDkxOTc2MiwicmVh" + "bG0iOiIvb3BlbmJhbmtpbmciLCJleHAiOjE2MjA5MjM0MDIsInRva2VuVHlwZSI6IkpXVFRva2VuIiwiaWF0IjoxNjIwOTE5ODA" + "yfQ.U7zDwtrnE2ocbpcbhOc3f-j6ve0EKoh6S9n8qVH69-zezg0Qcro3PTd59gEA6L0kz5ror6epScSaWy-6rKClCr8sFqA_Fx9" + "W5qe5K-WUFTWMtfX2ncIwf-RJzxazzfxkpIrKfVhi6R96qpi7RYSZ3GWUfxBm2za24ZvyUNVR5c9ptlyke5h4Wq1QZkaiHv02VT" + "EO2GbumtWIWYfpl84FepZvDm6E6O7K0KCTs8G--jrCnZljwL-qSgWEUkIDja4eaz4KYdZ7-U-CUVzdoMaxhZY5CbM09PRRPsiuy" + "vsZ6FVGx6YGHUN-BDIFssy6hpD53Dp2HGbCxZ0unBU50Q9N3w&state=10d260bf-a7d9-444a-92d9-7b7a5f088208");
ResponseEntity responseEntity = new ResponseEntity(null, headers, HttpStatus.FOUND);
given(this.rcsService.sendRCSResponseToAM(anyString(), any(RedirectionAction.class))).willReturn(responseEntity);
URI rewrittenUri = new URI("https://www.google.com#code=oq62Wr-V0E7cnuIl5rDSwscCyVo&id_token" + "=re-writtenIdToken");
HttpHeaders rewrittenHeaders = new HttpHeaders();
rewrittenHeaders.setLocation(rewrittenUri);
ResponseEntity rewrittenResponseEntity = new ResponseEntity(null, rewrittenHeaders, HttpStatus.FOUND);
given(jwtOverridingService.rewriteIdTokenFragmentInLocationHeader(any(ResponseEntity.class))).willReturn(rewrittenResponseEntity);
}
Aggregations