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