Search in sources :

Example 1 with ReceiptInput

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;
}
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 ReceiptInput

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;
}
Also used : JSONObject(org.json.JSONObject) ReceiptInput(org.wso2.carbon.consent.mgt.core.model.ReceiptInput)

Example 3 with 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);
    }
}
Also used : ReceiptServiceInput(org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) PostAuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)

Example 4 with ReceiptInput

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());
    }
}
Also used : AddReceiptResponse(org.wso2.carbon.consent.mgt.core.model.AddReceiptResponse) ReceiptInput(org.wso2.carbon.consent.mgt.core.model.ReceiptInput) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) SSOConsentServiceException(org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.exception.SSOConsentServiceException)

Example 5 with ReceiptInput

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);
}
Also used : ReceiptServiceInput(org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput) ReceiptInput(org.wso2.carbon.consent.mgt.core.model.ReceiptInput) IdentityRecoveryServerException(org.wso2.carbon.identity.recovery.IdentityRecoveryServerException) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) Gson(com.google.gson.Gson) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Aggregations

ReceiptInput (org.wso2.carbon.consent.mgt.core.model.ReceiptInput)6 ReceiptServiceInput (org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput)5 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)4 ConsentManager (org.wso2.carbon.consent.mgt.core.ConsentManager)3 PIICategoryValidity (org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)3 Purpose (org.wso2.carbon.consent.mgt.core.model.Purpose)3 ReceiptPurposeInput (org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput)3 ConsentUtilityServiceException (org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException)3 IdentityRecoveryServerException (org.wso2.carbon.identity.recovery.IdentityRecoveryServerException)3 Gson (com.google.gson.Gson)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JSONObject (org.json.JSONObject)1 AddReceiptResponse (org.wso2.carbon.consent.mgt.core.model.AddReceiptResponse)1 ConsentPurpose (org.wso2.carbon.consent.mgt.core.model.ConsentPurpose)1 PurposeCategory (org.wso2.carbon.consent.mgt.core.model.PurposeCategory)1 PostAuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)1 SSOConsentServiceException (org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.exception.SSOConsentServiceException)1 ConsentUtilityService (org.wso2.carbon.identity.consent.mgt.services.ConsentUtilityService)1