Search in sources :

Example 26 with Receipt

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

the class UserSelfRegistrationManager method filterClaimsFromReceipt.

private void filterClaimsFromReceipt(ReceiptInput receiptInput, Map<String, String> claims) throws IdentityRecoveryServerException {
    ConsentUtilityService consentUtilityService = IdentityRecoveryServiceDataHolder.getInstance().getConsentUtilityService();
    try {
        Set<String> filteredKeys = consentUtilityService.filterPIIsFromReceipt(claims.keySet(), receiptInput);
        claims.keySet().retainAll(filteredKeys);
    } catch (ConsentUtilityServiceException e) {
        throw new IdentityRecoveryServerException("Receipt validation failed against purposes", e);
    }
}
Also used : ConsentUtilityServiceException(org.wso2.carbon.identity.consent.mgt.exceptions.ConsentUtilityServiceException) IdentityRecoveryServerException(org.wso2.carbon.identity.recovery.IdentityRecoveryServerException) ConsentUtilityService(org.wso2.carbon.identity.consent.mgt.services.ConsentUtilityService)

Example 27 with Receipt

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

the class ConsentInformationProvider method getRetainedUserInformation.

@Override
public UserInformationDTO getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
    try {
        List<ConsentReceiptDTO> receipts = new ArrayList<>();
        int limit = 100;
        int offset = 0;
        String tenantDomain = realmService.getTenantManager().getDomain(tenantId);
        List<ReceiptListResponse> receiptListResponses;
        do {
            receiptListResponses = consentManager.searchReceipts(limit, offset, UserCoreUtil.addDomainToName(username, userStoreDomain), tenantDomain, null, ConsentConstants.ACTIVE_STATE);
            for (ReceiptListResponse receiptListResponse : receiptListResponses) {
                String receiptId = receiptListResponse.getConsentReceiptId();
                Receipt receipt = consentManager.getReceipt(receiptId);
                receipts.add(Utils.getConsentReceiptDTO(receipt));
            }
            offset += limit;
        } while (receiptListResponses != null && receiptListResponses.size() != 0);
        if (receipts.size() > 0) {
            return new UserInformationDTO(receipts);
        }
    } catch (UserStoreException e) {
        throw new UserExportException("Error while retrieving tenant domain from tenant id: " + tenantId, e);
    } catch (ConsentManagementException e) {
        throw new UserExportException("Error while retrieving consent receipts for user: " + UserCoreUtil.addDomainToName(username, userStoreDomain) + " in tenant id: " + tenantId, e);
    }
    return new UserInformationDTO();
}
Also used : ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) Receipt(org.wso2.carbon.consent.mgt.core.model.Receipt) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)

Example 28 with Receipt

use of org.wso2.carbon.consent.mgt.core.model.Receipt in project product-is by wso2.

the class SelfSignUpConsentTest method getConsent.

private String getConsent(String username, String password, String receiptId) {
    log.info("Retrieving consent for username " + username + ". reciptId : " + receiptId);
    RestClient restClient = new RestClient();
    Resource resource = restClient.resource(consentEndpoint + "/receipts/" + receiptId);
    log.info("Calling to receipt endpoint :" + consentEndpoint + "/receipts/" + receiptId);
    User user = new User();
    user.setUserName(username);
    user.setPassword(password);
    String response = resource.contentType(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(user)).get(String.class);
    return response;
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) RestClient(org.apache.wink.client.RestClient) Resource(org.apache.wink.client.Resource)

Example 29 with Receipt

use of org.wso2.carbon.consent.mgt.core.model.Receipt in project product-is by wso2.

the class SelfSignUpConsentTest method getPurposes.

@Test(alwaysRun = true, groups = "wso2.is", description = "Test for a valid user", dependsOnMethods = "selfSignUpWithConsents")
public void getPurposes() throws Exception {
    updateResidentIDPProperty(tenantResidentIDP, ENABLE_SELF_REGISTRATION_PROP_KEY, "true", false);
    updateResidentIDPProperty(tenantResidentIDP, DISABLE_ACC_LOCK_ON_SELF_REG_PROP_KEY, "false", false);
    String consents = getConsents(EBONY + "@" + secondaryTenantDomain, PASSWORD);
    log.info("Consents for user " + EBONY + " :" + consents);
    Assert.assertNotNull(consents);
    JSONArray purposesJson = new JSONArray(consents);
    String receiptID = ((JSONObject) purposesJson.get(0)).getString("consentReceiptID");
    String receipt = getConsent(EBONY + "@" + secondaryTenantDomain, PASSWORD, receiptID);
    JSONObject receiptJson = new JSONObject(receipt);
    Assert.assertEquals(receiptJson.getString("collectionMethod"), "Web Form - Self Registration");
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.testng.annotations.Test) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest)

Aggregations

ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)9 Receipt (org.wso2.carbon.consent.mgt.core.model.Receipt)9 ArrayList (java.util.ArrayList)8 ConsentManager (org.wso2.carbon.consent.mgt.core.ConsentManager)7 ReceiptListResponse (org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse)7 JSONObject (org.json.JSONObject)6 Test (org.testng.annotations.Test)6 SSOConsentServiceException (org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.exception.SSOConsentServiceException)6 ReceiptServiceInput (org.wso2.carbon.consent.mgt.core.model.ReceiptServiceInput)5 PIICategoryValidity (org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)4 ReceiptPurposeInput (org.wso2.carbon.consent.mgt.core.model.ReceiptPurposeInput)4 ConsentReceiptDTO (org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 JSONArray (org.json.JSONArray)3 ReceiptInput (org.wso2.carbon.consent.mgt.core.model.ReceiptInput)3 SSOConsentDisabledException (org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.exception.SSOConsentDisabledException)3 RealmService (org.wso2.carbon.user.core.service.RealmService)3 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)3