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