Search in sources :

Example 6 with PasswordQuestionsDto

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

the class SecurityQuestionsPanel method loadPageModel.

private PasswordQuestionsDto loadPageModel() {
    LOGGER.debug("Loading user for Security Question Page.");
    GuiProfiledPrincipal principalUser = AuthUtil.getPrincipalUser();
    PasswordQuestionsDto dto = new PasswordQuestionsDto(principalUser.getOid());
    OperationResult result = new OperationResult(OPERATION_LOAD_USER);
    try {
        Task task = getPageBase().createSimpleTask(OPERATION_LOAD_USER);
        OperationResult subResult = result.createSubresult(OPERATION_LOAD_USER);
        PrismObject<UserType> user = getPageBase().getModelService().getObject(UserType.class, principalUser.getOid(), null, task, subResult);
        dto.setUserQuestionAnswers(createUsersSecurityQuestionsList(user));
        subResult.recordSuccessIfUnknown();
    } catch (Exception ex) {
        LoggingUtils.logExceptionOnDebugLevel(LOGGER, "Couldn't get user Questions, Probably not set yet", ex);
    } finally {
        result.recomputeStatus();
    }
    CredentialsPolicyType credPolicy = principalUser.getApplicableSecurityPolicy().getCredentials();
    List<SecurityQuestionDefinitionType> questionsDef = new ArrayList<>();
    // Security Policy set question numbers
    if (credPolicy != null && credPolicy.getSecurityQuestions() != null) {
        // Actual Policy Question List
        questionsDef = getEnabledSecurityQuestions(credPolicy);
    } else {
        LOGGER.debug("Couldn't load credentials for security questions");
    }
    result = new OperationResult(OPERATION_LOAD_QUESTION_POLICY);
    try {
        /*User's Pre-Set Question List*/
        List<SecurityQuestionAnswerDTO> userQuestionList = dto.getUserQuestionAnswers();
        /* check if user's set number of
             * questions matches the policy or not*/
        // Case that policy have more than users's number of numbers
        int questionSize = questionsDef.size();
        if (userQuestionList == null) {
            dto.getActualQuestionAnswers().addAll(executeAddingQuestions(questionSize, 0, questionsDef));
        // TODO same questions check should be implemented
        } else if (questionSize > userQuestionList.size()) {
            dto.getActualQuestionAnswers().addAll(executePasswordQuestionsAndAnswers(userQuestionList, questionsDef, userQuestionList.size()));
            // QUESTION NUMBER BIGGER THAN QUESTION LIST
            // rest of the questions
            int difference = questionSize - userQuestionList.size();
            dto.getActualQuestionAnswers().addAll(executeAddingQuestions(difference, userQuestionList.size(), questionsDef));
        } else if (questionSize <= userQuestionList.size()) {
            // QUESTION NUMBER SMALLER THAN QUESTION LIST OR EQUALS TO QUESTION LIST
            dto.getActualQuestionAnswers().addAll(executePasswordQuestionsAndAnswers(userQuestionList, questionsDef, 0));
        }
    } catch (Exception ex) {
        result.recordFatalError(getString("PageMyPasswordQuestions.message.couldNotLoadSysConfig"), ex);
    }
    return dto;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) PasswordQuestionsDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto)

Aggregations

PasswordQuestionsDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 Collection (java.util.Collection)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 GuiProfiledPrincipal (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 SecurityQuestionAnswerDTO (com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO)1 ArrayList (java.util.ArrayList)1 Label (org.apache.wicket.markup.html.basic.Label)1 TextField (org.apache.wicket.markup.html.form.TextField)1 PropertyModel (org.apache.wicket.model.PropertyModel)1