Search in sources :

Example 6 with UserInformationDTO

use of org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO in project identity-governance by wso2-extensions.

the class BasicUserInformationProvider method getRetainedUserInformation.

@Override
public UserInformationDTO getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
    Claim[] userClaimValues;
    try {
        userClaimValues = getUserStoreManager(tenantId, userStoreDomain).getUserClaimValues(username, null);
    } catch (UserStoreException e) {
        throw new UserExportException("Error while retrieving the user information.", e);
    }
    if (userClaimValues != null) {
        Map<String, String> attributes = Arrays.stream(userClaimValues).collect(Collectors.toMap(Claim::getClaimUri, Claim::getValue));
        List<String> challengeQuestionUris = getChallengeQuestionUris(attributes);
        if (challengeQuestionUris.size() > 0) {
            for (String challengeQuestionUri : challengeQuestionUris) {
                attributes.remove(challengeQuestionUri);
            }
        }
        attributes.remove(CHALLENGE_QUESTION_URIS_CLAIM);
        return new UserInformationDTO(attributes);
    } else {
        return new UserInformationDTO();
    }
}
Also used : UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO) Claim(org.wso2.carbon.user.api.Claim)

Example 7 with UserInformationDTO

use of org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO in project identity-governance by wso2-extensions.

the class ConsentInformationProvider method getRetainedUserInformation.

@Override
public UserInformationDTO getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
    try {
        List<ConsentReceiptDTO> receipts = new ArrayList<>();
        int limit = 100;
        int offset = 0;
        String tenantDomain = realmService.getTenantManager().getDomain(tenantId);
        List<ReceiptListResponse> receiptListResponses;
        do {
            receiptListResponses = consentManager.searchReceipts(limit, offset, UserCoreUtil.addDomainToName(username, userStoreDomain), tenantDomain, null, ConsentConstants.ACTIVE_STATE);
            for (ReceiptListResponse receiptListResponse : receiptListResponses) {
                String receiptId = receiptListResponse.getConsentReceiptId();
                Receipt receipt = consentManager.getReceipt(receiptId);
                receipts.add(Utils.getConsentReceiptDTO(receipt));
            }
            offset += limit;
        } while (receiptListResponses != null && receiptListResponses.size() != 0);
        if (receipts.size() > 0) {
            return new UserInformationDTO(receipts);
        }
    } catch (UserStoreException e) {
        throw new UserExportException("Error while retrieving tenant domain from tenant id: " + tenantId, e);
    } catch (ConsentManagementException e) {
        throw new UserExportException("Error while retrieving consent receipts for user: " + UserCoreUtil.addDomainToName(username, userStoreDomain) + " in tenant id: " + tenantId, e);
    }
    return new UserInformationDTO();
}
Also used : ConsentReceiptDTO(org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO) Receipt(org.wso2.carbon.consent.mgt.core.model.Receipt) ReceiptListResponse(org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse) ConsentManagementException(org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)

Example 8 with UserInformationDTO

use of org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO in project identity-governance by wso2-extensions.

the class MockUserInformationService method getRetainedUserInformation.

@Override
public Map<String, Object> getRetainedUserInformation(String username, String userStoreDomain, int tenantId) throws UserExportException {
    Map<String, String> attributes = new HashMap<>();
    attributes.put("http://wso2.org/claims/username", "username1");
    attributes.put("http://wso2.org/claims/givenname", "lastname1");
    attributes.put("http://wso2.org/claims/lastname", "lastname1");
    UserInformationDTO basicUserInformationDTO = new UserInformationDTO(attributes);
    Map<String, Object> info = new HashMap<>();
    info.put("basic", basicUserInformationDTO.getData());
    return info;
}
Also used : HashMap(java.util.HashMap) UserInformationDTO(org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)

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