Search in sources :

Example 6 with ConsentManager

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

the class ConsentInformationProviderTest method testGetRetainedUserInformationGetDomainException.

@Test(expectedExceptions = UserExportException.class)
public void testGetRetainedUserInformationGetDomainException() throws Exception {
    RealmService realmService = mock(RealmService.class);
    TenantManager tenantManager = mock(TenantManager.class);
    when(realmService.getTenantManager()).thenReturn(tenantManager);
    when(tenantManager.getDomain(anyInt())).thenThrow(new UserStoreException());
    ReceiptListResponse receiptListResponse = mock(ReceiptListResponse.class);
    List<ReceiptListResponse> receiptListResponses = new ArrayList<>();
    receiptListResponses.add(receiptListResponse);
    ConsentManager consentManager = mock(ConsentManager.class);
    when(consentManager.searchReceipts(eq(100), eq(0), anyString(), anyString(), anyString(), anyString())).thenReturn(receiptListResponses);
    when(consentManager.searchReceipts(eq(100), eq(100), anyString(), anyString(), anyString(), 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);
    consentInformationProvider.getRetainedUserInformation(USERNAME_CLAIM_VALUE, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, -1234);
}
Also used : Receipt(org.wso2.carbon.consent.mgt.core.model.Receipt) RealmService(org.wso2.carbon.user.core.service.RealmService) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) UserStoreException(org.wso2.carbon.user.api.UserStoreException) ArrayList(java.util.ArrayList) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Test(org.testng.annotations.Test)

Example 7 with ConsentManager

use of org.wso2.carbon.consent.mgt.core.ConsentManager 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 8 with ConsentManager

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

the class ConsentInformationProviderTest method testGetRetainedUserInformationSearchReceiptsException.

@Test(expectedExceptions = UserExportException.class)
public void testGetRetainedUserInformationSearchReceiptsException() 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);
    ConsentManager consentManager = mock(ConsentManager.class);
    when(consentManager.searchReceipts(eq(100), eq(00), anyString(), anyString(), isNull(), anyString())).thenThrow(new ConsentManagementException());
    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);
    consentInformationProvider.getRetainedUserInformation(USERNAME_CLAIM_VALUE, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, -1234);
}
Also used : Receipt(org.wso2.carbon.consent.mgt.core.model.Receipt) RealmService(org.wso2.carbon.user.core.service.RealmService) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Test(org.testng.annotations.Test)

Example 9 with ConsentManager

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

the class UserSelfRegistrationManagerTest method testAddConsent.

@Test
public void testAddConsent() throws Exception {
    IdentityProvider identityProvider = new IdentityProvider();
    mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager);
    when(identityProviderManager.getResidentIdP(ArgumentMatchers.anyString())).thenReturn(identityProvider);
    ConsentManager consentManager = new MyConsentManager(new ConsentManagerConfigurationHolder());
    IdentityRecoveryServiceDataHolder.getInstance().setConsentManager(consentManager);
    userSelfRegistrationManager.addUserConsent(consentData, "wso2.com");
    Assert.assertEquals(IdentityRecoveryConstants.Consent.COLLECTION_METHOD_SELF_REGISTRATION, resultReceipt.getCollectionMethod());
    Assert.assertEquals("someJurisdiction", resultReceipt.getJurisdiction());
    Assert.assertEquals("en", resultReceipt.getLanguage());
    Assert.assertNotNull(resultReceipt.getServices());
    Assert.assertEquals(1, resultReceipt.getServices().size());
    Assert.assertNotNull(resultReceipt.getServices().get(0).getPurposes());
    Assert.assertEquals(1, resultReceipt.getServices().get(0).getPurposes().size());
    Assert.assertEquals(new Integer(3), resultReceipt.getServices().get(0).getPurposes().get(0).getPurposeId());
    Assert.assertEquals(IdentityRecoveryConstants.Consent.EXPLICIT_CONSENT_TYPE, resultReceipt.getServices().get(0).getPurposes().get(0).getConsentType());
    Assert.assertEquals(IdentityRecoveryConstants.Consent.INFINITE_TERMINATION, resultReceipt.getServices().get(0).getPurposes().get(0).getTermination());
    Assert.assertEquals(new Integer(3), resultReceipt.getServices().get(0).getPurposes().get(0).getPurposeId());
}
Also used : ConsentManagerConfigurationHolder(org.wso2.carbon.consent.mgt.core.model.ConsentManagerConfigurationHolder) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 10 with ConsentManager

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

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