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;
}
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()]);
}
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()]);
}
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);
}
}
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;
}
Aggregations