use of com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel in project midpoint by Evolveum.
the class PageMyPasswordQuestions method updateQuestions.
private void updateQuestions(String useroid, AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_SAVE_QUESTIONS);
OperationResult result = new OperationResult(OPERATION_SAVE_QUESTIONS);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
SecurityQuestionAnswerType[] answerTypeList = new SecurityQuestionAnswerType[questionNumber];
try {
int listnum = 0;
for (Iterator iterator = pqPanels.iterator(); iterator.hasNext(); ) {
MyPasswordQuestionsPanel type = (MyPasswordQuestionsPanel) iterator.next();
SecurityQuestionAnswerType answerType = new SecurityQuestionAnswerType();
ProtectedStringType answer = new ProtectedStringType();
answer.setClearValue(((TextField<String>) type.get(MyPasswordQuestionsPanel.F_ANSWER)).getModelObject());
answerType.setQuestionAnswer(answer);
//used apache's unescapeHtml method for special chars like \'
String results = StringEscapeUtils.unescapeHtml((type.get(MyPasswordQuestionsPanel.F_QUESTION)).getDefaultModelObjectAsString());
answerType.setQuestionIdentifier(getQuestionIdentifierFromQuestion(results));
answerTypeList[listnum] = answerType;
listnum++;
}
//if(answerTypeList.length !=)
// fill in answerType data here
ItemPath path = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceContainer(UserType.class, useroid, path, getPrismContext(), answerTypeList);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
getModelService().executeChanges(deltas, null, task, result);
/*
System.out.println("getModel");
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
PasswordQuestionsDto dto = new PasswordQuestionsDto();
PrismObjectDefinition objDef =registry.findObjectDefinitionByCompileTimeClass(UserType.class);
Class<? extends ObjectType> type = UserType.class;
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
SecurityQuestionAnswerType secQuesAnsType= new SecurityQuestionAnswerType();
ProtectedStringType protStrType= new ProtectedStringType();
protStrType.setClearValue("deneme");
secQuesAnsType.setQuestionAnswer(protStrType);
dto.setSecurityAnswers(new ArrayList<SecurityQuestionAnswerType>());
dto.getSecurityAnswers().add(secQuesAnsType);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, dto.getSecurityAnswers().get(0).getQuestionAnswer());
// PropertyDelta delta= PropertyDelta.createModifica
System.out.println("Update Questions3");
deltas.add(ObjectDelta.createModifyDelta(useroid, delta, type, getPrismContext()));
System.out.println("Update Questions4");
getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_QUESTIONS), result);
System.out.println("Update Questions5");
*/
success(getString("message.success"));
target.add(getFeedbackPanel());
} catch (Exception ex) {
error(getString("message.error"));
target.add(getFeedbackPanel());
ex.printStackTrace();
}
}
use of com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel in project midpoint by Evolveum.
the class PageSecurityQuestions method savePerformed.
private void savePerformed(final AjaxRequestTarget target) {
int correctAnswers = 0;
for (Iterator iterator = pqPanels.iterator(); iterator.hasNext(); ) {
MyPasswordQuestionsPanel type = (MyPasswordQuestionsPanel) iterator.next();
List<SecurityQuestionAnswerDTO> userQuestionList = model.getObject().getSecurityAnswers();
if (userQuestionList != null) {
for (Iterator iterator2 = userQuestionList.iterator(); iterator2.hasNext(); ) {
SecurityQuestionAnswerDTO securityQuestionAnswerDTO = (SecurityQuestionAnswerDTO) iterator2.next();
// TODO do this in a proper way, what is this.
String results = StringEscapeUtils.unescapeHtml((type.get(MyPasswordQuestionsPanel.F_QUESTION)).getDefaultModelObjectAsString());
if (getQuestionIdentifierFromQuestion(results).trim().equalsIgnoreCase(securityQuestionAnswerDTO.getPwdQuestion().trim())) {
if (((TextField<String>) type.get(MyPasswordQuestionsPanel.F_ANSWER)).getModelObject().equalsIgnoreCase(securityQuestionAnswerDTO.getPwdAnswer())) {
correctAnswers++;
}
}
}
}
}
if (questionNumber == correctAnswers) {
getSession().removeAttribute(SESSION_ATTRIBUTE_POID);
runPrivileged(new Producer<Object>() {
@Override
public Object run() {
resetPassword(principalModel.getObject().asObjectable(), target);
return null;
}
});
} else {
warn(getString("pageSecurityQuestions.message.WrongAnswer"));
target.add(getFeedbackPanel());
return;
}
}
use of com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel in project midpoint by Evolveum.
the class PageSecurityQuestions method initLayout.
public void initLayout() {
Form mainForm = new Form(ID_MAIN_FORM);
pqPanels = new ArrayList<MyPasswordQuestionsPanel>();
PrismObject<SecurityPolicyType> securityPolicy = getSecurityPolicy();
LOGGER.trace("Found security policy: {}", securityPolicy);
if (securityPolicy == null) {
LOGGER.error("No security policy, cannot process security questions");
// we do not want to provide any information to the attacker.
throw new RestartResponseException(PageError.class);
}
questionNumber = securityPolicy.asObjectable().getCredentials() != null && securityPolicy.asObjectable().getCredentials().getSecurityQuestions() != null ? securityPolicy.asObjectable().getCredentials().getSecurityQuestions().getQuestionNumber() : 0;
policyQuestionList = securityPolicy.asObjectable().getCredentials() != null && securityPolicy.asObjectable().getCredentials().getSecurityQuestions() != null ? securityPolicy.asObjectable().getCredentials().getSecurityQuestions().getQuestion() : new ArrayList<SecurityQuestionDefinitionType>();
List<SecurityQuestionAnswerDTO> userQuestionList = model.getObject().getSecurityAnswers();
if (userQuestionList == null) {
getSession().error(getString("pageForgetPassword.message.ContactAdminQuestionsNotSet"));
SecurityContext securityContext = SecurityContextHolder.getContext();
securityContext.setAuthentication(null);
throw new RestartResponseException(PageForgotPassword.class);
}
if (questionNumber <= userQuestionList.size()) {
// Questions
for (Iterator iterator = policyQuestionList.iterator(); iterator.hasNext(); ) {
SecurityQuestionDefinitionType securityQuestionDefinitionType = (SecurityQuestionDefinitionType) iterator.next();
// user's question List loop to match the questions
for (int userQuestint = 0; userQuestint < userQuestionList.size(); userQuestint++) {
// if the question is in the policy check
int panelNumber = 0;
if (userQuestionList.get(userQuestint).getPwdQuestion().equalsIgnoreCase(securityQuestionDefinitionType.getIdentifier())) {
SecurityQuestionAnswerDTO a = new SecurityQuestionAnswerDTO(userQuestionList.get(userQuestint).getPwdQuestion(), "", userQuestionList.get(userQuestint).getQuestionItself());
a = checkIfQuestionisValid(a, policyQuestionList);
MyPasswordQuestionsPanel panel = new MyPasswordQuestionsPanel(ID_PASSWORD_QUESTIONS_PANEL + panelNumber, a);
pqPanels.add(panel);
panelNumber++;
// This is the Question!
}
}
}
}
add(mainForm);
mainForm.add(getPanels(pqPanels));
initButtons(mainForm);
}
use of com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel in project midpoint by Evolveum.
the class PageMyPasswordQuestions method executePasswordQuestionsAndAnswers.
/**
* method for get existing questions and answer from user credentials
* @author oguzhan
* @param userQuestionList
* @param policyQuestionList
* @param panelNumber
*/
public void executePasswordQuestionsAndAnswers(List<SecurityQuestionAnswerDTO> userQuestionList, List<SecurityQuestionDefinitionType> policyQuestionList, int panelNumber) {
int userQuest = 0;
LOGGER.debug("executePasswordQuestionsAndAnswers");
for (Iterator iterator = policyQuestionList.iterator(); iterator.hasNext(); ) {
/* Loop for finding the Existing Questions
* and Answers according to Policy*/
SecurityQuestionDefinitionType securityQuestionDefinitionType = (SecurityQuestionDefinitionType) iterator.next();
//user's question List loop to match the questions
for (int i = userQuest; i < userQuestionList.size(); i++) {
if (userQuestionList.get(i).getPwdQuestion().trim().compareTo(securityQuestionDefinitionType.getIdentifier().trim()) == 0) {
SecurityQuestionAnswerDTO a = new SecurityQuestionAnswerDTO(userQuestionList.get(i).getPwdQuestion(), userQuestionList.get(i).getPwdAnswer(), userQuestionList.get(i).getQuestionItself());
a = checkIfQuestionisValidSingle(a, securityQuestionDefinitionType);
MyPasswordQuestionsPanel panel = new MyPasswordQuestionsPanel(ID_PASSWORD_QUESTIONS_PANEL + panelNumber, a);
pqPanels.add(panel);
panelNumber++;
userQuest++;
break;
} else if (userQuestionList.get(i).getPwdQuestion().trim().compareTo(securityQuestionDefinitionType.getIdentifier().trim()) != 0) {
SecurityQuestionAnswerDTO a = new SecurityQuestionAnswerDTO(policyQuestionList.get(panelNumber).getIdentifier(), "", policyQuestionList.get(panelNumber).getQuestionText());
a.setQuestionItself(securityQuestionDefinitionType.getQuestionText());
userQuestionList.get(i).setPwdQuestion(securityQuestionDefinitionType.getIdentifier().trim());
MyPasswordQuestionsPanel panel = new MyPasswordQuestionsPanel(ID_PASSWORD_QUESTIONS_PANEL + panelNumber, a);
pqPanels.add(panel);
panelNumber++;
userQuest++;
break;
}
}
}
}
use of com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel in project midpoint by Evolveum.
the class PageMyPasswordQuestions method initLayout.
public void initLayout() {
Form mainForm = new Form(ID_MAIN_FORM);
//question panel list
pqPanels = new ArrayList<MyPasswordQuestionsPanel>();
OperationResult result = new OperationResult(OPERATION_LOAD_QUESTION_POLICY);
try {
Task task = getPageBase().createSimpleTask(OPERATION_LOAD_QUESTION_POLICY);
OperationResult subResult = result.createSubresult(OPERATION_LOAD_QUESTION_POLICY);
try {
//PrismObject<SystemConfigurationType> config = getPageBase().getModelService().getObject(
// SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null,
//task, result);
CredentialsPolicyType credPolicy = getModelInteractionService().getCredentialsPolicy(null, null, result);
//Global Policy set question numbers
if (credPolicy != null && credPolicy.getSecurityQuestions() != null) {
questionNumber = credPolicy.getSecurityQuestions().getQuestionNumber();
// Actual Policy Question List
policyQuestionList = credPolicy.getSecurityQuestions().getQuestion();
} else {
questionNumber = 0;
policyQuestionList = new ArrayList<SecurityQuestionDefinitionType>();
}
} catch (Exception ex) {
ex.printStackTrace();
/* List<SecurityQuestionAnswerDTO> userQuestionList= model.getObject().getSecurityAnswers();
int panelNumber=0;
PrismObject<UserType> user = null;
Collection options = SelectorOptions.createCollection(UserType.F_CREDENTIALS,
GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
Task taskTwo = createSimpleTask("LOAD USER WRAPPER");
user = getModelService().getObject(UserType.class, SecurityUtils.getPrincipalUser().getOid(), options, taskTwo, result);
OperationResult parentResult = new OperationResult(OPERATION_LOAD_QUESTION_POLICY);
questionNumber = getModelInteractionService().getCredentialsPolicy(user, parentResult).getSecurityQuestions().getQuestionNumber();
policyQuestionList=getModelInteractionService().getCredentialsPolicy(user, parentResult).getSecurityQuestions().getQuestion();
if(userQuestionList==null){
executeAddingQuestions(questionNumber, 0, policyQuestionList);
LOGGER.info(getModelInteractionService().getCredentialsPolicy(user, parentResult).getSecurityQuestions().getQuestionNumber().toString());
}else{
for(int userQuestint=0;userQuestint<userQuestionList.size();userQuestint++){
SecurityQuestionAnswerDTO answerDTO= checkIfQuestionisValid(userQuestionList.get(userQuestint), policyQuestionList);
if (userQuestionList.get(userQuestint)!=null){
LOGGER.debug("Questitself"+userQuestionList.get(userQuestint).getQuestionItself());
MyPasswordQuestionsPanel panel=new MyPasswordQuestionsPanel(ID_PASSWORD_QUESTIONS_PANEL+ panelNumber,userQuestionList.get(userQuestint));
pqPanels.add(panel);
panelNumber++;
}
}
//TODO same questions check should be implemented
}
add(mainForm);
mainForm.add(getPanels(pqPanels));
initButtons(mainForm);
return;
*/
}
/*User's Pre-Set Question List*/
List<SecurityQuestionAnswerDTO> userQuestionList = model.getObject().getSecurityAnswers();
//Case that policy have more than users's number of numbers
if ((userQuestionList == null) || (questionNumber > userQuestionList.size())) {
if (userQuestionList == null) {
executeAddingQuestions(questionNumber, 0, policyQuestionList);
//TODO same questions check should be implemented
} else {
executePasswordQuestionsAndAnswers(userQuestionList, policyQuestionList, userQuestionList.size());
//QUESTION NUMBER BIGGER THAN QUESTION LIST
//rest of the questions
int difference = questionNumber - userQuestionList.size();
executeAddingQuestions(difference, userQuestionList.size(), policyQuestionList);
}
} else if (questionNumber == userQuestionList.size()) {
//QUESTION NUMBER EQUALS TO QUESTION LIST
executePasswordQuestionsAndAnswers(userQuestionList, policyQuestionList, 0);
//TODO PART2: Case that policy have smaller than users's number of numbers
} else if (questionNumber < userQuestionList.size()) {
//QUESTION NUMBER SMALLER THAN QUESTION LIST
executePasswordQuestionsAndAnswers(userQuestionList, policyQuestionList, 0);
//this part will be using at remove operation in the future
/* int diff = userQuestionList.size()-questionNumber;
for(Iterator iterator = userQuestionList.iterator(); iterator.hasNext();){
SecurityQuestionAnswerDTO element = (SecurityQuestionAnswerDTO)iterator.next();
for(int i=0; i<diff;i++){
if(element == userQuestionList.get(questionNumber+i)){
try{
//LOGGER.info("REMOVE");
iterator.remove();
} catch (UnsupportedOperationException uoe) {
LOGGER.info(uoe.getStackTrace().toString());
}
}
}
}*/
}
} catch (Exception ex) {
result.recordFatalError("Couldn't load system configuration.", ex);
}
add(mainForm);
mainForm.add(getPanels(pqPanels));
initButtons(mainForm);
}
Aggregations