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);
}
}
Aggregations