Search in sources :

Example 11 with ConsentManager

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

the class UserSelfRegistrationManager method validateAndFilterFromReceipt.

private void validateAndFilterFromReceipt(String consent, Map<String, String> claimsMap) throws IdentityRecoveryServerException {
    if (StringUtils.isEmpty(consent)) {
        return;
    }
    ConsentManager consentManager = IdentityRecoveryServiceDataHolder.getInstance().getConsentManager();
    try {
        List<Purpose> purposes = consentManager.listPurposes(PURPOSE_GROUP_SELF_REGISTER, PURPOSE_GROUP_TYPE_SYSTEM, 0, 0);
        Gson gson = new Gson();
        ReceiptInput receiptInput = gson.fromJson(consent, ReceiptInput.class);
        validateUserConsent(receiptInput, purposes);
        filterClaimsFromReceipt(receiptInput, claimsMap);
    } catch (ConsentManagementException e) {
        throw new IdentityRecoveryServerException("Error while retrieving System purposes for self registration", e);
    }
}
Also used : 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) Purpose(org.wso2.carbon.consent.mgt.core.model.Purpose) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager)

Example 12 with ConsentManager

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

the class ConsentDeletionAppMgtListener method doPostDeleteApplication.

/**
 * When an application is deleted, it will delete all relevant receipts issued againsed that application.
 *
 * @param applicationName Name of the application which is getting deleted.
 * @param tenantDomain    Tenant domain of the application.
 * @param userName        Username of the person who does the deletion.
 * @return true.
 * @throws IdentityApplicationManagementException IdentityApplicationManagementException.
 */
@Override
public boolean doPostDeleteApplication(String applicationName, String tenantDomain, String userName) throws IdentityApplicationManagementException {
    ConsentManager consentManager = IdentityConsentDataHolder.getInstance().getConsentManager();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Deleting consents on deletion of application: %s, in tenant domain: %s.", applicationName, tenantDomain));
    }
    try {
        List<ReceiptListResponse> receiptListResponses = consentManager.searchReceipts(consentSearchLimit, 0, "*", tenantDomain, applicationName, null, null);
        if (log.isDebugEnabled()) {
            log.debug(String.format("%d number of consents found for application %s", receiptListResponses.size(), applicationName));
        }
        receiptListResponses.forEach(rethrowConsumer(receiptListResponse -> {
            if (log.isDebugEnabled()) {
                log.debug(String.format("Deleting receipt with id : %s, issued for user: ", receiptListResponse.getConsentReceiptId(), receiptListResponse.getPiiPrincipalId()));
            }
            consentManager.deleteReceipt(receiptListResponse.getConsentReceiptId());
        }));
    } catch (ConsentManagementException e) {
        throw new IdentityApplicationManagementException("Error while deleting user consents for application " + applicationName, e);
    }
    return true;
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityConsentMgtUtils(org.wso2.carbon.identity.consent.mgt.IdentityConsentMgtUtils) IdentityConsentDataHolder(org.wso2.carbon.identity.consent.mgt.internal.IdentityConsentDataHolder) Properties(java.util.Properties) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) LambdaExceptionUtils.rethrowConsumer(org.wso2.carbon.identity.core.util.LambdaExceptionUtils.rethrowConsumer) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) List(java.util.List) Map(java.util.Map) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) IdentityUtil(org.wso2.carbon.identity.core.util.IdentityUtil) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager)

Example 13 with ConsentManager

use of org.wso2.carbon.consent.mgt.core.ConsentManager 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);
}
Also used : ConsentUtilityServiceException(org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException) PurposePIICategory(org.wso2.carbon.consent.mgt.core.model.PurposePIICategory) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) Purpose(org.wso2.carbon.consent.mgt.core.model.Purpose) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager)

Aggregations

ConsentManager (org.wso2.carbon.consent.mgt.core.ConsentManager)12 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)7 Test (org.testng.annotations.Test)6 ReceiptListResponse (org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse)5 RealmService (org.wso2.carbon.user.core.service.RealmService)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Receipt (org.wso2.carbon.consent.mgt.core.model.Receipt)3 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)3 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)3 Gson (com.google.gson.Gson)2 Map (java.util.Map)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ConsentManagerImpl (org.wso2.carbon.consent.mgt.core.ConsentManagerImpl)2 Purpose (org.wso2.carbon.consent.mgt.core.model.Purpose)2 ReceiptInput (org.wso2.carbon.consent.mgt.core.model.ReceiptInput)2 ReceiptServiceInput (org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput)2 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2