Search in sources :

Example 1 with ReceiptServiceInput

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

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

the class JITProvisioningPostAuthenticationHandler method setIDPData.

/**
 * Set the IDP releated data in the receipt service input.
 *
 * @param tenantDomain        Tenant domain.
 * @param receiptServiceInput Relevant receipt service input which the
 * @throws PostAuthenticationFailedException Post Authentication Failed Exception.
 */
private void setIDPData(String tenantDomain, ReceiptServiceInput receiptServiceInput) throws PostAuthenticationFailedException {
    String resideIdpDescription = "Resident IDP";
    IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
    IdentityProvider residentIdP = null;
    try {
        residentIdP = idpManager.getResidentIdP(tenantDomain);
    } catch (IdentityProviderManagementException e) {
        handleExceptions(String.format(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA.getMessage(), tenantDomain), ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA.getCode(), e);
    }
    if (residentIdP == null) {
        throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA_IDP_IS_NULL.getCode(), String.format(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA_IDP_IS_NULL.getMessage(), tenantDomain));
    }
    if (StringUtils.isEmpty(receiptServiceInput.getService())) {
        if (log.isDebugEnabled()) {
            log.debug("No service name found. Hence adding resident IDP home realm ID");
        }
        receiptServiceInput.setService(residentIdP.getHomeRealmId());
    }
    if (StringUtils.isEmpty(receiptServiceInput.getTenantDomain())) {
        receiptServiceInput.setTenantDomain(tenantDomain);
    }
    if (StringUtils.isEmpty(receiptServiceInput.getSpDescription())) {
        if (StringUtils.isNotEmpty(residentIdP.getIdentityProviderDescription())) {
            receiptServiceInput.setSpDescription(residentIdP.getIdentityProviderDescription());
        } else {
            receiptServiceInput.setSpDescription(resideIdpDescription);
        }
    }
    if (StringUtils.isEmpty(receiptServiceInput.getSpDisplayName())) {
        if (StringUtils.isNotEmpty(residentIdP.getDisplayName())) {
            receiptServiceInput.setSpDisplayName(residentIdP.getDisplayName());
        } else {
            receiptServiceInput.setSpDisplayName(resideIdpDescription);
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) PostAuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 3 with ReceiptServiceInput

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

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

the class SSOConsentServiceImpl method getReceiptServiceInput.

private ReceiptServiceInput getReceiptServiceInput(ServiceProvider serviceProvider, String spTenantDomain, List<ReceiptPurposeInput> purposeInputs) {
    ReceiptServiceInput serviceInput = new ReceiptServiceInput();
    serviceInput.setPurposes(purposeInputs);
    serviceInput.setTenantDomain(spTenantDomain);
    if (serviceProvider == null) {
        return serviceInput;
    }
    String spName = serviceProvider.getApplicationName();
    String spDescription;
    spDescription = serviceProvider.getDescription();
    if (StringUtils.isBlank(spDescription)) {
        spDescription = spName;
    }
    serviceInput.setService(spName);
    serviceInput.setSpDisplayName(spName);
    serviceInput.setSpDescription(spDescription);
    return serviceInput;
}
Also used : ReceiptServiceInput(org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput)

Example 5 with ReceiptServiceInput

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

the class UserSelfRegistrationManager method setIDPData.

private void setIDPData(String tenantDomain, ReceiptServiceInput receiptServiceInput) throws IdentityProviderManagementException {
    IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
    IdentityProvider residentIdP = idpManager.getResidentIdP(tenantDomain);
    if (StringUtils.isEmpty(receiptServiceInput.getService())) {
        if (log.isDebugEnabled()) {
            log.debug("No service name found. Hence adding resident IDP home realm ID");
        }
        receiptServiceInput.setService(residentIdP.getHomeRealmId());
    }
    if (StringUtils.isEmpty(receiptServiceInput.getTenantDomain())) {
        receiptServiceInput.setTenantDomain(tenantDomain);
    }
    if (StringUtils.isEmpty(receiptServiceInput.getSpDescription())) {
        if (StringUtils.isNotEmpty(residentIdP.getIdentityProviderDescription())) {
            receiptServiceInput.setSpDescription(residentIdP.getIdentityProviderDescription());
        } else {
            receiptServiceInput.setSpDescription(IdentityRecoveryConstants.Consent.RESIDENT_IDP);
        }
    }
    if (StringUtils.isEmpty(receiptServiceInput.getSpDisplayName())) {
        if (StringUtils.isNotEmpty(residentIdP.getDisplayName())) {
            receiptServiceInput.setSpDisplayName(residentIdP.getDisplayName());
        } else {
            receiptServiceInput.setSpDisplayName(IdentityRecoveryConstants.Consent.RESIDENT_IDP);
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager)

Aggregations

ReceiptServiceInput (org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput)7 ReceiptPurposeInput (org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput)4 PIICategoryValidity (org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)3 ArrayList (java.util.ArrayList)2 ConsentManager (org.wso2.carbon.consent.mgt.core.ConsentManager)2 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)2 Purpose (org.wso2.carbon.consent.mgt.core.model.Purpose)2 ReceiptInput (org.wso2.carbon.consent.mgt.core.model.ReceiptInput)2 PostAuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.PostAuthenticationFailedException)2 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)2 ConsentUtilityServiceException (org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException)2 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)2 IdentityProviderManager (org.wso2.carbon.idp.mgt.IdentityProviderManager)2 Gson (com.google.gson.Gson)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 ConsentPurpose (org.wso2.carbon.consent.mgt.core.model.ConsentPurpose)1 PurposeCategory (org.wso2.carbon.consent.mgt.core.model.PurposeCategory)1