use of org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse in project carbon-identity-framework by wso2.
the class ConsentDeletionUserEventHandler method handleEvent.
/**
* Delete consents issued against a particular user when a user is deleted.
*
* @param event Post User Delete event.
* @throws IdentityEventException IdentityEventException.
*/
@Override
public void handleEvent(Event event) throws IdentityEventException {
IdentityEventMessageContext eventContext = new IdentityEventMessageContext(event);
if (!isEnabled(eventContext)) {
if (log.isDebugEnabled()) {
log.debug("ConsentDeletionUserEventHandler is disabled. Not handling the " + event.getEventName() + " event.");
}
return;
}
Map<String, Object> eventProperties = event.getEventProperties();
String userName = (String) eventProperties.get(IdentityEventConstants.EventProperty.USER_NAME);
UserStoreManager userStoreManager = (UserStoreManager) eventProperties.get(IdentityEventConstants.EventProperty.USER_STORE_MANAGER);
String domainName = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
String tenantDomain = getUserTenantDomain(eventProperties);
String usernameWithUserStoreDomain = UserCoreUtil.addDomainToName(userName, domainName);
if (log.isDebugEnabled()) {
log.debug(String.format("Deleting consents for user: %s , in tenant domain :%s", usernameWithUserStoreDomain, tenantDomain));
}
ConsentManager consentManager = IdentityConsentDataHolder.getInstance().getPrivilegedConsentManager();
try {
List<ReceiptListResponse> receiptListResponses = consentManager.searchReceipts(consentSearchLimit, 0, usernameWithUserStoreDomain, null, "*", null);
if (log.isDebugEnabled()) {
log.debug(String.format("Found %d receipts issued for user: %s, in tenant domain: %s", receiptListResponses.size(), usernameWithUserStoreDomain, tenantDomain));
}
receiptListResponses.forEach(rethrowConsumer(receiptListResponse -> {
if (log.isDebugEnabled()) {
log.debug(String.format("Deleting receipt with ID : %s, issued for application %s", receiptListResponse.getConsentReceiptId(), receiptListResponse.getSpDisplayName()));
}
consentManager.deleteReceipt(receiptListResponse.getConsentReceiptId());
}));
} catch (ConsentManagementException e) {
throw new IdentityEventException("Error while deleting consents for user " + userName, e);
}
}
use of org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse 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.model.ReceiptListResponse 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.model.ReceiptListResponse 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.model.ReceiptListResponse in project carbon-identity-framework by wso2.
the class SSOConsentServiceImpl method getConsentReceiptOfUser.
private Receipt getConsentReceiptOfUser(ServiceProvider serviceProvider, AuthenticatedUser authenticatedUser, String spName, String spTenantDomain, String subject) throws SSOConsentServiceException {
int receiptListLimit = 2;
List<ReceiptListResponse> receiptListResponses;
try {
receiptListResponses = getReceiptListOfUserForSP(authenticatedUser, spName, spTenantDomain, subject, receiptListLimit);
if (isDebugEnabled()) {
String message = String.format("Retrieved %s receipts for user: %s, service provider: %s in tenant " + "domain %s", receiptListResponses.size(), subject, serviceProvider, spTenantDomain);
logDebug(message);
}
if (hasUserMultipleReceipts(receiptListResponses)) {
throw new SSOConsentServiceException("Consent Management Error", "User cannot have more than one " + "ACTIVE consent per service provider.");
} else if (hasUserSingleReceipt(receiptListResponses)) {
String receiptId = getFirstConsentReceiptFromList(receiptListResponses);
return getReceipt(authenticatedUser, receiptId);
} else {
return null;
}
} catch (ConsentManagementException e) {
throw new SSOConsentServiceException("Consent Management Error", "Error while retrieving user consents.", e);
}
}
Aggregations