Search in sources :

Example 21 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageRegistrationBase method initResetCredentialsConfiguration.

private void initResetCredentialsConfiguration() {
    SecurityPolicyType securityPolicy = resolveSecurityPolicy();
    this.resetPasswordPolicy = new ResetPolicyDto();
    try {
        this.resetPasswordPolicy.initResetPolicyDto(securityPolicy);
    } catch (SchemaException e) {
        LOGGER.error("Failed to initialize self registration configuration.", e);
        getSession().error(createStringResource("PageSelfRegistration.selfRegistration.configuration.init.failed").getString());
        throw new RestartResponseException(PageLogin.class);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) ResetPolicyDto(com.evolveum.midpoint.web.page.forgetpassword.ResetPolicyDto) SecurityPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)

Example 22 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageSecurityQuestions method createUsersSecurityQuestionsList.

private List<SecurityQuestionDto> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
    SecurityQuestionsCredentialsType credentialsPolicyType = user.asObjectable().getCredentials().getSecurityQuestions();
    if (credentialsPolicyType == null || credentialsPolicyType.getQuestionAnswer() == null || credentialsPolicyType.getQuestionAnswer().isEmpty()) {
        String key = "web.security.flexAuth.any.security.questions";
        error(getString(key));
        LOGGER.error(key);
        throw new RestartResponseException(PageSecurityQuestions.class);
    }
    List<SecurityQuestionAnswerType> secQuestAnsList = credentialsPolicyType.getQuestionAnswer();
    SecurityPolicyType securityPolicy = resolveSecurityPolicy(user);
    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);
    }
    if (securityPolicy.getCredentials() == null) {
        LOGGER.error("No credential for security policy, cannot process security questions");
        // we do not want to provide any information to the attacker.
        throw new RestartResponseException(PageError.class);
    }
    SecurityQuestionsCredentialsPolicyType secQuestionsPolicy = securityPolicy.getCredentials().getSecurityQuestions();
    List<SecurityQuestionDefinitionType> questionList = secQuestionsPolicy != null ? secQuestionsPolicy.getQuestion() : new ArrayList<SecurityQuestionDefinitionType>();
    List<SecurityQuestionDto> questionsDto = new ArrayList<SecurityQuestionDto>();
    int questionNumber = secQuestionsPolicy != null ? secQuestionsPolicy.getQuestionNumber() : 1;
    for (SecurityQuestionDefinitionType question : questionList) {
        if (Boolean.TRUE.equals(question.isEnabled())) {
            for (SecurityQuestionAnswerType userAnswer : secQuestAnsList) {
                if (question.getIdentifier().equals(userAnswer.getQuestionIdentifier())) {
                    SecurityQuestionDto questionDto = new SecurityQuestionDto(question.getIdentifier());
                    questionDto.setQuestionText(question.getQuestionText());
                    questionsDto.add(questionDto);
                    break;
                }
            }
        }
        if (questionNumber == questionsDto.size()) {
            break;
        }
    }
    if (questionsDto.size() < questionNumber) {
        String key = "pageForgetPassword.message.ContactAdminQuestionsNotSetEnough";
        error(getString(key));
        LOGGER.error(key);
        throw new RestartResponseException(PageSecurityQuestions.class);
    }
    return questionsDto;
}
Also used : ArrayList(java.util.ArrayList) SecurityQuestionDto(com.evolveum.midpoint.web.security.util.SecurityQuestionDto) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 23 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageAccountActivation method propagatePassword.

private void propagatePassword(AjaxRequestTarget target, Form<?> form) {
    List<ShadowType> shadowsToActivate = getShadowsToActivate();
    PasswordTextField passwordPanel = (PasswordTextField) form.get(createComponentPath(ID_PASSWORD));
    String value = passwordPanel.getModelObject();
    ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_USER_URI);
    UsernamePasswordAuthenticationToken token;
    try {
        token = authenticationEvaluator.authenticate(connEnv, new PasswordAuthenticationContext(userModel.getObject().getName().getOrig(), value, userModel.getObject().getClass()));
    } catch (Exception ex) {
        LOGGER.error("Failed to authenticate user, reason {}", ex.getMessage());
        getSession().error(getString("PageAccountActivation.authentication.failed"));
        throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
    }
    if (token == null) {
        LOGGER.error("Failed to authenticate user");
        getSession().error(getString("PageAccountActivation.authentication.failed"));
        throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
    }
    ProtectedStringType passwordValue = new ProtectedStringType();
    passwordValue.setClearValue(value);
    Collection<ObjectDelta<ShadowType>> passwordDeltas = new ArrayList<>(shadowsToActivate.size());
    for (ShadowType shadow : shadowsToActivate) {
        ObjectDelta<ShadowType> shadowDelta = getPrismContext().deltaFactory().object().createModificationReplaceProperty(ShadowType.class, shadow.getOid(), SchemaConstants.PATH_PASSWORD_VALUE, passwordValue);
        shadowDelta.addModificationReplaceProperty(ShadowType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_ACTIVE);
        passwordDeltas.add(shadowDelta);
    }
    OperationResult result = runPrivileged(new Producer<OperationResult>() {

        private static final long serialVersionUID = 1L;

        @Override
        public OperationResult run() {
            OperationResult result = new OperationResult(OPERATION_ACTIVATE_SHADOWS);
            Task task = createAnonymousTask(OPERATION_ACTIVATE_SHADOWS);
            WebModelServiceUtils.save((Collection) passwordDeltas, null, result, task, PageAccountActivation.this);
            return result;
        }
    });
    result.recomputeStatus();
    if (!result.isSuccess()) {
        getSession().error(getString("PageAccountActivation.account.activation.failed"));
        LOGGER.error("Failed to acitvate accounts, reason: {} ", result.getMessage());
        target.add(getFeedbackPanel());
    } else {
        getSession().success(getString("PageAccountActivation.account.activation.successful"));
        target.add(getFeedbackPanel());
        activated = true;
    }
    target.add(PageAccountActivation.this);
}
Also used : PasswordAuthenticationContext(com.evolveum.midpoint.model.api.context.PasswordAuthenticationContext) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment) RestartResponseException(org.apache.wicket.RestartResponseException) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 24 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PagePostAuthentication method initStaticLayout.

@Override
protected WebMarkupContainer initStaticLayout() {
    Task task = createSimpleTask(OPERATION_LOAD_WRAPPER);
    OperationResult result = new OperationResult(OPERATION_LOAD_WRAPPER);
    PrismObjectWrapperFactory<UserType> factory = findObjectWrapperFactory(userModel.getObject().asPrismObject().getDefinition());
    WrapperContext context = new WrapperContext(task, result);
    try {
        objectWrapper = factory.createObjectWrapper(userModel.getObject().asPrismObject(), ItemStatus.NOT_CHANGED, context);
    } catch (SchemaException e) {
        result.recordFatalError(getString("PagePostAuthentication.message.couldntPerformPostAuth.fatalError"));
        showResult(result);
        throw new RestartResponseException(PageLogin.class);
    }
    WebMarkupContainer wrappers = new WebMarkupContainer(ID_WRAPPER_CONTENT);
    try {
        Panel main = initItemPanel(ID_MAIN_PANEL, UserType.COMPLEX_TYPE, PrismContainerWrapperModel.fromContainerWrapper(Model.of(objectWrapper), ItemPath.EMPTY_PATH), null);
        wrappers.add(main);
        Panel password = initItemPanel(ID_PASSWORD_PANEL, PasswordType.COMPLEX_TYPE, PrismContainerWrapperModel.fromContainerWrapper(Model.of(objectWrapper), ItemPath.create(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD)), null);
        wrappers.add(password);
    } catch (SchemaException e) {
        LOGGER.error("Cannot create panel, {}", e.getMessage(), e);
        getSession().error("Unexpected error occurred. Please contact system administrator.");
        throw new RestartResponseException(PageLogin.class);
    }
    return wrappers;
}
Also used : WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Panel(org.apache.wicket.markup.html.panel.Panel) Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) PageLogin(com.evolveum.midpoint.web.page.login.PageLogin) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 25 with RestartResponseException

use of org.apache.wicket.RestartResponseException in project midpoint by Evolveum.

the class PageEmailNonse method processResetPassword.

private void processResetPassword(AjaxRequestTarget target) {
    UserType user = searchUser();
    if (user == null) {
        getSession().error(getString("pageForgetPassword.message.user.not.found"));
        throw new RestartResponseException(PageEmailNonse.class);
    }
    LOGGER.trace("Reset Password user: {}", user);
    if (getResetPasswordPolicy() == null) {
        LOGGER.debug("No policies for reset password defined");
        getSession().error(getString("pageForgetPassword.message.policy.not.found"));
        throw new RestartResponseException(PageEmailNonse.class);
    }
    OperationResult result = saveUserNonce(user, getMailNoncePolicy(user.asPrismObject()));
    if (result.getStatus() == OperationResultStatus.SUCCESS) {
        submited = true;
        target.add(PageEmailNonse.this);
    } else {
        getSession().error(getString("PageForgotPassword.send.nonce.failed"));
        LOGGER.error("Failed to send nonce to user: {} ", result.getMessage());
        throw new RestartResponseException(PageEmailNonse.this);
    }
}
Also used : RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

RestartResponseException (org.apache.wicket.RestartResponseException)73 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)36 Task (com.evolveum.midpoint.task.api.Task)27 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)20 ArrayList (java.util.ArrayList)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 CommonException (com.evolveum.midpoint.util.exception.CommonException)8 SecurityPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)5 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)5 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 PageError (com.evolveum.midpoint.web.page.error.PageError)5 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 Collection (java.util.Collection)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 IModel (org.apache.wicket.model.IModel)4 StringValue (org.apache.wicket.util.string.StringValue)4