Search in sources :

Example 1 with AccountConsentDecision

use of com.forgerock.openbanking.common.model.rcs.consentdecision.AccountConsentDecision 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)

Aggregations

FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)1 AccountConsentDecision (com.forgerock.openbanking.common.model.rcs.consentdecision.AccountConsentDecision)1 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)1