Search in sources :

Example 1 with MyPasswordQuestionsPanel

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();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Iterator(java.util.Iterator) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with MyPasswordQuestionsPanel

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;
    }
}
Also used : SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) Iterator(java.util.Iterator) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 3 with MyPasswordQuestionsPanel

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);
}
Also used : SecurityQuestionDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) SecurityPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType) RestartResponseException(org.apache.wicket.RestartResponseException) SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) SecurityContext(org.springframework.security.core.context.SecurityContext) Iterator(java.util.Iterator) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel)

Example 4 with MyPasswordQuestionsPanel

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;
            }
        }
    }
}
Also used : SecurityQuestionDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType) SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) Iterator(java.util.Iterator) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel)

Example 5 with MyPasswordQuestionsPanel

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityQuestionDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType) Form(org.apache.wicket.markup.html.form.Form) SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CredentialsPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsPolicyType) RestartResponseException(org.apache.wicket.RestartResponseException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException)

Aggregations

MyPasswordQuestionsPanel (com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel)6 SecurityQuestionAnswerDTO (com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO)5 Iterator (java.util.Iterator)4 SecurityQuestionDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType)3 RestartResponseException (org.apache.wicket.RestartResponseException)3 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 Form (org.apache.wicket.markup.html.form.Form)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 CredentialsPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsPolicyType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 SecurityPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)1 SecurityQuestionAnswerType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)1 ArrayList (java.util.ArrayList)1