use of org.wso2.carbon.consent.mgt.core.model.ReceiptInput 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.consent.mgt.core.model.ReceiptInput in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandler method buildConsentForResidentIDP.
/**
* Builds consent receipt input according to consent API.
*
* @param piiPrincipalId P11 Principal ID
* @param consent Consent String which contains services.
* @param policyURL Policy URL.
* @return Consent string which contains above facts.
*/
private ReceiptInput buildConsentForResidentIDP(String piiPrincipalId, String consent, String policyURL) {
ReceiptInput receiptInput = new ReceiptInput();
receiptInput.setJurisdiction("USA");
receiptInput.setCollectionMethod(FrameworkConstants.Consent.COLLECTION_METHOD_JIT);
receiptInput.setLanguage(FrameworkConstants.Consent.LANGUAGE_ENGLISH);
receiptInput.setPiiPrincipalId(piiPrincipalId);
receiptInput.setPolicyUrl(policyURL);
JSONObject receipt = new JSONObject(consent);
receiptInput.setServices(getReceiptServiceInputs(receipt));
if (log.isDebugEnabled()) {
log.debug("Built consent from endpoint util : " + consent);
}
return receiptInput;
}
use of org.wso2.carbon.consent.mgt.core.model.ReceiptInput in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandler method addConsent.
/**
* Persist the consents received from the user, while user creation.
*
* @param receiptInput Relevant receipt input representing consent data.
* @param tenantDomain Relevant tenant domain.
* @throws PostAuthenticationFailedException Post Authentication Failed Exception.
*/
private void addConsent(ReceiptInput receiptInput, String tenantDomain) throws PostAuthenticationFailedException {
ConsentManager consentManager = FrameworkServiceDataHolder.getInstance().getConsentManager();
if (receiptInput.getServices().size() == 0) {
throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getCode(), String.format(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getMessage(), tenantDomain));
}
// There should be one receipt
ReceiptServiceInput receiptServiceInput = receiptInput.getServices().get(0);
receiptServiceInput.setTenantDomain(tenantDomain);
try {
setIDPData(tenantDomain, receiptServiceInput);
receiptInput.setTenantDomain(tenantDomain);
consentManager.addConsent(receiptInput);
} catch (ConsentManagementException e) {
handleExceptions(String.format(ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getMessage(), tenantDomain), ErrorMessages.ERROR_WHILE_ADDING_CONSENT.getCode(), e);
}
}
use of org.wso2.carbon.consent.mgt.core.model.ReceiptInput in project carbon-identity-framework by wso2.
the class SSOConsentServiceImpl method addReceipt.
private void addReceipt(String subject, String subjectTenantDomain, ServiceProvider serviceProvider, String spTenantDomain, List<ClaimMetaData> claimsWithConsent, List<ClaimMetaData> claimsDeniedConsent) throws SSOConsentServiceException {
ReceiptInput receiptInput = buildReceiptInput(subject, serviceProvider, spTenantDomain, claimsWithConsent, claimsDeniedConsent);
AddReceiptResponse receiptResponse;
try {
startTenantFlowWithUser(subject, subjectTenantDomain);
receiptResponse = getConsentManager().addConsent(receiptInput);
} catch (ConsentManagementException e) {
throw new SSOConsentServiceException("Consent receipt error", "Error while adding the consent " + "receipt", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
if (isDebugEnabled()) {
logDebug("Successfully added consent receipt: " + receiptResponse.getConsentReceiptId());
}
}
use of org.wso2.carbon.consent.mgt.core.model.ReceiptInput in project identity-governance by wso2-extensions.
the class UserSelfRegistrationManager method addConsent.
private void addConsent(String consent, String tenantDomain) throws ConsentManagementException, IdentityRecoveryServerException {
Gson gson = new Gson();
ReceiptInput receiptInput = gson.fromJson(consent, ReceiptInput.class);
ConsentManager consentManager = IdentityRecoveryServiceDataHolder.getInstance().getConsentManager();
if (receiptInput.getServices().size() < 0) {
throw new IdentityRecoveryServerException("A service should be available in a receipt");
}
// There should be a one receipt
ReceiptServiceInput receiptServiceInput = receiptInput.getServices().get(0);
// without giving consent to any of the purposes.
if (receiptServiceInput.getPurposes().isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Consent does not contain any purposes. Hence not adding consent");
}
return;
}
receiptServiceInput.setTenantDomain(tenantDomain);
try {
setIDPData(tenantDomain, receiptServiceInput);
} catch (IdentityProviderManagementException e) {
throw new ConsentManagementException("Error while retrieving identity provider data", "Error while " + "setting IDP data", e);
}
receiptInput.setTenantDomain(tenantDomain);
consentManager.addConsent(receiptInput);
}
Aggregations