Search in sources :

Example 1 with SecurityInformationDTO

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

Aggregations

Map (java.util.Map)1 UserExportException (org.wso2.carbon.identity.user.export.core.UserExportException)1 SecurityInformationDTO (org.wso2.carbon.identity.user.export.core.dto.SecurityInformationDTO)1 UserInformationDTO (org.wso2.carbon.identity.user.export.core.dto.UserInformationDTO)1 Claim (org.wso2.carbon.user.api.Claim)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1 UserStoreManager (org.wso2.carbon.user.api.UserStoreManager)1