Search in sources :

Example 6 with SecurityQuestionAnswerDTO

use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.

the class SecurityQuestionsPanel method createUsersSecurityQuestionsList.

public List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
    LOGGER.debug("Security Questions Loading for user: " + user.getOid());
    if (user.asObjectable().getCredentials() != null && user.asObjectable().getCredentials().getSecurityQuestions() != null) {
        List<SecurityQuestionAnswerType> secQuestAnsList = user.asObjectable().getCredentials().getSecurityQuestions().getQuestionAnswer();
        if (secQuestAnsList != null) {
            LOGGER.debug("User SecurityQuestion ANswer List is Not null");
            List<SecurityQuestionAnswerDTO> secQuestAnswListDTO = 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) {
                        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't decrypt user answer", e);
                    }
                }
                secQuestAnswListDTO.add(new SecurityQuestionAnswerDTO(securityQuestionAnswerType.getQuestionIdentifier(), decoded));
            }
            return secQuestAnswListDTO;
        }
    }
    return null;
}
Also used : SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) ArrayList(java.util.ArrayList) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Example 7 with SecurityQuestionAnswerDTO

use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO 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 8 with SecurityQuestionAnswerDTO

use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO 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)

Example 9 with SecurityQuestionAnswerDTO

use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.

the class PageMyPasswordQuestions method executeAddingQuestions.

/**
	 * method for adding questions to user credentials 
	 * @author oguzhan
	 * @param questionNumber
	 * @param panelNumber
	 * @param policyQuestionList
	 */
public void executeAddingQuestions(int questionNumber, int panelNumber, List<SecurityQuestionDefinitionType> policyQuestionList) {
    LOGGER.debug("executeAddingQuestions");
    for (int i = 0; i < questionNumber; i++) {
        //LOGGER.info("\n\n Adding panel element");
        SecurityQuestionAnswerDTO a = new SecurityQuestionAnswerDTO(policyQuestionList.get(panelNumber).getIdentifier(), "", policyQuestionList.get(panelNumber).getQuestionText());
        MyPasswordQuestionsPanel panel = new MyPasswordQuestionsPanel(ID_PASSWORD_QUESTIONS_PANEL + panelNumber, a);
        pqPanels.add(panel);
        panelNumber++;
    }
}
Also used : SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel)

Example 10 with SecurityQuestionAnswerDTO

use of com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO in project midpoint by Evolveum.

the class PageMyPasswordQuestions method createUsersSecurityQuestionsList.

public List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
    LOGGER.debug("Security Questions Loading for user: " + user.getOid());
    if (user.asObjectable().getCredentials() != null && user.asObjectable().getCredentials().getSecurityQuestions() != null) {
        List<SecurityQuestionAnswerType> secQuestAnsList = user.asObjectable().getCredentials().getSecurityQuestions().getQuestionAnswer();
        if (secQuestAnsList != null) {
            LOGGER.debug("User SecurityQuestion ANswer List is Not null");
            List<SecurityQuestionAnswerDTO> secQuestAnswListDTO = new ArrayList<SecurityQuestionAnswerDTO>();
            for (Iterator iterator = secQuestAnsList.iterator(); iterator.hasNext(); ) {
                SecurityQuestionAnswerType securityQuestionAnswerType = (SecurityQuestionAnswerType) iterator.next();
                Protector protector = getPrismContext().getDefaultProtector();
                String decoded = "";
                if (securityQuestionAnswerType.getQuestionAnswer().getEncryptedDataType() != null) {
                    try {
                        decoded = protector.decryptString(securityQuestionAnswerType.getQuestionAnswer());
                    } catch (EncryptionException e) {
                        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't decrypt user answer", e);
                    }
                }
                //LOGGER.debug("SecAnswerIdentifier:"+securityQuestionAnswerType.getQuestionIdentifier());
                secQuestAnswListDTO.add(new SecurityQuestionAnswerDTO(securityQuestionAnswerType.getQuestionIdentifier(), decoded));
            }
            return secQuestAnswListDTO;
        }
    }
    return null;
}
Also used : SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Aggregations

SecurityQuestionAnswerDTO (com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO)13 ArrayList (java.util.ArrayList)8 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)7 MyPasswordQuestionsPanel (com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel)5 Protector (com.evolveum.midpoint.prism.crypto.Protector)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 SecurityQuestionDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionDefinitionType)2 Iterator (java.util.Iterator)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 Form (org.apache.wicket.markup.html.form.Form)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 GuiProfiledPrincipal (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)1 PasswordQuestionsDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto)1 CredentialsPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsPolicyType)1 SecurityQuestionAnswerType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType)1