Search in sources :

Example 16 with OBErrorException

use of com.forgerock.openbanking.exceptions.OBErrorException in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpPaymentsEndpointWrapper method checkRequestAndConsentRiskMatch.

// The Risk section must matches the values specified in the consent.
public void checkRequestAndConsentRiskMatch(OBDomesticVRPRequest request, FRDomesticVRPConsent frConsent) throws OBErrorException {
    OBRisk1 requestRisk = request.getRisk();
    OBRisk1 consentRisk = toOBRisk1(frConsent.getRisk());
    if (!requestRisk.equals(consentRisk)) {
        throw new OBErrorException(OBRIErrorType.REQUEST_VRP_RISK_DOESNT_MATCH_CONSENT);
    }
}
Also used : OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) OBRisk1(uk.org.openbanking.datamodel.payment.OBRisk1) FRDomesticVRPConsentConverter.toOBRisk1(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toOBRisk1)

Example 17 with OBErrorException

use of com.forgerock.openbanking.exceptions.OBErrorException in project openbanking-aspsp by OpenBankingToolkit.

the class DomesticVrpPaymentsEndpointWrapper method validateMaximumIndividualAmount.

private void validateMaximumIndividualAmount(OBDomesticVRPRequest vrpRequest, FRDomesticVRPConsent frConsent) throws OBErrorException {
    FRDomesticVRPControlParameters controlParameters = frConsent.getVrpDetails().getData().getControlParameters();
    Double consentAmount = Double.valueOf(controlParameters.getMaximumIndividualAmount().getAmount());
    Double requestAmount = Double.valueOf(vrpRequest.getData().getInstruction().getInstructedAmount().getAmount());
    if (requestAmount.compareTo(consentAmount) > 0) {
        throw new OBErrorException(OBRIErrorType.REQUEST_VRP_CONTROL_PARAMETERS_RULES, VRPErrorControlParametersFields.RequestControlFields.MAX_INDIVIDUAL_AMOUNT, VRPErrorControlParametersFields.ConsentControlFields.MAX_INDIVIDUAL_AMOUNT);
    }
}
Also used : OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) FRDomesticVRPControlParameters(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPControlParameters)

Example 18 with OBErrorException

use of com.forgerock.openbanking.exceptions.OBErrorException in project openbanking-aspsp by OpenBankingToolkit.

the class FilePaymentsApiEndpointWrapper method verifyContentTypeHeader.

public void verifyContentTypeHeader(String contentTypeHeader) throws OBErrorException {
    // Check the file content-type header is compatible with the consent type
    MediaType consentContentType = consent.getFileType().getContentType();
    log.debug("Consent indicates file content-type of: '{}'. Actual content-type header of submitted file: '{}'", consent.getFileType().getContentType(), contentTypeHeader);
    if (!consentContentType.isCompatibleWith(MediaType.parseMediaType(contentTypeHeader))) {
        log.warn("Content type header '{}' for payment file consent does not match the specified file type: '{}'. Expected content-type: {}", consentContentType, consent.getFileType(), consentContentType);
        throw new OBErrorException(OBRIErrorType.REQUEST_MEDIA_TYPE_NOT_ACCEPTABLE, consentContentType);
    }
    log.debug("File content type is correct for consent id: ", consent.getId());
}
Also used : MediaType(org.springframework.http.MediaType) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Example 19 with OBErrorException

use of com.forgerock.openbanking.exceptions.OBErrorException in project openbanking-aspsp by OpenBankingToolkit.

the class Psd2WithSessionApiHelperService method getPsuNameFromSession.

public String getPsuNameFromSession(String obriSession) throws OBErrorException {
    try {
        SignedJWT session = cryptoApiClient.decryptJwe(obriSession);
        String psuName = session.getJWTClaimsSet().getSubject();
        return psuName;
    } catch (Exception e) {
        log.info("getPsuNameFromSession() caught exception getting psu name from session '{};", obriSession, e);
    }
    throw new OBErrorException(OBRIErrorType.SESSION_TOKEN_INVALID_FORMAT);
}
Also used : OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) SignedJWT(com.nimbusds.jwt.SignedJWT) OAuth2InvalidClientException(com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Example 20 with OBErrorException

use of com.forgerock.openbanking.exceptions.OBErrorException in project openbanking-aspsp by OpenBankingToolkit.

the class AccessTokenService method verifyAccessTokenScopes.

public void verifyAccessTokenScopes(List<String> expectedScopes, SignedJWT accessToken) throws OBErrorException {
    try {
        List<String> scopes = getScopes(accessToken);
        if (!scopes.containsAll(expectedScopes)) {
            log.info("Access token did not contain expected scopes. Token scopes '{}' Expected scopes '{}'", scopes, expectedScopes);
            throw new OBErrorException(OBRIErrorType.ACCESS_TOKEN_INVALID, "Did not contain the expected scopes");
        }
        log.debug("verifyAccessTokenScopes() accessToken contains expected scopes");
    } catch (Exception e) {
        throw new OBErrorException(OBRIErrorType.ACCESS_TOKEN_INVALID, "Access token did not contain valid " + "scopes");
    }
}
Also used : OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) OAuth2BearerTokenUsageInvalidTokenException(com.forgerock.openbanking.common.error.exception.oauth2.OAuth2BearerTokenUsageInvalidTokenException) PermissionDenyException(com.forgerock.openbanking.common.error.exception.PermissionDenyException) InvalidTokenException(com.forgerock.openbanking.jwt.exceptions.InvalidTokenException) ParseException(java.text.ParseException) IOException(java.io.IOException) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Aggregations

OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)69 Test (org.junit.Test)20 ParseException (java.text.ParseException)19 IOException (java.io.IOException)13 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)9 SignedJWT (com.nimbusds.jwt.SignedJWT)9 ResponseEntity (org.springframework.http.ResponseEntity)9 InvalidTokenException (com.forgerock.openbanking.jwt.exceptions.InvalidTokenException)8 Tpp (com.forgerock.openbanking.model.Tpp)8 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)6 PaymentConsent (com.forgerock.openbanking.common.model.openbanking.persistence.payment.PaymentConsent)5 List (java.util.List)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 AccountRequest (com.forgerock.openbanking.common.model.openbanking.persistence.account.AccountRequest)4 OIDCConstants (com.forgerock.openbanking.constants.OIDCConstants)4 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)4 PermissionDenyException (com.forgerock.openbanking.common.error.exception.PermissionDenyException)3 OAuth2BearerTokenUsageInvalidTokenException (com.forgerock.openbanking.common.error.exception.oauth2.OAuth2BearerTokenUsageInvalidTokenException)3 OAuth2InvalidClientException (com.forgerock.openbanking.common.error.exception.oauth2.OAuth2InvalidClientException)3