Search in sources :

Example 1 with PIICategoryValidity

use of org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity 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 PIICategoryValidity

use of org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity in project carbon-identity-framework by wso2.

the class JITProvisioningPostAuthenticationHandler method getReceiptPurposeInputs.

/**
 * To get the receive purpose inputs from json object from the client side.
 *
 * @param receiptPurpose Relevant receipt purpose.
 * @return receipt purpose input, based on receipt purpose object.
 */
private ReceiptPurposeInput getReceiptPurposeInputs(JSONObject receiptPurpose) {
    ReceiptPurposeInput receiptPurposeInput = new ReceiptPurposeInput();
    receiptPurposeInput.setConsentType(FrameworkConstants.Consent.EXPLICIT_CONSENT_TYPE);
    receiptPurposeInput.setPrimaryPurpose(true);
    receiptPurposeInput.setThirdPartyDisclosure(false);
    receiptPurposeInput.setPurposeId(receiptPurpose.getInt("purposeId"));
    JSONArray purposeCategoryId = receiptPurpose.getJSONArray("purposeCategoryId");
    List<Integer> purposeCategoryIdArray = new ArrayList<>();
    for (int index = 0; index < purposeCategoryId.length(); index++) {
        purposeCategoryIdArray.add(purposeCategoryId.getInt(index));
    }
    receiptPurposeInput.setTermination(FrameworkConstants.Consent.INFINITE_TERMINATION);
    receiptPurposeInput.setPurposeCategoryId(purposeCategoryIdArray);
    receiptPurposeInput.setTermination(FrameworkConstants.Consent.INFINITE_TERMINATION);
    List<PIICategoryValidity> piiCategoryValidities = new ArrayList<>();
    JSONArray piiCategories = (JSONArray) receiptPurpose.get(FrameworkConstants.Consent.PII_CATEGORY);
    for (int categoryIndex = 0; categoryIndex < piiCategories.length(); categoryIndex++) {
        JSONObject piiCategory = (JSONObject) piiCategories.get(categoryIndex);
        PIICategoryValidity piiCategoryValidity = new PIICategoryValidity(piiCategory.getInt("piiCategoryId"), FrameworkConstants.Consent.INFINITE_TERMINATION);
        piiCategoryValidity.setConsented(true);
        piiCategoryValidities.add(piiCategoryValidity);
    }
    receiptPurposeInput.setPiiCategory(piiCategoryValidities);
    return receiptPurposeInput;
}
Also used : JSONObject(org.json.JSONObject) ReceiptPurposeInput(org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) PIICategoryValidity(org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)

Example 3 with PIICategoryValidity

use of org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity in project carbon-identity-framework by wso2.

the class SSOConsentServiceImpl method getReceiptPurposeInput.

private ReceiptPurposeInput getReceiptPurposeInput(String consentType, String termination, Purpose purpose, List<PIICategoryValidity> piiCategoryIds, List<Integer> purposeCategoryIds) {
    ReceiptPurposeInput purposeInput = new ReceiptPurposeInput();
    purposeInput.setPrimaryPurpose(true);
    purposeInput.setTermination(termination);
    purposeInput.setConsentType(consentType);
    purposeInput.setThirdPartyDisclosure(false);
    purposeInput.setPurposeId(purpose.getId());
    purposeInput.setPurposeCategoryId(purposeCategoryIds);
    purposeInput.setPiiCategory(piiCategoryIds);
    return purposeInput;
}
Also used : ReceiptPurposeInput(org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput)

Example 4 with PIICategoryValidity

use of org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity in project carbon-identity-framework by wso2.

the class SSOConsentServiceImpl method getPiiCategoryValidityForRequestedClaims.

private List<PIICategoryValidity> getPiiCategoryValidityForRequestedClaims(List<ClaimMetaData> requestedClaims, boolean isConsented, String termination) throws SSOConsentServiceException {
    List<PIICategoryValidity> piiCategoryIds = new ArrayList<>();
    if (CollectionUtils.isEmpty(requestedClaims)) {
        return piiCategoryIds;
    }
    for (ClaimMetaData requestedClaim : requestedClaims) {
        if (requestedClaim == null || requestedClaim.getClaimUri() == null) {
            continue;
        }
        PIICategory piiCategory;
        try {
            piiCategory = getConsentManager().getPIICategoryByName(requestedClaim.getClaimUri());
        } catch (ConsentManagementClientException e) {
            if (isInvalidPIICategoryError(e)) {
                piiCategory = addPIICategoryForClaim(requestedClaim);
            } else {
                throw new SSOConsentServiceException("Consent PII category error", "Error while retrieving" + " PII category: " + DEFAULT_PURPOSE_CATEGORY, e);
            }
        } catch (ConsentManagementException e) {
            throw new SSOConsentServiceException("Consent PII category error", "Error while retrieving " + "PII category: " + DEFAULT_PURPOSE_CATEGORY, e);
        }
        PIICategoryValidity piiCategoryValidity = new PIICategoryValidity(piiCategory.getId(), termination);
        piiCategoryValidity.setConsented(isConsented);
        piiCategoryIds.add(piiCategoryValidity);
    }
    return piiCategoryIds;
}
Also used : PIICategory(org.wso2.carbon.consent.mgt.core.model.PIICategory) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) ArrayList(java.util.ArrayList) SSOConsentServiceException(org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.exception.SSOConsentServiceException) PIICategoryValidity(org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity) ConsentManagementClientException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementClientException)

Example 5 with PIICategoryValidity

use of org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity in project identity-governance by wso2-extensions.

the class Utils method getConsentReceiptDTO.

/**
 * This API is used to get ConsentReceiptDTO response.
 *
 * @param receipt Receipt instance.
 * @return ConsentReceiptDTO.
 */
public static ConsentReceiptDTO getConsentReceiptDTO(Receipt receipt) {
    ConsentReceiptDTO consentReceiptDTO = new ConsentReceiptDTO();
    consentReceiptDTO.setCollectionMethod(receipt.getCollectionMethod());
    consentReceiptDTO.setConsentReceiptID(receipt.getConsentReceiptId());
    consentReceiptDTO.setJurisdiction(receipt.getJurisdiction());
    consentReceiptDTO.setConsentTimestamp(receipt.getConsentTimestamp());
    consentReceiptDTO.setLanguage(receipt.getLanguage());
    consentReceiptDTO.setPiiPrincipalId(receipt.getPiiPrincipalId());
    consentReceiptDTO.setPolicyUrl(receipt.getPolicyUrl());
    consentReceiptDTO.setSensitive(receipt.isSensitive());
    consentReceiptDTO.setTenantDomain(receipt.getTenantDomain());
    consentReceiptDTO.setVersion(receipt.getVersion());
    consentReceiptDTO.setState(receipt.getState());
    consentReceiptDTO.setServices(receipt.getServices().stream().map(receiptService -> {
        ServiceDTO serviceDTO = new ServiceDTO();
        serviceDTO.setService(receiptService.getService());
        serviceDTO.setTenantDomain(receiptService.getTenantDomain());
        serviceDTO.setPurposes(receiptService.getPurposes().stream().map(consentPurpose -> {
            PurposeDTO purposeDTO = new PurposeDTO();
            purposeDTO.setConsentType(consentPurpose.getConsentType());
            purposeDTO.setPiiCategory(consentPurpose.getPiiCategory().stream().map(piiCategoryValidity -> {
                PiiCategoryDTO piiCategoryDTO = new PiiCategoryDTO();
                piiCategoryDTO.setPiiCategory(piiCategoryValidity.getName());
                piiCategoryDTO.setValidity(piiCategoryValidity.getValidity());
                return piiCategoryDTO;
            }).collect(Collectors.toList()));
            purposeDTO.setPrimaryPurpose(consentPurpose.isPrimaryPurpose());
            purposeDTO.setPurpose(consentPurpose.getPurpose());
            purposeDTO.setPurposeCategory(consentPurpose.getPurposeCategory());
            purposeDTO.setTermination(consentPurpose.getTermination());
            purposeDTO.setThirdPartyDisclosure(consentPurpose.isThirdPartyDisclosure());
            purposeDTO.setThirdPartyName(consentPurpose.getThirdPartyName());
            return purposeDTO;
        }).collect(Collectors.toList()));
        return serviceDTO;
    }).collect(Collectors.toList()));
    consentReceiptDTO.setSpiCat(receipt.getSpiCat());
    consentReceiptDTO.setPiiControllers(receipt.getPiiControllers().stream().map(piiController -> {
        PiiControllerDTO piiControllerDTO = new PiiControllerDTO();
        AddressDTO addressDTO = new AddressDTO();
        consentReceiptDTO.setPublicKey(receipt.getPublicKey());
        addressDTO.setAddressCountry(piiController.getAddress().getAddressCountry());
        addressDTO.setAddressLocality(piiController.getAddress().getAddressLocality());
        addressDTO.setAddressRegion(piiController.getAddress().getAddressRegion());
        addressDTO.setPostalCode(piiController.getAddress().getPostalCode());
        addressDTO.setPostOfficeBoxNumber(piiController.getAddress().getPostOfficeBoxNumber());
        addressDTO.setStreetAddress(piiController.getAddress().getStreetAddress());
        piiControllerDTO.setAddress(addressDTO);
        piiControllerDTO.setContact(piiController.getContact());
        piiControllerDTO.setEmail(piiController.getEmail());
        piiControllerDTO.setPhone(piiController.getPhone());
        piiControllerDTO.setPiiController(piiController.getPiiController());
        piiControllerDTO.setPiiControllerUrl(piiController.getPiiControllerUrl());
        piiControllerDTO.setOnBehalf(piiController.isOnBehalf());
        return piiControllerDTO;
    }).collect(Collectors.toList()));
    return consentReceiptDTO;
}
Also used : ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) PurposeDTO(org.wso2.carbon.identity.user.export.core.dto.PurposeDTO) PiiControllerDTO(org.wso2.carbon.identity.user.export.core.dto.PiiControllerDTO) ServiceDTO(org.wso2.carbon.identity.user.export.core.dto.ServiceDTO) PiiCategoryDTO(org.wso2.carbon.identity.user.export.core.dto.PiiCategoryDTO) AddressDTO(org.wso2.carbon.identity.user.export.core.dto.AddressDTO)

Aggregations

PIICategoryValidity (org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)7 ArrayList (java.util.ArrayList)5 ReceiptPurposeInput (org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput)5 ReceiptServiceInput (org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput)3 ConsentPurpose (org.wso2.carbon.consent.mgt.core.model.ConsentPurpose)2 Purpose (org.wso2.carbon.consent.mgt.core.model.Purpose)2 ConsentUtilityServiceException (org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException)2 ConsentReceiptDTO (org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO)2 PiiControllerDTO (org.wso2.carbon.identity.user.export.core.dto.PiiControllerDTO)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 Test (org.testng.annotations.Test)1 ConsentManagementClientException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementClientException)1 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)1 Address (org.wso2.carbon.consent.mgt.core.model.Address)1 PIICategory (org.wso2.carbon.consent.mgt.core.model.PIICategory)1 PiiController (org.wso2.carbon.consent.mgt.core.model.PiiController)1 PurposeCategory (org.wso2.carbon.consent.mgt.core.model.PurposeCategory)1