use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.
the class PageSecurityQuestions method savePerformed.
private void savePerformed(final AjaxRequestTarget target) {
int correctAnswers = 0;
for (MyPasswordQuestionsPanel type : pqPanels) {
List<SecurityQuestionAnswerDTO> userQuestionList = questions.getUserQuestionAnswers();
if (userQuestionList != null) {
for (SecurityQuestionAnswerDTO securityQuestionAnswerDTO : userQuestionList) {
// TODO do this in a proper way, what is this.
String results = StringEscapeUtils.unescapeHtml4(type.get(MyPasswordQuestionsPanel.ID_QUESTION).getDefaultModelObjectAsString());
if (getQuestionIdentifierFromQuestion(results).trim().equalsIgnoreCase(securityQuestionAnswerDTO.getPwdQuestionIdentifier().trim())) {
if (((TextField<String>) type.get(MyPasswordQuestionsPanel.ID_ANSWER)).getModelObject().equalsIgnoreCase(securityQuestionAnswerDTO.getPwdAnswer())) {
correctAnswers++;
}
}
}
}
}
if (questionNumber == correctAnswers) {
getSession().removeAttribute(SESSION_ATTRIBUTE_POID);
runPrivileged((Producer<Object>) () -> {
resetPassword(user.asObjectable(), target);
return null;
});
} else {
warn(getString("pageSecurityQuestions.message.WrongAnswer"));
target.add(getFeedbackPanel());
}
}
use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.
the class PageSecurityQuestions method createUsersSecurityQuestionsList.
private List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
SecurityQuestionsCredentialsType credentialsPolicyType = user.asObjectable().getCredentials().getSecurityQuestions();
if (credentialsPolicyType == null) {
return null;
}
List<SecurityQuestionAnswerType> secQuestAnsList = credentialsPolicyType.getQuestionAnswer();
if (secQuestAnsList != null) {
List<SecurityQuestionAnswerDTO> secQuestAnsListDTO = new ArrayList<>();
for (SecurityQuestionAnswerType securityQuestionAnswerType : secQuestAnsList) {
Protector protector = getPrismContext().getDefaultProtector();
String decoded = "";
if (securityQuestionAnswerType.getQuestionAnswer().getEncryptedDataType() != null) {
try {
decoded = protector.decryptString(securityQuestionAnswerType.getQuestionAnswer());
} catch (EncryptionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
secQuestAnsListDTO.add(new SecurityQuestionAnswerDTO(securityQuestionAnswerType.getQuestionIdentifier(), decoded));
}
return secQuestAnsListDTO;
} else {
return null;
}
}
use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.
the class SecurityQuestionsPanel method executePasswordQuestionsAndAnswers.
/**
* method for get existing questions and answer from user credentials
*
* @author oguzhan
*/
public List<SecurityQuestionAnswerDTO> executePasswordQuestionsAndAnswers(List<SecurityQuestionAnswerDTO> userQuestionList, List<SecurityQuestionDefinitionType> policyQuestionList, int panelNumber) {
int userQuest = 0;
LOGGER.debug("executePasswordQuestionsAndAnswers");
List<SecurityQuestionAnswerDTO> secQuestionAnswer = new ArrayList<>();
for (SecurityQuestionDefinitionType securityQuestionDefinitionType : policyQuestionList) {
// user's question List loop to match the questions
for (int i = userQuest; i < userQuestionList.size(); i++) {
SecurityQuestionAnswerDTO dto = userQuestionList.get(i);
if (dto.getPwdQuestionIdentifier().trim().compareTo(securityQuestionDefinitionType.getIdentifier().trim()) == 0) {
SecurityQuestionAnswerDTO a = new SecurityQuestionAnswerDTO(dto.getPwdQuestionIdentifier(), dto.getPwdAnswer(), dto.getPwdQuestion());
a = checkIfQuestionIsValidSingle(a, securityQuestionDefinitionType);
secQuestionAnswer.add(a);
panelNumber++;
userQuest++;
break;
} else if (dto.getPwdQuestionIdentifier().trim().compareTo(securityQuestionDefinitionType.getIdentifier().trim()) != 0) {
SecurityQuestionDefinitionType def = policyQuestionList.get(panelNumber);
SecurityQuestionAnswerDTO a = new SecurityQuestionAnswerDTO(def.getIdentifier(), "", def.getQuestionText());
a.setPwdQuestion(securityQuestionDefinitionType.getQuestionText());
secQuestionAnswer.add(a);
dto.setPwdQuestionIdentifier(securityQuestionDefinitionType.getIdentifier().trim());
panelNumber++;
userQuest++;
break;
}
}
}
return secQuestionAnswer;
}
use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.
the class SecurityQuestionsPanel method executeAddingQuestions.
/**
* method for adding questions to user credentials
*
* @author oguzhan
*/
public List<SecurityQuestionAnswerDTO> executeAddingQuestions(int questionNumber, int panelNumber, List<SecurityQuestionDefinitionType> policyQuestionList) {
LOGGER.debug("executeAddingQuestions");
List<SecurityQuestionAnswerDTO> questionsAnswer = new ArrayList<>();
for (int i = 0; i < questionNumber; i++) {
SecurityQuestionDefinitionType def = policyQuestionList.get(panelNumber);
SecurityQuestionAnswerDTO a = new SecurityQuestionAnswerDTO(def.getIdentifier(), "", def.getQuestionText());
questionsAnswer.add(a);
panelNumber++;
}
return questionsAnswer;
}
use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.
the class SecurityQuestionsPanel method onSavePerformed.
public void onSavePerformed(AjaxRequestTarget target) {
Task task = getPageBase().createSimpleTask(OPERATION_SAVE_QUESTIONS);
OperationResult result = new OperationResult(OPERATION_SAVE_QUESTIONS);
List<SecurityQuestionAnswerType> answerTypeList = new ArrayList<>();
try {
int listnum = 0;
for (SecurityQuestionAnswerDTO answerDto : getModelObject().getActualQuestionAnswers()) {
SecurityQuestionAnswerType answerType = new SecurityQuestionAnswerType();
ProtectedStringType answer = new ProtectedStringType();
if (StringUtils.isEmpty(answerDto.getPwdAnswer())) {
// target.add(getPageBase().getFeedbackPanel());
continue;
}
answer.setClearValue(answerDto.getPwdAnswer());
if (!answer.isEncrypted()) {
WebComponentUtil.encryptProtectedString(answer, true, getPageBase().getMidpointApplication());
}
answerType.setQuestionAnswer(answer);
answerType.setQuestionIdentifier(answerDto.getPwdQuestionIdentifier());
answerTypeList.add(answerType);
listnum++;
}
// fill in answerType data here
ItemPath path = ItemPath.create(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
String useroid = getModelObject().getFocusOid();
ObjectDelta<UserType> objectDelta = getPrismContext().deltaFactory().object().createModificationReplaceContainer(UserType.class, useroid, path, answerTypeList.toArray(new SecurityQuestionAnswerType[answerTypeList.size()]));
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
getPageBase().getModelService().executeChanges(deltas, null, task, result);
success(getString("message.success"));
target.add(getPageBase().getFeedbackPanel());
} catch (Exception ex) {
error(getString("message.error"));
target.add(getPageBase().getFeedbackPanel());
ex.printStackTrace();
}
}
Aggregations