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);
}
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();
}
}
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);
}
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());
}
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);
}
Aggregations