Search in sources :

Example 1 with QuestionDTO

use of org.wso2.carbon.identity.recovery.endpoint.dto.QuestionDTO 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 2 with QuestionDTO

use of org.wso2.carbon.identity.recovery.endpoint.dto.QuestionDTO in project identity-governance by wso2-extensions.

the class RecoveryUtil method getInitiateQuestionResponseDTO.

public static InitiateAllQuestionResponseDTO getInitiateQuestionResponseDTO(ChallengeQuestionsResponse challengeQuestionsResponse) {
    InitiateAllQuestionResponseDTO initiateAllQuestionResponseDTO = new InitiateAllQuestionResponseDTO();
    List<QuestionDTO> questionDTOs = new ArrayList<>();
    for (ChallengeQuestion challengeQuestion : challengeQuestionsResponse.getQuestion()) {
        QuestionDTO questionDTO = new QuestionDTO();
        questionDTO.setQuestion(challengeQuestion.getQuestion());
        questionDTO.setQuestionSetId(challengeQuestion.getQuestionSetId());
        questionDTOs.add(questionDTO);
    }
    initiateAllQuestionResponseDTO.setQuestions(questionDTOs);
    initiateAllQuestionResponseDTO.setKey(challengeQuestionsResponse.getCode());
    LinkDTO linkDTO = new LinkDTO();
    linkDTO.setRel("validate-answer");
    linkDTO.setUri("/api/identity/recovery/v0.9");
    initiateAllQuestionResponseDTO.setLink(linkDTO);
    return initiateAllQuestionResponseDTO;
}
Also used : InitiateAllQuestionResponseDTO(org.wso2.carbon.identity.recovery.endpoint.dto.InitiateAllQuestionResponseDTO) LinkDTO(org.wso2.carbon.identity.recovery.endpoint.dto.LinkDTO) ArrayList(java.util.ArrayList) QuestionDTO(org.wso2.carbon.identity.recovery.endpoint.dto.QuestionDTO) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Example 3 with QuestionDTO

use of org.wso2.carbon.identity.recovery.endpoint.dto.QuestionDTO in project identity-governance by wso2-extensions.

the class RecoveryUtil method getInitiateQuestionResponseDTO.

public static InitiateQuestionResponseDTO getInitiateQuestionResponseDTO(ChallengeQuestionResponse challengeQuestionResponse) {
    InitiateQuestionResponseDTO initiateQuestionResponseDTO = new InitiateQuestionResponseDTO();
    QuestionDTO questionDTO = new QuestionDTO();
    if (challengeQuestionResponse.getQuestion() != null) {
        questionDTO.setQuestion(challengeQuestionResponse.getQuestion().getQuestion());
        questionDTO.setQuestionSetId(challengeQuestionResponse.getQuestion().getQuestionSetId());
        initiateQuestionResponseDTO.setQuestion(questionDTO);
    }
    initiateQuestionResponseDTO.setKey(challengeQuestionResponse.getCode());
    LinkDTO linkDTO = new LinkDTO();
    if (IdentityRecoveryConstants.RECOVERY_STATUS_COMPLETE.equals(challengeQuestionResponse.getStatus())) {
        linkDTO.setRel("set-password");
        linkDTO.setUri("/api/identity/recovery/v0.9");
    } else {
        linkDTO.setRel("validate-answer");
        linkDTO.setUri("/api/identity/recovery/v0.9");
    }
    initiateQuestionResponseDTO.setLink(linkDTO);
    return initiateQuestionResponseDTO;
}
Also used : LinkDTO(org.wso2.carbon.identity.recovery.endpoint.dto.LinkDTO) QuestionDTO(org.wso2.carbon.identity.recovery.endpoint.dto.QuestionDTO) InitiateQuestionResponseDTO(org.wso2.carbon.identity.recovery.endpoint.dto.InitiateQuestionResponseDTO)

Aggregations

ArrayList (java.util.ArrayList)2 LinkDTO (org.wso2.carbon.identity.recovery.endpoint.dto.LinkDTO)2 QuestionDTO (org.wso2.carbon.identity.recovery.endpoint.dto.QuestionDTO)2 ChallengeQuestionDTO (org.wso2.carbon.identity.mgt.dto.ChallengeQuestionDTO)1 InitiateAllQuestionResponseDTO (org.wso2.carbon.identity.recovery.endpoint.dto.InitiateAllQuestionResponseDTO)1 InitiateQuestionResponseDTO (org.wso2.carbon.identity.recovery.endpoint.dto.InitiateQuestionResponseDTO)1 ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)1 Collection (org.wso2.carbon.registry.core.Collection)1 Registry (org.wso2.carbon.registry.core.Registry)1 Resource (org.wso2.carbon.registry.core.Resource)1 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)1