Search in sources :

Example 1 with ConsentReceiptDTO

use of org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO in project identity-governance by wso2-extensions.

the class Utils method getConsentReceiptDTO.

/**
 * This API is used to get ConsentReceiptDTO response.
 *
 * @param receipt Receipt instance.
 * @return ConsentReceiptDTO.
 */
public static ConsentReceiptDTO getConsentReceiptDTO(Receipt receipt) {
    ConsentReceiptDTO consentReceiptDTO = new ConsentReceiptDTO();
    consentReceiptDTO.setCollectionMethod(receipt.getCollectionMethod());
    consentReceiptDTO.setConsentReceiptID(receipt.getConsentReceiptId());
    consentReceiptDTO.setJurisdiction(receipt.getJurisdiction());
    consentReceiptDTO.setConsentTimestamp(receipt.getConsentTimestamp());
    consentReceiptDTO.setLanguage(receipt.getLanguage());
    consentReceiptDTO.setPiiPrincipalId(receipt.getPiiPrincipalId());
    consentReceiptDTO.setPolicyUrl(receipt.getPolicyUrl());
    consentReceiptDTO.setSensitive(receipt.isSensitive());
    consentReceiptDTO.setTenantDomain(receipt.getTenantDomain());
    consentReceiptDTO.setVersion(receipt.getVersion());
    consentReceiptDTO.setState(receipt.getState());
    consentReceiptDTO.setServices(receipt.getServices().stream().map(receiptService -> {
        ServiceDTO serviceDTO = new ServiceDTO();
        serviceDTO.setService(receiptService.getService());
        serviceDTO.setTenantDomain(receiptService.getTenantDomain());
        serviceDTO.setPurposes(receiptService.getPurposes().stream().map(consentPurpose -> {
            PurposeDTO purposeDTO = new PurposeDTO();
            purposeDTO.setConsentType(consentPurpose.getConsentType());
            purposeDTO.setPiiCategory(consentPurpose.getPiiCategory().stream().map(piiCategoryValidity -> {
                PiiCategoryDTO piiCategoryDTO = new PiiCategoryDTO();
                piiCategoryDTO.setPiiCategory(piiCategoryValidity.getName());
                piiCategoryDTO.setValidity(piiCategoryValidity.getValidity());
                return piiCategoryDTO;
            }).collect(Collectors.toList()));
            purposeDTO.setPrimaryPurpose(consentPurpose.isPrimaryPurpose());
            purposeDTO.setPurpose(consentPurpose.getPurpose());
            purposeDTO.setPurposeCategory(consentPurpose.getPurposeCategory());
            purposeDTO.setTermination(consentPurpose.getTermination());
            purposeDTO.setThirdPartyDisclosure(consentPurpose.isThirdPartyDisclosure());
            purposeDTO.setThirdPartyName(consentPurpose.getThirdPartyName());
            return purposeDTO;
        }).collect(Collectors.toList()));
        return serviceDTO;
    }).collect(Collectors.toList()));
    consentReceiptDTO.setSpiCat(receipt.getSpiCat());
    consentReceiptDTO.setPiiControllers(receipt.getPiiControllers().stream().map(piiController -> {
        PiiControllerDTO piiControllerDTO = new PiiControllerDTO();
        AddressDTO addressDTO = new AddressDTO();
        consentReceiptDTO.setPublicKey(receipt.getPublicKey());
        addressDTO.setAddressCountry(piiController.getAddress().getAddressCountry());
        addressDTO.setAddressLocality(piiController.getAddress().getAddressLocality());
        addressDTO.setAddressRegion(piiController.getAddress().getAddressRegion());
        addressDTO.setPostalCode(piiController.getAddress().getPostalCode());
        addressDTO.setPostOfficeBoxNumber(piiController.getAddress().getPostOfficeBoxNumber());
        addressDTO.setStreetAddress(piiController.getAddress().getStreetAddress());
        piiControllerDTO.setAddress(addressDTO);
        piiControllerDTO.setContact(piiController.getContact());
        piiControllerDTO.setEmail(piiController.getEmail());
        piiControllerDTO.setPhone(piiController.getPhone());
        piiControllerDTO.setPiiController(piiController.getPiiController());
        piiControllerDTO.setPiiControllerUrl(piiController.getPiiControllerUrl());
        piiControllerDTO.setOnBehalf(piiController.isOnBehalf());
        return piiControllerDTO;
    }).collect(Collectors.toList()));
    return consentReceiptDTO;
}
Also used : ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) PurposeDTO(org.wso2.carbon.identity.user.export.core.dto.PurposeDTO) PiiControllerDTO(org.wso2.carbon.identity.user.export.core.dto.PiiControllerDTO) ServiceDTO(org.wso2.carbon.identity.user.export.core.dto.ServiceDTO) PiiCategoryDTO(org.wso2.carbon.identity.user.export.core.dto.PiiCategoryDTO) AddressDTO(org.wso2.carbon.identity.user.export.core.dto.AddressDTO)

Example 2 with ConsentReceiptDTO

use of org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO in project identity-governance by wso2-extensions.

the class ConsentInformationProviderTest method testGetRetainedUserInformation.

@Test
public void testGetRetainedUserInformation() throws Exception {
    RealmService realmService = mock(RealmService.class);
    TenantManager tenantManager = mock(TenantManager.class);
    when(realmService.getTenantManager()).thenReturn(tenantManager);
    when(tenantManager.getDomain(anyInt())).thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    ReceiptListResponse receiptListResponse = new ReceiptListResponse("test1", "test1", "1", -1234, "test1", "test1", "test1");
    List<ReceiptListResponse> receiptListResponses = new ArrayList<>();
    receiptListResponses.add(receiptListResponse);
    ConsentManager consentManager = mock(ConsentManager.class);
    when(consentManager.searchReceipts(eq(100), eq(0), anyString(), anyString(), isNull(), anyString())).thenReturn(receiptListResponses);
    when(consentManager.searchReceipts(eq(100), eq(100), anyString(), anyString(), isNull(), anyString())).thenReturn(new ArrayList<ReceiptListResponse>());
    Receipt mockReceipt = mock(Receipt.class);
    when(mockReceipt.getPiiPrincipalId()).thenReturn(USERNAME_CLAIM_VALUE);
    when(consentManager.getReceipt(anyString())).thenReturn(mockReceipt);
    ConsentInformationProvider consentInformationProvider = new ConsentInformationProvider();
    consentInformationProvider.setRealmService(realmService);
    consentInformationProvider.setConsentManager(consentManager);
    UserInformationDTO retainedUserInformationObj = consentInformationProvider.getRetainedUserInformation(USERNAME_CLAIM_VALUE, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, -1234);
    if (retainedUserInformationObj != null && retainedUserInformationObj.getData() instanceof List) {
        List retainedUserInformationList = (List) retainedUserInformationObj.getData();
        Object receiptObj = retainedUserInformationList.get(0);
        if (receiptObj instanceof ConsentReceiptDTO) {
            ConsentReceiptDTO receipt = (ConsentReceiptDTO) receiptObj;
            Assert.assertEquals(receipt.getPiiPrincipalId(), USERNAME_CLAIM_VALUE);
        } else {
            Assert.fail();
        }
    } else {
        Assert.fail();
    }
}
Also used : ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) Receipt(org.wso2.carbon.consent.mgt.core.model.Receipt) ArrayList(java.util.ArrayList) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO) RealmService(org.wso2.carbon.user.core.service.RealmService) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) ArrayList(java.util.ArrayList) List(java.util.List) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Test(org.testng.annotations.Test)

Example 3 with ConsentReceiptDTO

use of org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO in project identity-governance by wso2-extensions.

the class UtilsTest method testGetConsentReceiptDTO.

@Test
public void testGetConsentReceiptDTO() throws Exception {
    Receipt receipt = new Receipt();
    receipt.setConsentReceiptId(CONSENT_RECEIPT_ID);
    receipt.setVersion(RECEIPT_VERSION);
    receipt.setJurisdiction(RECEIPT_JURISDICTION);
    receipt.setCollectionMethod(RECEIPT_COLLECTION_METHOD);
    receipt.setLanguage(RECEIPT_LANGUAGE);
    receipt.setPiiPrincipalId(USERNAME_CLAIM_VALUE);
    receipt.setConsentTimestamp(1517447315404L);
    PiiController piiController = new PiiController(PII_CONTROLLER_NAME, false, PII_CONTROLLER_CONTACT, PII_CONTROLLER_EMAIL, PII_CONTROLLER_PHONE, PII_CONTROLLER_URL, new Address(ADDRESS_COUNTRY, ADDRESS_LOCALITY, ADDRESS_REGION, ADDRESS_OFFICE_BOX_NUMBER, ADDRESS_POSTAL_CODE, ADDRESS_STREET_ADDRESS));
    List<PiiController> piiControllers = new ArrayList<>();
    piiControllers.add(piiController);
    receipt.setPiiControllers(piiControllers);
    ReceiptService receiptService = new ReceiptService();
    receiptService.setService(SERVICE_TRAVELOCITY);
    receiptService.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    receiptService.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    receiptService.setReceiptToServiceId(1);
    ConsentPurpose consentPurpose = new ConsentPurpose();
    consentPurpose.setPurpose(CONSENT_PURPOSE);
    List<String> purposeCategories = new ArrayList<>();
    purposeCategories.add(PURPOSE_CATEGORY);
    consentPurpose.setPurposeCategory(purposeCategories);
    consentPurpose.setConsentType(CONSENT_TYPE);
    PIICategoryValidity piiCategory = new PIICategoryValidity(PII_CATEGORY_ID, PII_CATEGORY_VALIDITY);
    List<PIICategoryValidity> piiCategories = new ArrayList<>();
    piiCategories.add(piiCategory);
    consentPurpose.setPiiCategory(piiCategories);
    consentPurpose.setPrimaryPurpose(true);
    consentPurpose.setTermination(CONSENT_TERMINATION);
    consentPurpose.setThirdPartyDisclosure(false);
    consentPurpose.setServiceToPurposeId(1);
    List<ConsentPurpose> purposes = new ArrayList<>();
    purposes.add(consentPurpose);
    receiptService.setPurposes(purposes);
    List<ReceiptService> receiptServices = new ArrayList<>();
    receiptServices.add(receiptService);
    receipt.setServices(receiptServices);
    receipt.setPolicyUrl(RECEIPT_POLICY_URL);
    receipt.setSensitive(true);
    receipt.setState(RECEIPT_STATE);
    receipt.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    receipt.setTenantId(-1234);
    List<String> spiCategory = new ArrayList<>();
    spiCategory.add(SPI_CATEGORY);
    receipt.setSpiCat(spiCategory);
    ConsentReceiptDTO consentReceiptDTO = Utils.getConsentReceiptDTO(receipt);
    Assert.assertEquals(consentReceiptDTO.getConsentReceiptID(), CONSENT_RECEIPT_ID);
    Assert.assertEquals(consentReceiptDTO.getVersion(), RECEIPT_VERSION);
    Assert.assertEquals(consentReceiptDTO.getJurisdiction(), RECEIPT_JURISDICTION);
    Assert.assertEquals(consentReceiptDTO.getCollectionMethod(), RECEIPT_COLLECTION_METHOD);
    Assert.assertEquals(consentReceiptDTO.getLanguage(), RECEIPT_LANGUAGE);
    Assert.assertEquals(consentReceiptDTO.getPolicyUrl(), RECEIPT_POLICY_URL);
    Assert.assertEquals(consentReceiptDTO.getSensitive(), Boolean.TRUE);
    Assert.assertEquals(consentReceiptDTO.getState(), RECEIPT_STATE);
    Assert.assertEquals(consentReceiptDTO.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    Assert.assertEquals(consentReceiptDTO.getConsentTimestamp(), Long.valueOf(RECEIPT_CONSENT_TIMESTAMP));
    Assert.assertEquals(consentReceiptDTO.getSpiCat().size(), 1);
    Assert.assertEquals(consentReceiptDTO.getSpiCat().get(0), SPI_CATEGORY);
    List<PiiControllerDTO> piiControllersFromDTO = consentReceiptDTO.getPiiControllers();
    Assert.assertEquals(piiControllersFromDTO.size(), 1);
    Assert.assertEquals(piiControllersFromDTO.get(0).getContact(), PII_CONTROLLER_CONTACT);
    Assert.assertEquals(piiControllersFromDTO.get(0).getEmail(), PII_CONTROLLER_EMAIL);
    Assert.assertEquals(piiControllersFromDTO.get(0).getPhone(), PII_CONTROLLER_PHONE);
    Assert.assertEquals(piiControllersFromDTO.get(0).getPiiControllerUrl(), PII_CONTROLLER_URL);
    Assert.assertEquals(piiControllersFromDTO.get(0).getPiiController(), PII_CONTROLLER_NAME);
    Assert.assertEquals(piiControllersFromDTO.get(0).getOnBehalf(), Boolean.FALSE);
    Assert.assertEquals(piiControllersFromDTO.get(0).getAddress().getAddressCountry(), ADDRESS_COUNTRY);
    Assert.assertEquals(piiControllersFromDTO.get(0).getAddress().getAddressLocality(), ADDRESS_LOCALITY);
    Assert.assertEquals(piiControllersFromDTO.get(0).getAddress().getAddressRegion(), ADDRESS_REGION);
    Assert.assertEquals(piiControllersFromDTO.get(0).getAddress().getPostalCode(), ADDRESS_POSTAL_CODE);
    Assert.assertEquals(piiControllersFromDTO.get(0).getAddress().getPostOfficeBoxNumber(), ADDRESS_OFFICE_BOX_NUMBER);
    Assert.assertEquals(piiControllersFromDTO.get(0).getAddress().getStreetAddress(), ADDRESS_STREET_ADDRESS);
    Assert.assertEquals(consentReceiptDTO.getServices().size(), 1);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getService(), SERVICE_TRAVELOCITY);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().size(), 1);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getConsentType(), CONSENT_TYPE);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getPurpose(), CONSENT_PURPOSE);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getTermination(), CONSENT_TERMINATION);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getThirdPartyName(), null);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getThirdPartyDisclosure(), Boolean.FALSE);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getPrimaryPurpose(), Boolean.TRUE);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getPiiCategory().size(), 1);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getPiiCategory().get(0).getValidity(), PII_CATEGORY_VALIDITY);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getPurposeCategory().size(), 1);
    Assert.assertEquals(consentReceiptDTO.getServices().get(0).getPurposes().get(0).getPurposeCategory().get(0), PURPOSE_CATEGORY);
}
Also used : PiiController(org.wso2.carbon.consent.mgt.core.model.PiiController) ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) Receipt(org.wso2.carbon.consent.mgt.core.model.Receipt) ReceiptService(org.wso2.carbon.consent.mgt.core.model.ReceiptService) Address(org.wso2.carbon.consent.mgt.core.model.Address) PiiControllerDTO(org.wso2.carbon.identity.user.export.core.dto.PiiControllerDTO) ArrayList(java.util.ArrayList) ConsentPurpose(org.wso2.carbon.consent.mgt.core.model.ConsentPurpose) PIICategoryValidity(org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity) Test(org.testng.annotations.Test)

Example 4 with ConsentReceiptDTO

use of org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO 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)

Aggregations

ConsentReceiptDTO (org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO)4 ArrayList (java.util.ArrayList)3 Receipt (org.wso2.carbon.consent.mgt.core.model.Receipt)3 Test (org.testng.annotations.Test)2 ReceiptListResponse (org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse)2 PiiControllerDTO (org.wso2.carbon.identity.user.export.core.dto.PiiControllerDTO)2 UserInformationDTO (org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)2 List (java.util.List)1 ConsentManager (org.wso2.carbon.consent.mgt.core.ConsentManager)1 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)1 Address (org.wso2.carbon.consent.mgt.core.model.Address)1 ConsentPurpose (org.wso2.carbon.consent.mgt.core.model.ConsentPurpose)1 PIICategoryValidity (org.wso2.carbon.consent.mgt.core.model.PIICategoryValidity)1 PiiController (org.wso2.carbon.consent.mgt.core.model.PiiController)1 ReceiptService (org.wso2.carbon.consent.mgt.core.model.ReceiptService)1 UserExportException (org.wso2.carbon.identity.user.export.core.UserExportException)1 AddressDTO (org.wso2.carbon.identity.user.export.core.dto.AddressDTO)1 PiiCategoryDTO (org.wso2.carbon.identity.user.export.core.dto.PiiCategoryDTO)1 PurposeDTO (org.wso2.carbon.identity.user.export.core.dto.PurposeDTO)1 ServiceDTO (org.wso2.carbon.identity.user.export.core.dto.ServiceDTO)1