Search in sources :

Example 1 with UserExportException

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

the class MeApiServiceImpl method getMe.

@Override
public Response getMe() {
    String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    String userStoreDomain = UserCoreUtil.extractDomainFromName(username);
    username = UserCoreUtil.removeDomainFromName(username);
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    Map userAttributes;
    try {
        userAttributes = Utils.getUserInformationService().getRetainedUserInformation(username, userStoreDomain, tenantId);
    } catch (UserExportException e) {
        ErrorDTO errorDTO = new ErrorDTO();
        errorDTO.setRef(Utils.getCorrelation());
        errorDTO.setMessage(e.getMessage());
        return Response.serverError().entity(errorDTO).build();
    }
    return Response.ok().status(Response.Status.OK).entity(userAttributes).build();
}
Also used : ErrorDTO(org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with UserExportException

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

the class BasicUserInformationProvider method getUserStoreManager.

protected UserStoreManager getUserStoreManager(int tenantId, String userStoreDomain) throws UserExportException {
    UserStoreManager userStoreManager;
    try {
        String tenantDomain = realmService.getTenantManager().getDomain(tenantId);
        userStoreManager = getUserRealm(tenantDomain).getUserStoreManager().getSecondaryUserStoreManager(userStoreDomain);
    } catch (UserStoreException e) {
        throw new UserExportException("Error while retrieving the user store manager.", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Retrieved user store manager for tenant id: " + tenantId);
    }
    return userStoreManager;
}
Also used : UserStoreException(org.wso2.carbon.user.api.UserStoreException) UserExportException(org.wso2.carbon.identity.user.export.core.UserExportException) UserStoreManager(org.wso2.carbon.user.api.UserStoreManager)

Example 3 with UserExportException

use of org.wso2.carbon.identity.user.export.core.UserExportException 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 UserExportException

use of org.wso2.carbon.identity.user.export.core.UserExportException 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 UserExportException

use of org.wso2.carbon.identity.user.export.core.UserExportException 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)

Aggregations

UserExportException (org.wso2.carbon.identity.user.export.core.UserExportException)6 UserInformationDTO (org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ErrorDTO (org.wso2.carbon.identity.user.endpoint.dto.ErrorDTO)2 Claim (org.wso2.carbon.user.api.Claim)2 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)2 ArrayList (java.util.ArrayList)1 ConsentManagementException (org.wso2.carbon.consent.mgt.core.exception.ConsentManagementException)1 Receipt (org.wso2.carbon.consent.mgt.core.model.Receipt)1 ReceiptListResponse (org.wso2.carbon.consent.mgt.core.model.ReceiptListResponse)1 ConsentReceiptDTO (org.wso2.carbon.identity.user.export.core.dto.ConsentReceiptDTO)1 SecurityInformationDTO (org.wso2.carbon.identity.user.export.core.dto.SecurityInformationDTO)1 UserInformationProvider (org.wso2.carbon.identity.user.export.core.service.UserInformationProvider)1