Search in sources :

Example 26 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-governance by wso2-extensions.

the class ChallengeQuestionManagementAdminService method getChallengeQuestionsForLocale.

/**
 * Get all tenant questions of a locale in a tenant domain
 *
 * @param tenantDomain
 * @param locale
 * @return
 * @throws IdentityRecoveryServerException
 */
public ChallengeQuestion[] getChallengeQuestionsForLocale(String tenantDomain, String locale) throws IdentityRecoveryException {
    // check for cross tenant access
    checkCrossTenantAccess(tenantDomain);
    List<ChallengeQuestion> challengeQuestionList;
    try {
        challengeQuestionList = questionManager.getAllChallengeQuestions(tenantDomain, locale);
        return challengeQuestionList.toArray(new ChallengeQuestion[challengeQuestionList.size()]);
    } catch (IdentityRecoveryException e) {
        String errorMgs = String.format("Error loading challenge questions for tenant %s in %s locale.", tenantDomain, locale);
        log.error(errorMgs, e);
        throw new IdentityRecoveryException(errorMgs, e);
    }
}
Also used : IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Example 27 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-governance by wso2-extensions.

the class Utils method getChallengeSetUris.

public static List<String> getChallengeSetUris(ChallengeQuestion[] challengeQuestions) {
    HashSet<String> questionSetNames = new HashSet<String>();
    if (ArrayUtils.isNotEmpty(challengeQuestions)) {
        for (ChallengeQuestion question : challengeQuestions) {
            if (question.getQuestionSetId() != null) {
                questionSetNames.add(question.getQuestionSetId());
            }
        }
    }
    List<String> challengeSetUriList = new ArrayList<String>(questionSetNames);
    Collections.sort(challengeSetUriList);
    return challengeSetUriList;
}
Also used : ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChallengeQuestion(org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion)

Example 28 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-governance by wso2-extensions.

the class Utils method getUniqueQuestionIds.

public static List<String> getUniqueQuestionIds(List<ChallengeQuestion> challengeQuestions, String setId) {
    HashSet<String> questionIds = new HashSet<String>();
    for (ChallengeQuestion question : challengeQuestions) {
        if (StringUtils.equalsIgnoreCase(setId, question.getQuestionSetId())) {
            questionIds.add(question.getQuestionId());
        }
    }
    List<String> questioIdList = new ArrayList<>(questionIds);
    Collections.sort(questioIdList);
    return questioIdList;
}
Also used : ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ChallengeQuestion(org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion)

Example 29 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-governance by wso2-extensions.

the class ChallengeQuestionManager method addChallengeQuestions.

/**
 * Add new challenge questions to the registry of a tenant
 *
 * @param questions
 * @param tenantDomain
 * @throws IdentityRecoveryException
 */
public void addChallengeQuestions(ChallengeQuestion[] questions, String tenantDomain) throws IdentityRecoveryException {
    try {
        tenantDomain = validateTenantDomain(tenantDomain);
        // check whether registry path for question collection exists
        Resource challengeQuestionCollection = resourceMgtService.getIdentityResource(QUESTIONS_BASE_PATH, tenantDomain);
        // create the question collection if it does not exist
        if (challengeQuestionCollection == null) {
            challengeQuestionCollection = new CollectionImpl();
            resourceMgtService.putIdentityResource(challengeQuestionCollection, QUESTIONS_BASE_PATH, tenantDomain);
        }
        for (ChallengeQuestion challengeQuestion : questions) {
            validateChallengeQuestionAttributes(challengeQuestion);
            String questionPath = getQuestionPath(challengeQuestion);
            String locale = validateLocale(challengeQuestion.getLocale());
            // create a registry resource
            Resource resource = createRegistryResource(challengeQuestion);
            resourceMgtService.putIdentityResource(resource, questionPath, tenantDomain, locale);
        }
    } catch (RegistryException | UnsupportedEncodingException e) {
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_REGISTRY_EXCEPTION_SET_CHALLENGE_QUESTIONS, null, e);
    }
}
Also used : CollectionImpl(org.wso2.carbon.registry.core.CollectionImpl) Resource(org.wso2.carbon.registry.core.Resource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Example 30 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-governance by wso2-extensions.

the class ChallengeQuestionManager method getUserChallengeQuestion.

/**
 * Retrieve the challenge question answered from a particular challenge question set.
 *
 * @param user
 * @param challengesUri claim uri of the challenge set
 * @return
 * @throws IdentityRecoveryException
 */
public ChallengeQuestion getUserChallengeQuestion(User user, String challengesUri) throws IdentityRecoveryException {
    validateUser(user);
    ChallengeQuestion userChallengeQuestion = null;
    if (log.isDebugEnabled()) {
        log.debug("Retrieving Challenge question from the user profile.");
    }
    String challengeValue = null;
    try {
        challengeValue = Utils.getClaimFromUserStoreManager(user, challengesUri);
    } catch (UserStoreException e) {
        throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_GETTING_CHALLENGE_QUESTION, user.getUserName(), e);
    }
    if (challengeValue != null) {
        String challengeQuestionSeparator = getChallengeSeparator();
        String[] challengeValues = challengeValue.split(challengeQuestionSeparator);
        if (challengeValues != null && challengeValues.length == 2) {
            userChallengeQuestion = new ChallengeQuestion(challengesUri, challengeValues[0].trim());
        }
    }
    return userChallengeQuestion;
}
Also used : UserStoreException(org.wso2.carbon.user.api.UserStoreException) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Aggregations

ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)26 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)8 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)8 UserChallengeAnswer (org.wso2.carbon.identity.recovery.model.UserChallengeAnswer)7 ChallengeQuestion (org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)5 IdentityException (org.wso2.carbon.identity.base.IdentityException)3 ChallengeQuestionManager (org.wso2.carbon.identity.recovery.ChallengeQuestionManager)3 ChallengeQuestionResponse (org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse)3 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)3 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)3 ChallengeQuestionDTO (org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO)3 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 Map (java.util.Map)2