Search in sources :

Example 6 with ChallengeQuestionDTO

use of org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO in project carbon-identity-framework by wso2.

the class ChallengeQuestionProcessor method getAllChallengeQuestions.

/**
 * @return
 * @throws IdentityException
 */
public List<ChallengeQuestionDTO> getAllChallengeQuestions() throws IdentityException {
    List<ChallengeQuestionDTO> questionDTOs = new ArrayList<ChallengeQuestionDTO>();
    try {
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        Registry registry = IdentityMgtServiceComponent.getRegistryService().getConfigSystemRegistry(tenantId);
        if (registry.resourceExists(IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS)) {
            Collection collection = (Collection) registry.get(IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS);
            String[] children = collection.getChildren();
            for (String child : children) {
                Resource resource = registry.get(child);
                String question = resource.getProperty("question");
                String isPromoteQuestion = resource.getProperty("isPromoteQuestion");
                String questionSetId = resource.getProperty("questionSetId");
                if (question != null) {
                    ChallengeQuestionDTO questionDTO = new ChallengeQuestionDTO();
                    questionDTO.setQuestion(question);
                    if (isPromoteQuestion != null) {
                        questionDTO.setPromoteQuestion(Boolean.parseBoolean(isPromoteQuestion));
                    }
                    if (questionSetId != null) {
                        questionDTO.setQuestionSetId(questionSetId);
                    }
                    questionDTO.setPromoteQuestion(false);
                    questionDTOs.add(questionDTO);
                }
            }
        }
    } catch (RegistryException e) {
        throw IdentityException.error(e.getMessage(), e);
    }
    return questionDTOs;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.wso2.carbon.registry.core.Resource) Collection(org.wso2.carbon.registry.core.Collection) Registry(org.wso2.carbon.registry.core.Registry) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 7 with ChallengeQuestionDTO

use of org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO in project carbon-identity-framework by wso2.

the class UserInformationRecoveryService method getAllChallengeQuestions.

/**
 * Get all challenge questions
 *
 * @return array of questions
 * @throws IdentityMgtServiceException if fails
 */
public ChallengeQuestionDTO[] getAllChallengeQuestions() throws IdentityMgtServiceException {
    ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
    List<ChallengeQuestionDTO> questionDTOs = null;
    try {
        questionDTOs = processor.getAllChallengeQuestions();
    } catch (IdentityException e) {
        log.error("Error while loading user challenges", e);
        throw new IdentityMgtServiceException("Error while loading user challenges");
    }
    return questionDTOs.toArray(new ChallengeQuestionDTO[questionDTOs.size()]);
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ChallengeQuestionProcessor(org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor) IdentityException(org.wso2.carbon.identity.base.IdentityException) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)

Example 8 with ChallengeQuestionDTO

use of org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementAdminService method getAllChallengeQuestions.

/**
 * get all challenge questions
 *
 * @return array of questions
 * @throws IdentityMgtServiceException if fails
 */
public ChallengeQuestionDTO[] getAllChallengeQuestions() throws IdentityMgtServiceException {
    ChallengeQuestionProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor();
    List<ChallengeQuestionDTO> questionDTOs = null;
    try {
        questionDTOs = processor.getAllChallengeQuestions();
    } catch (IdentityException e) {
        String errorMessage = "Error while loading user challenge questions";
        log.error(errorMessage, e);
        throw new IdentityMgtServiceException(errorMessage);
    }
    return questionDTOs.toArray(new ChallengeQuestionDTO[questionDTOs.size()]);
}
Also used : IdentityMgtServiceException(org.wso2.carbon.identity.mgt.IdentityMgtServiceException) ChallengeQuestionProcessor(org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor) IdentityException(org.wso2.carbon.identity.base.IdentityException) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)

Example 9 with ChallengeQuestionDTO

use of org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO in project carbon-identity-framework by wso2.

the class UserIdentityManagementUtil method loadDefaultChallenges.

/**
 * This methods adds default challenge question set to current domain
 */
public static void loadDefaultChallenges() {
    List<ChallengeQuestionDTO> questionSetDTOs = new ArrayList<ChallengeQuestionDTO>();
    for (String challenge : IdentityMgtConstants.getSecretQuestionsSet01()) {
        ChallengeQuestionDTO dto = new ChallengeQuestionDTO();
        dto.setQuestion(challenge);
        dto.setPromoteQuestion(true);
        dto.setQuestionSetId(IdentityMgtConstants.DEFAULT_CHALLENGE_QUESTION_URI01);
        questionSetDTOs.add(dto);
    }
    for (String challenge : IdentityMgtConstants.getSecretQuestionsSet02()) {
        ChallengeQuestionDTO dto = new ChallengeQuestionDTO();
        dto.setQuestion(challenge);
        dto.setPromoteQuestion(true);
        dto.setQuestionSetId(IdentityMgtConstants.DEFAULT_CHALLENGE_QUESTION_URI02);
        questionSetDTOs.add(dto);
    }
    try {
        IdentityMgtServiceComponent.getRecoveryProcessor().getQuestionProcessor().setChallengeQuestions(questionSetDTOs.toArray(new ChallengeQuestionDTO[questionSetDTOs.size()]));
    } catch (IdentityException e) {
        log.error("Error while promoting default challenge questions", e);
    }
}
Also used : ArrayList(java.util.ArrayList) IdentityException(org.wso2.carbon.identity.base.IdentityException) ChallengeQuestionDTO(org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)

Example 10 with ChallengeQuestionDTO

use of org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO in project identity-api-server by wso2.

the class ServerChallengeService method patchChallengeSet.

/**
 * Update a specific challenge questions of an existing set
 *
 * @param challengeSetId
 * @param challengeQuestionPatchDTO
 * @return
 */
public boolean patchChallengeSet(String challengeSetId, ChallengeQuestionPatchDTO challengeQuestionPatchDTO) {
    if (!isChallengeSetExists(challengeSetId, ContextLoader.getTenantDomainFromContext())) {
        throw handleError(Response.Status.NOT_FOUND, ChallengeConstant.ErrorMessage.ERROR_CHALLENGE_SET_NOT_EXISTS);
    }
    if (Constants.OPERATION_ADD.equalsIgnoreCase(challengeQuestionPatchDTO.getOperation())) {
        List<ChallengeQuestionDTO> challenges = new ArrayList<>();
        ChallengeQuestionDTO challengeQuestion = challengeQuestionPatchDTO.getChallengeQuestion();
        challenges.add(challengeQuestion);
        List<ChallengeQuestion> questions = buildChallengeQuestions(challenges, challengeSetId);
        ChallengeQuestion[] toPatch = questions.toArray(new ChallengeQuestion[0]);
        try {
            getChallengeQuestionManager().addChallengeQuestions(toPatch, ContextLoader.getTenantDomainFromContext());
        } catch (IdentityRecoveryException e) {
            throw handleIdentityRecoveryException(e, ChallengeConstant.ErrorMessage.ERROR_CODE_ERROR_ADDING_CHALLENGE_QUESTION_TO_A_SET);
        }
    } else {
        throw handleError(Response.Status.NOT_IMPLEMENTED, ChallengeConstant.ErrorMessage.ERROR_CODE_ERROR_OPERATION_NOT_SUPPORTED);
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) ChallengeQuestionDTO(org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Aggregations

ChallengeQuestionDTO (org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)6 IdentityException (org.wso2.carbon.identity.base.IdentityException)5 ArrayList (java.util.ArrayList)4 ChallengeQuestionProcessor (org.wso2.carbon.identity.mgt.ChallengeQuestionProcessor)4 IdentityMgtServiceException (org.wso2.carbon.identity.mgt.IdentityMgtServiceException)4 ChallengeQuestionDTO (org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO)3 UserChallengesDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesDTO)2 Collection (org.wso2.carbon.registry.core.Collection)2 Registry (org.wso2.carbon.registry.core.Registry)2 Resource (org.wso2.carbon.registry.core.Resource)2 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UserChallengesSetDTO (org.wso2.carbon.identity.mgt.dto.UserChallengesSetDTO)1 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)1 ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)1 ChallengeQuestionToExternal (org.wso2.carbon.identity.rest.api.server.challenge.v1.core.functions.ChallengeQuestionToExternal)1 ChallengeSetDTO (org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeSetDTO)1 AuthorizationManager (org.wso2.carbon.user.api.AuthorizationManager)1