List of usage examples for com.vaadin.server UserError UserError
public UserError(String textErrorMessage)
From source file:org.lucidj.newview.NewView.java
License:Apache License
private boolean component_fill_artifact_options(FormLayout form) { if (test_debug_artifact_options) { TextField email = new TextField("Email"); email.setValue("viking@surface.mars"); email.setWidth("50%"); email.setRequired(true);/* w w w.j a va2 s .c o m*/ form.addComponent(email); TextField location = new TextField("Location"); location.setValue("Mars, Solar System"); location.setWidth("50%"); location.setComponentError(new UserError("This address doesn't exist")); form.addComponent(location); TextField phone = new TextField("Phone"); phone.setWidth("50%"); form.addComponent(phone); } return (test_debug_artifact_options); }
From source file:org.opencms.ui.components.fileselect.CmsResourceSelectField.java
License:Open Source License
/** * Updates the resource value from the input field.<p> * * @param inputValue the input value/*ww w . j av a2 s . c o m*/ */ void updateValueFromInput(String inputValue) { m_textField.setComponentError(null); m_value = null; if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(inputValue)) { try { CmsObject cms = A_CmsUI.getCmsObject(); CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(inputValue); if (site != null) { CmsObject rootCms = OpenCms.initCmsObject(cms); rootCms.getRequestContext().setSiteRoot("/"); m_value = rootCms.readResource(inputValue, m_filter); } else { m_value = cms.readResource(inputValue, m_filter); } } catch (CmsException e) { LOG.trace("Could not read resource from input", e); m_textField.setComponentError(new UserError("The resource path is not valid")); } } }
From source file:org.opencms.ui.login.CmsChangePasswordDialog.java
License:Open Source License
/** * Checks the security level of the given password.<p> * * @param password the password// w w w . j a v a 2 s .co m */ void checkSecurity(String password) { I_CmsPasswordHandler handler = OpenCms.getPasswordHandler(); try { handler.validatePassword(password); if (handler instanceof I_CmsPasswordSecurityEvaluator) { SecurityLevel level = ((I_CmsPasswordSecurityEvaluator) handler).evaluatePasswordSecurity(password); m_form.setErrorPassword1(null, OpenCmsTheme.SECURITY + "-" + level.name()); } else { m_form.setErrorPassword1(null, OpenCmsTheme.SECURITY_STRONG); } } catch (CmsSecurityException e) { m_form.setErrorPassword1(new UserError(e.getLocalizedMessage(m_locale)), OpenCmsTheme.SECURITY_INVALID); } if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_form.getPassword2())) { showPasswordMatchError(!password.equals(m_form.getPassword2())); } }
From source file:org.opencms.ui.login.CmsChangePasswordDialog.java
License:Open Source License
/** * Shows or hides the not matching passwords error.<p> * * @param show <code>true</code> to show the error */// ww w.ja va2 s.c o m void showPasswordMatchError(boolean show) { if (show) { m_form.setErrorPassword2( new UserError( Messages.get().getBundle(m_locale).key(Messages.GUI_PWCHANGE_PASSWORD_MISMATCH_0)), OpenCmsTheme.SECURITY_INVALID); } else { m_form.setErrorPassword2(null, OpenCmsTheme.SECURITY_STRONG); } }
From source file:org.opencms.ui.login.CmsChangePasswordDialog.java
License:Open Source License
/** * Submits the password change.<p> *//* www . jav a 2 s . co m*/ void submit() { String password1 = m_form.getPassword1(); String password2 = m_form.getPassword2(); if (validatePasswords(password1, password2)) { String oldPassword = m_form.getOldPassword(); boolean error = false; if (oldPassword.equals(password1)) { m_form.setErrorPassword1( new UserError(Messages.get().getBundle(m_locale) .key(Messages.GUI_PWCHANGE_DIFFERENT_PASSWORD_REQUIRED_0)), OpenCmsTheme.SECURITY_INVALID); error = true; } else { try { m_cms.setPassword(m_user.getName(), oldPassword, password1); } catch (CmsException e) { m_form.setErrorOldPassword(new UserError(e.getLocalizedMessage(m_locale)), OpenCmsTheme.SECURITY_INVALID); error = true; LOG.debug(e.getLocalizedMessage(), e); } } if (!error) { if (m_context != null) { close(); } else { // this will be the case for forced password changes after login CmsVaadinUtils.showAlert( Messages.get().getBundle(m_locale).key(Messages.GUI_PWCHANGE_SUCCESS_HEADER_0), Messages.get().getBundle(m_locale) .key(Messages.GUI_PWCHANGE_GUI_PWCHANGE_SUCCESS_CONTENT_0), new Runnable() { public void run() { A_CmsUI.get().getPage() .setLocation(OpenCms.getLinkManager().substituteLinkForUnknownTarget( CmsLoginUI.m_adminCms, CmsWorkplaceLoginHandler.LOGIN_HANDLER, false)); } }); } } } }
From source file:org.opencms.ui.login.CmsChangePasswordDialog.java
License:Open Source License
/** * Validates the passwords, checking if they match and fulfill the requirements of the password handler.<p> * Will show the appropriate errors if necessary.<p> * * @param password1 password 1//from w ww .j a v a2 s. c o m * @param password2 password 2 * * @return <code>true</code> if valid */ boolean validatePasswords(String password1, String password2) { if (!password1.equals(password2)) { showPasswordMatchError(true); return false; } showPasswordMatchError(false); try { OpenCms.getPasswordHandler().validatePassword(password1); m_form.getPassword1Field().setComponentError(null); return true; } catch (CmsException e) { m_form.setErrorPassword1(new UserError(e.getLocalizedMessage(m_locale)), OpenCmsTheme.SECURITY_INVALID); return false; } }
From source file:org.opencms.ui.login.CmsSetPasswordDialog.java
License:Open Source License
/** * Submits the password.<p>//w ww.j a v a 2s . c o m */ @Override void submit() { if ((m_user == null) || m_user.isManaged()) { return; } String password1 = m_form.getPassword1(); String password2 = m_form.getPassword2(); String error = null; if (validatePasswords(password1, password2)) { try { m_cms.setPassword(m_user.getName(), password1); CmsTokenValidator.clearToken(CmsLoginUI.m_adminCms, m_user); } catch (CmsException e) { error = e.getLocalizedMessage(m_locale); LOG.debug(e.getLocalizedMessage(), e); } catch (Exception e) { error = e.getLocalizedMessage(); LOG.error(e.getLocalizedMessage(), e); } if (error != null) { m_form.setErrorPassword1(new UserError(error), OpenCmsTheme.SECURITY_INVALID); } else { CmsVaadinUtils.showAlert( Messages.get().getBundle(A_CmsUI.get().getLocale()) .key(Messages.GUI_PWCHANGE_SUCCESS_HEADER_0), Messages.get().getBundle(A_CmsUI.get().getLocale()) .key(Messages.GUI_PWCHANGE_GUI_PWCHANGE_SUCCESS_CONTENT_0), new Runnable() { public void run() { A_CmsUI.get().getPage() .setLocation(OpenCms.getLinkManager().substituteLinkForUnknownTarget( CmsLoginUI.m_adminCms, CmsWorkplaceLoginHandler.LOGIN_HANDLER, false)); } }); } } }
From source file:org.opennms.features.vaadin.jmxconfiggenerator.ui.UIHelper.java
License:Open Source License
/** * Validates the given field and sets the component error accordingly. * Please note, that the provided field must implement {@link Field} and must be a sub class of {@link AbstractComponent}. * * @param field The field to validate (must be a sub class of {@link AbstractComponent}). * @param swallowValidationExceptions Indicates if an InvalidValueException is swallowed and not propagated. * If false the first occurring InvalidValueException is thrown. * @throws Validator.InvalidValueException If the field is not valid (see {@link Validator#validate(Object)}. */// w ww .j a va 2s . c o m public static void validateField(Field<?> field, boolean swallowValidationExceptions) throws Validator.InvalidValueException { if (field instanceof AbstractComponent && field.isEnabled()) { try { field.validate(); ((AbstractComponent) field).setComponentError(null); } catch (Validator.InvalidValueException ex) { // Some fields unify exceptions, we have to consider this if (ex.getMessage() == null) { ex = ex.getCauses()[0]; } // set error message ((AbstractComponent) field).setComponentError(new UserError(ex.getMessage())); if (!swallowValidationExceptions) { throw ex; } } } }
From source file:org.solrsystem.ingest.vaadin.views.LogIn.java
License:Apache License
public LogIn() { loginLayout.setWidth("100%"); loginLayout.setHeight("300px"); loginForm.setSpacing(true);/*from w ww . ja v a 2 s .c o m*/ loginLabel.setImmediate(true); userNameTextField.setRequired(true); passwordField.setRequired(true); loginSubmit.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { authToken.setUsername(userNameTextField.getValue()); authToken.setPassword(passwordField.getValue().toCharArray()); try { Subject currentUser = SecurityUtils.getSubject(); currentUser.login(authToken); if (currentUser.isAuthenticated()) { User user = currentUser.getPrincipals().oneByType(User.class); loginLabel.setValue("Hello " + user.getDisplayName()); } } catch (UnknownAccountException uae) { userNameTextField.setComponentError(new UserError("Unknown User")); loginLabel.setValue("That user does not exist"); } catch (IncorrectCredentialsException ice) { loginLabel.setValue("Invalid password"); passwordField.setComponentError(new UserError("Invalid Password")); } catch (LockedAccountException lae) { loginLabel.setValue("Account is locked. Contact your System Administrator"); loginLabel.setComponentError(new UserError("Account locked")); } catch (ExcessiveAttemptsException eae) { loginLabel.setValue("Too many login failures."); loginLabel.setComponentError(new UserError("Failures Exceeded")); } catch (Exception e) { e.printStackTrace(); loginLabel.setValue("Internal Error:" + e.getMessage()); } } }); loginForm.addComponent(loginLabel); loginForm.addComponent(userNameTextField); loginForm.addComponent(passwordField); loginForm.addComponent(loginSubmit); loginLayout.addComponent(loginForm, 1, 1); }
From source file:org.vaadin.viritin.components.UploadFileHandler.java
License:Apache License
/** * By default just spans a new raw thread to get the input. For strict Java * EE fellows, this might not suite, so override and use executor service. * * @param in the input stream where file content can be handled * @param filename the file name on the senders machine * @param mimeType the mimeType interpreted from the file name *//*ww w. jav a2s .c o m*/ protected void writeResponce(final PipedInputStream in, String filename, String mimeType) { new Thread() { @Override public void run() { try { fileHandler.handleFile(in, filename, mimeType); in.close(); } catch (Exception e) { getUI().access(() -> { setComponentError(new UserError("Handling file failed")); throw new RuntimeException(e); }); } } }.start(); }