Search in sources :

Example 1 with UserInformationDTO

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();
    }
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Map(java.util.Map) Claim(org.wso2.carbon.user.core.claim.Claim) Test(org.testng.annotations.Test)

Example 2 with UserInformationDTO

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

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();
}
Also used : UserStoreManager(org.wso2.carbon.user.api.UserStoreManager) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) SecurityInformationDTO(org.wso2.carbon.identity.user.export.core.dto.SecurityInformationDTO) Map(java.util.Map) Claim(org.wso2.carbon.user.api.Claim)

Example 4 with 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;
}
Also used : HashMap(java.util.HashMap) UserInformationProvider(org.wso2.carbon.identity.user.export.core.service.UserInformationProvider) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)

Example 5 with UserInformationDTO

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();
    }
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) TenantManager(org.wso2.carbon.user.core.tenant.TenantManager) Test(org.testng.annotations.Test)

Aggregations

UserInformationDTO (org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)8 Test (org.testng.annotations.Test)3 UserExportException (org.wso2.carbon.identity.user.export.core.UserExportException)3 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 RealmService (org.wso2.carbon.user.core.service.RealmService)3 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Receipt (org.wso2.carbon.consent.mgt.core.model.Receipt)2 ReceiptListResponse (org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse)2 ConsentReceiptDTO (org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO)2 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)2 Claim (org.wso2.carbon.user.api.Claim)2 UserRealm (org.wso2.carbon.user.core.UserRealm)2 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)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 SecurityInformationDTO (org.wso2.carbon.identity.user.export.core.dto.SecurityInformationDTO)1