Search in sources :

Example 1 with ConsentUtilityServiceException

use of org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException in project carbon-identity-framework by wso2.

the class ConsentUtilityService method filterPIIsFromReceipt.

/**
 * If the consent is not given for a PII
 *
 * @param keySet
 * @param receipt
 * @return
 * @throws ConsentUtilityServiceException
 */
public Set<String> filterPIIsFromReceipt(Set<String> keySet, ReceiptInput receipt) throws ConsentUtilityServiceException {
    if (keySet == null || receipt == null) {
        throw new ConsentUtilityServiceException("Key set and receipt should not be null");
    }
    List<ReceiptServiceInput> services = receipt.getServices();
    Set<String> consentedPIIs = new HashSet<>();
    for (ReceiptServiceInput service : services) {
        List<ReceiptPurposeInput> purposes = service.getPurposes();
        for (ReceiptPurposeInput consentPurpose : purposes) {
            List<PIICategoryValidity> piiCategories = consentPurpose.getPiiCategory();
            for (PIICategoryValidity piiCategory : piiCategories) {
                consentedPIIs.add(getPIIName(consentPurpose.getPurposeId(), piiCategory.getId()));
            }
        }
    }
    keySet.retainAll(consentedPIIs);
    return keySet;
}
Also used : ConsentUtilityServiceException(org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException) ReceiptServiceInput(org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput) ReceiptPurposeInput(org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput) PIICategoryValidity(org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity) HashSet(java.util.HashSet)

Example 2 with ConsentUtilityServiceException

use of org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException in project carbon-identity-framework by wso2.

the class ConsentUtilityService method getMandatoryPIIs.

/**
 * Returns the set of mandatory PIIs of a given set of purposes.
 *
 * @param purposes List of purposes.
 * @return Set of Mandatory PIIs.
 * @throws ConsentUtilityServiceException
 */
public Set<Integer> getMandatoryPIIs(List<Purpose> purposes) throws ConsentUtilityServiceException {
    if (purposes == null) {
        throw new ConsentUtilityServiceException("Purposes list should not be null");
    }
    Set<Integer> mandatoryPIIs = new HashSet<>();
    for (Purpose purpose : purposes) {
        Set<Integer> mandatoryPurposePIIs = getMandatoryPIIs(purpose);
        mandatoryPIIs.addAll(mandatoryPurposePIIs);
    }
    return mandatoryPIIs;
}
Also used : ConsentUtilityServiceException(org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException) Purpose(org.wso2.carbon.consent.mgt.core.model.Purpose) HashSet(java.util.HashSet)

Example 3 with ConsentUtilityServiceException

use of org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException in project carbon-identity-framework by wso2.

the class ConsentUtilityService method validateReceiptPIIs.

/**
 * Validate a given receipt with with respective purposes.
 *
 * @param receiptInput User given receipt.
 * @param purposes     Configured purposes.
 * @throws ConsentUtilityServiceException ConsentUtilityServiceException.
 */
public void validateReceiptPIIs(ReceiptInput receiptInput, List<Purpose> purposes) throws ConsentUtilityServiceException {
    if (purposes == null || receiptInput == null) {
        throw new IllegalArgumentException("Receipt Input and purposes should not be null");
    }
    if (log.isDebugEnabled()) {
        log.debug("Validating receipt against purposes.");
    }
    List<ReceiptServiceInput> services = receiptInput.getServices();
    for (Purpose purpose : purposes) {
        purpose = fillPurpose(purpose);
        boolean purposeConsented = false;
        Set<Integer> mandatoryPIIs = getMandatoryPIIs(purpose);
        if (log.isDebugEnabled()) {
            log.debug("Mandatory PIIs for purpose : " + purpose.getName() + " : " + Arrays.toString(mandatoryPIIs.toArray()));
        }
        for (ReceiptServiceInput service : services) {
            List<ReceiptPurposeInput> consentPurposes = service.getPurposes();
            for (ReceiptPurposeInput consentPurpose : consentPurposes) {
                if (Objects.equals(consentPurpose.getPurposeId(), purpose.getId())) {
                    purposeConsented = true;
                    List<PIICategoryValidity> pIICategories = consentPurpose.getPiiCategory();
                    Set<Integer> consentedPIIs = getPIIs(pIICategories);
                    if (log.isDebugEnabled()) {
                        log.debug("Consented PIIs: " + Arrays.toString(consentedPIIs.toArray()));
                    }
                    if (!consentedPIIs.containsAll(mandatoryPIIs)) {
                        throw new ConsentUtilityServiceException("One or more mandatory attributes are missing in" + " the given receipt");
                    }
                }
            }
            if (!purposeConsented && !mandatoryPIIs.isEmpty()) {
                throw new ConsentUtilityServiceException("Consent receipt does not contain consent for " + "purpose " + purpose.getName() + " with ID: " + purpose.getId() + ", which has " + "mandatory PIIs");
            }
        }
    }
}
Also used : ReceiptServiceInput(org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput) ConsentUtilityServiceException(org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException) ReceiptPurposeInput(org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput) Purpose(org.wso2.carbon.consent.mgt.core.model.Purpose) PIICategoryValidity(org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)

Example 4 with ConsentUtilityServiceException

use of org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException in project carbon-identity-framework by wso2.

the class ConsentUtilityService method getPIIName.

private String getPIIName(int purposeId, int pIIId) throws ConsentUtilityServiceException {
    ConsentManager consentManager = IdentityConsentDataHolder.getInstance().getConsentManager();
    try {
        Purpose purpose = consentManager.getPurpose(purposeId);
        List<PurposePIICategory> purposePIICategories = purpose.getPurposePIICategories();
        for (PurposePIICategory purposePIICategory : purposePIICategories) {
            if (purposePIICategory.getId() == pIIId) {
                return purposePIICategory.getName();
            }
        }
    } catch (ConsentManagementException e) {
        throw new ConsentUtilityServiceException("Error while retrieving purpose with id:" + purposeId, e);
    }
    throw new ConsentUtilityServiceException("No PII can be found within given id: " + pIIId + "for purpose :" + purposeId);
}
Also used : ConsentUtilityServiceException(org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException) PurposePIICategory(org.wso2.carbon.consent.mgt.core.model.PurposePIICategory) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) Purpose(org.wso2.carbon.consent.mgt.core.model.Purpose) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager)

Example 5 with ConsentUtilityServiceException

use of org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException in project carbon-identity-framework by wso2.

the class ConsentUtilityService method getPIIs.

private Set<Integer> getPIIs(Purpose purpose) throws ConsentUtilityServiceException {
    Set<Integer> uniquePIIs = new HashSet<>();
    purpose = fillPurpose(purpose);
    List<PurposePIICategory> purposePIICategories = purpose.getPurposePIICategories();
    for (PurposePIICategory purposePIICategory : purposePIICategories) {
        uniquePIIs.add(purposePIICategory.getId());
    }
    return uniquePIIs;
}
Also used : PurposePIICategory(org.wso2.carbon.consent.mgt.core.model.PurposePIICategory) HashSet(java.util.HashSet)

Aggregations

ConsentUtilityServiceException (org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException)7 HashSet (java.util.HashSet)5 Purpose (org.wso2.carbon.consent.mgt.core.model.Purpose)4 PurposePIICategory (org.wso2.carbon.consent.mgt.core.model.PurposePIICategory)3 PIICategoryValidity (org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)2 ReceiptPurposeInput (org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput)2 ReceiptServiceInput (org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput)2 ConsentManager (org.wso2.carbon.consent.mgt.core.ConsentManager)1 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)1 ConsentUtilityService (org.wso2.carbon.identity.consent.mgt.services.ConsentUtilityService)1 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)1