use of org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO in project identity-governance by wso2-extensions.
the class BasicUserInformationProviderTest method testGetUserAttributes.
@Test
public void testGetUserAttributes() throws Exception {
RealmService realmService = mock(RealmService.class);
RegistryService registryService = mock(RegistryService.class);
TenantManager tenantManager = mock(TenantManager.class);
when(realmService.getTenantManager()).thenReturn(tenantManager);
when(tenantManager.getDomain(anyInt())).thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
UserRealm userRealm = mock(UserRealm.class);
UserStoreManager userStoreManager = mock(UserStoreManager.class);
UserStoreManager secUserStoreManager = mock(UserStoreManager.class);
when(userStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(secUserStoreManager);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
mockedAnonymousSessionUtil.when(() -> AnonymousSessionUtil.getRealmByTenantDomain(any(RegistryService.class), any(RealmService.class), anyString())).thenReturn(userRealm);
Claim[] claims = getClaims();
when(secUserStoreManager.getUserClaimValues(USERNAME_CLAIM_VALUE, null)).thenReturn(claims);
BasicUserInformationProvider basicUserInformationProvider = new BasicUserInformationProvider();
basicUserInformationProvider.setRealmService(realmService);
basicUserInformationProvider.setRegistryService(registryService);
UserInformationDTO userAttributesObj = basicUserInformationProvider.getRetainedUserInformation(USERNAME_CLAIM_VALUE, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, -1234);
if (userAttributesObj != null && userAttributesObj.getData() instanceof Map) {
Map userAttributes = (Map) userAttributesObj.getData();
Assert.assertEquals(userAttributes.get(USERNAME_CLAIM_URI), USERNAME_CLAIM_VALUE);
Assert.assertEquals(userAttributes.get(GIVEN_NAME_CLAIM_URI), GIVEN_NAME_CLAIM_VALUE);
Assert.assertEquals(userAttributes.get(LAST_NAME_CLAIM_URI), LAST_NAME_CLAIM_VALUE);
} else {
Assert.fail();
}
}
use of org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO 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.identity.user.export.core.dto.UserInformationDTO in project identity-governance by wso2-extensions.
the class SecurityInformationProvider method getRetainedUserInformation.
@Override
public UserInformationDTO getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
String challengeQuestionClaimValue = null;
UserStoreManager userStoreManager;
try {
userStoreManager = getUserStoreManager(tenantId, userStoreDomain);
Claim[] userClaims = userStoreManager.getUserClaimValues(username, null);
for (Claim claim : userClaims) {
if (CHALLENGE_QUESTION_URIS_CLAIM.equals(claim.getClaimUri())) {
challengeQuestionClaimValue = userStoreManager.getUserClaimValue(username, CHALLENGE_QUESTION_URIS_CLAIM, null);
}
}
} catch (UserStoreException e) {
throw new UserExportException("Error while retrieving the user information.", e);
}
if (challengeQuestionClaimValue != null) {
List<String> challengeQuestionUris = getChallengeQuestionUris(challengeQuestionClaimValue);
SecurityInformationDTO securityInformationDTO = new SecurityInformationDTO();
if (challengeQuestionUris.size() > 0) {
Map<String, String> challengeQuestions;
try {
challengeQuestions = userStoreManager.getUserClaimValues(username, challengeQuestionUris.toArray(new String[challengeQuestionUris.size()]), null);
} catch (UserStoreException e) {
throw new UserExportException("Error while retrieving the user information.", e);
}
String challengeQuestionSeparator = challengeQuestionSeparator();
for (Map.Entry<String, String> challengeQuestion : challengeQuestions.entrySet()) {
String[] challengeQuestionsParts = challengeQuestion.getValue().split(challengeQuestionSeparator);
securityInformationDTO.addChallengeQuestion(challengeQuestionsParts[0]);
}
}
return new UserInformationDTO(securityInformationDTO);
} else {
if (log.isDebugEnabled()) {
log.debug("Challenge question claim is not available in the tenant: " + tenantId);
}
}
return new UserInformationDTO();
}
use of org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO in project identity-governance by wso2-extensions.
the class UserInformationServiceImpl method getRetainedUserInformation.
@Override
public Map<String, Object> getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
Map<String, Object> userInformation = new HashMap<>();
for (UserInformationProvider userInformationProvider : userInformationProviders) {
if (userInformationProvider.isEnabled()) {
UserInformationDTO retainedUserInformation = userInformationProvider.getRetainedUserInformation(username, userStoreDomain, tenantId);
if (retainedUserInformation != null && retainedUserInformation.isInformationAvailable()) {
String type = userInformationProvider.getType();
userInformation.put(type, retainedUserInformation.getData());
}
}
}
return userInformation;
}
use of org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO in project identity-governance by wso2-extensions.
the class BasicUserInformationProviderTest method testGetUserAttributesEmpty.
@Test
public void testGetUserAttributesEmpty() throws Exception {
RealmService realmService = mock(RealmService.class);
RegistryService registryService = mock(RegistryService.class);
TenantManager tenantManager = mock(TenantManager.class);
when(realmService.getTenantManager()).thenReturn(tenantManager);
when(tenantManager.getDomain(anyInt())).thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
UserRealm userRealm = mock(UserRealm.class);
UserStoreManager userStoreManager = mock(UserStoreManager.class);
UserStoreManager secUserStoreManager = mock(UserStoreManager.class);
when(userStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(secUserStoreManager);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
mockedAnonymousSessionUtil.when(() -> AnonymousSessionUtil.getRealmByTenantDomain(any(RegistryService.class), any(RealmService.class), anyString())).thenReturn(userRealm);
when(secUserStoreManager.getUserClaimValues(USERNAME_CLAIM_VALUE, null)).thenReturn(null);
BasicUserInformationProvider basicUserInformationProvider = new BasicUserInformationProvider();
basicUserInformationProvider.setRealmService(realmService);
basicUserInformationProvider.setRegistryService(registryService);
UserInformationDTO userAttributesObj = basicUserInformationProvider.getRetainedUserInformation(USERNAME_CLAIM_VALUE, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME, -1234);
if (userAttributesObj.isInformationAvailable()) {
Assert.fail();
}
}
Aggregations