Search in sources :

Example 26 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountAccessConsentDecisionDelegate method consentDecision.

@Override
public void consentDecision(String consentDecisionSerialised, boolean decision) throws IOException, OBErrorException {
    AccountConsentDecision accountConsentDecision = objectMapper.readValue(consentDecisionSerialised, AccountConsentDecision.class);
    if (decision) {
        List<FRAccount> accounts = accountsService.get(accountRequest.getUserId());
        List<String> accountsId = accounts.stream().map(Account::getId).collect(Collectors.toList());
        if (!accountsId.containsAll(accountConsentDecision.getSharedAccounts())) {
            log.error("The PSU {} is trying to share an account '{}' he doesn't own. List of his accounts '{}'", accountRequest.getUserId(), accountsId, accountConsentDecision.getSharedAccounts());
            throw new OBErrorException(OBRIErrorType.RCS_CONSENT_DECISION_INVALID_ACCOUNT, accountRequest.getUserId(), accountsId, accountConsentDecision.getSharedAccounts());
        }
        accountRequest.setAccountIds(accountConsentDecision.getSharedAccounts());
        accountRequest.setStatus(FRExternalRequestStatusCode.AUTHORISED);
        accountRequest.setStatusUpdateDateTime(DateTime.now());
        accountRequestStoreService.save(accountRequest);
    } else {
        log.debug("The account request {} has been deny", accountRequest.getId());
        accountRequest.setStatus(FRExternalRequestStatusCode.REJECTED);
        accountRequest.setStatusUpdateDateTime(DateTime.now());
        accountRequestStoreService.save(accountRequest);
    }
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) AccountConsentDecision(com.forgerock.openbanking.common.model.rcs.consentdecision.AccountConsentDecision) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Example 27 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountsApiController method getAccount.

@Override
public ResponseEntity<OBReadAccount6> getAccount(String accountId, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, List<OBExternalPermissions1Code> permissions, String httpUrl) throws OBErrorResponseException {
    log.info("Read account {} with permission {}", accountId, permissions);
    FRAccount response = frAccountRepository.byAccountId(accountId, toFRExternalPermissionsCodeList(permissions));
    List<OBAccount6> obAccounts = Collections.singletonList(toOBAccount6(response.getAccount()));
    return ResponseEntity.ok(new OBReadAccount6().data(new OBReadAccount6Data().account(obAccounts)).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(PaginationUtil.generateMetaData(1)));
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount6(uk.org.openbanking.datamodel.account.OBReadAccount6) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) FRFinancialAccountConverter.toOBAccount6(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount6) OBReadAccount6Data(uk.org.openbanking.datamodel.account.OBReadAccount6Data)

Example 28 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountsApiController method getAccounts.

@Override
public ResponseEntity<OBReadAccount6> getAccounts(String page, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, List<String> accountIds, List<OBExternalPermissions1Code> permissions, String httpUrl) throws OBErrorResponseException {
    log.info("Accounts from account ids {}", accountIds);
    List<FRAccount> frAccounts = frAccountRepository.byAccountIds(accountIds, toFRExternalPermissionsCodeList(permissions));
    List<OBAccount6> obAccounts = frAccounts.stream().map(frAccount -> toOBAccount6(frAccount.getAccount())).collect(Collectors.toList());
    return ResponseEntity.ok(new OBReadAccount6().data(new OBReadAccount6Data().account(obAccounts)).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(PaginationUtil.generateMetaData(1)));
}
Also used : PaginationUtil(com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil) FRAccountRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList(com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList) Slf4j(lombok.extern.slf4j.Slf4j) OBReadAccount6Data(uk.org.openbanking.datamodel.account.OBReadAccount6Data) List(java.util.List) OBExternalPermissions1Code(uk.org.openbanking.datamodel.account.OBExternalPermissions1Code) FRFinancialAccountConverter.toOBAccount6(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount6) OBReadAccount6(uk.org.openbanking.datamodel.account.OBReadAccount6) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount6(uk.org.openbanking.datamodel.account.OBReadAccount6) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) FRFinancialAccountConverter.toOBAccount6(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount6) OBReadAccount6Data(uk.org.openbanking.datamodel.account.OBReadAccount6Data)

Example 29 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountsApiController method getAccounts.

public ResponseEntity<OBReadAccount3> getAccounts(@ApiParam(value = "Page number.", required = false, defaultValue = "0") @RequestParam(value = "page", defaultValue = "0") String page, @ApiParam(value = "The unique id of the ASPSP to which the request is issued. The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC") @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.") @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @RequestHeader(value = "x-ob-account-ids", required = true) List<String> accountIds, @RequestHeader(value = "x-ob-permissions", required = true) List<OBExternalPermissions1Code> permissions, @RequestHeader(value = "x-ob-url", required = true) String httpUrl) throws OBErrorResponseException {
    log.info("Accounts from account ids {}", accountIds);
    List<OBAccount3> accounts = frAccountRepository.byAccountIds(accountIds, toFRExternalPermissionsCodeList(permissions)).stream().map(FRAccount::getAccount).map(FRFinancialAccountConverter::toOBAccount3).collect(Collectors.toList());
    return ResponseEntity.ok(new OBReadAccount3().data(new OBReadAccount3Data().account(accounts)).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(PaginationUtil.generateMetaData(1)));
}
Also used : OBReadAccount3Data(uk.org.openbanking.datamodel.account.OBReadAccount3Data) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount3(uk.org.openbanking.datamodel.account.OBReadAccount3) FRFinancialAccountConverter.toOBAccount3(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount3) OBAccount3(uk.org.openbanking.datamodel.account.OBAccount3)

Example 30 with FRAccount

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.

the class AccountsApiController method getAccounts.

@Override
public ResponseEntity<OBReadAccount5> getAccounts(String page, String authorization, DateTime xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, List<String> accountIds, List<OBExternalPermissions1Code> permissions, String httpUrl) throws OBErrorResponseException {
    log.info("Accounts from account ids {}", accountIds);
    List<FRAccount> frAccounts = frAccountRepository.byAccountIds(accountIds, toFRExternalPermissionsCodeList(permissions));
    List<OBAccount6> obAccounts = frAccounts.stream().map(frAccount -> toOBAccount6(frAccount.getAccount())).collect(Collectors.toList());
    return ResponseEntity.ok(new OBReadAccount5().data(new OBReadAccount5Data().account(obAccounts)).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(PaginationUtil.generateMetaData(1)));
}
Also used : PaginationUtil(com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil) FRAccountRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) Controller(org.springframework.stereotype.Controller) Collectors(java.util.stream.Collectors) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList(com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) OBExternalPermissions1Code(uk.org.openbanking.datamodel.account.OBExternalPermissions1Code) OBReadAccount5(uk.org.openbanking.datamodel.account.OBReadAccount5) FRFinancialAccountConverter.toOBAccount6(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount6) ResponseEntity(org.springframework.http.ResponseEntity) OBReadAccount5Data(uk.org.openbanking.datamodel.account.OBReadAccount5Data) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount5(uk.org.openbanking.datamodel.account.OBReadAccount5) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBAccount6(uk.org.openbanking.datamodel.account.OBAccount6) FRFinancialAccountConverter.toOBAccount6(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount6) OBReadAccount5Data(uk.org.openbanking.datamodel.account.OBReadAccount5Data)

Aggregations

FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)48 Test (org.junit.Test)31 Collections (java.util.Collections)26 Optional (java.util.Optional)25 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)24 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)23 RunWith (org.junit.runner.RunWith)23 InjectMocks (org.mockito.InjectMocks)23 Mock (org.mockito.Mock)23 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)23 MoneyService (com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService)22 PaymentNotificationFacade (com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade)22 FRCreditDebitIndicator (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator)22 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)22 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)22 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)22 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)22 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)22 BDDMockito.given (org.mockito.BDDMockito.given)22 Mockito.doThrow (org.mockito.Mockito.doThrow)22