List of usage examples for com.vaadin.ui Notification TYPE_WARNING_MESSAGE
Type TYPE_WARNING_MESSAGE
To view the source code for com.vaadin.ui Notification TYPE_WARNING_MESSAGE.
Click Source Link
From source file:com.expressui.core.MainApplication.java
License:Open Source License
/** * Shows big warning box to user.//from w w w . ja va 2s. com * * @param warningMessage message to display */ public void showWarning(String warningMessage) { getMainWindow().showNotification(warningMessage, Window.Notification.TYPE_WARNING_MESSAGE); }
From source file:eu.lod2.EXMLExtended.java
License:Apache License
private void uploadToVirtuoso() throws LOD2Exception { if (exportGraph.getExportGraph() == null) { uploadButton.setComponentError(new UserError("No graph selected")); return;// w ww. j a v a 2 s .com } else if (oStream == null || oStream.toString().isEmpty()) { uploadButton.setComponentError(null); this.transform(); if (oStream.toString().isEmpty()) { this.getWindow().showNotification( "The transformation results in an empty dataset. This can be correct, or indicate an issue.", "", Notification.TYPE_WARNING_MESSAGE); return; } } try { rdfFile = new File(state.getCreatedUploadDir() + "file.rdf"); FileOutputStream fos = new FileOutputStream(rdfFile); oStream.writeTo(fos); String baseURI = state.getCurrentGraph() + "#"; RepositoryConnection con = state.getRdfStore().getConnection(); Resource contextURI = con.getValueFactory().createURI(exportGraph.getExportGraph()); Resource[] contexts = new Resource[] { contextURI }; con.add(rdfFile, baseURI, RDFFormat.RDFXML, contexts); } catch (Exception e) { e.printStackTrace(); throw new LOD2Exception("Upload failed:", e); } this.getWindow().showNotification("The processing has succeeded.", "", Notification.TYPE_HUMANIZED_MESSAGE); }
From source file:org.vaadin.addons.sitekit.flow.AbstractFlowViewlet.java
License:Apache License
@SuppressWarnings("unchecked") @Override// w w w . j a v a 2 s.c om public final <T extends Flowlet> T back() { if (!viewPath.getLast().isDirty()) { viewPath.removeLast(); final Flowlet view = viewPath.getLast(); refreshPathLabels(); view.enter(); tabSheet.setSelectedTab((Component) view); return (T) view; } else { Notification.show("Please save or discard changes.", Notification.TYPE_WARNING_MESSAGE); return null; } }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.login.ForgotPasswordFlowlet.java
License:Apache License
@Override public void initialize() { pinProperty = new ObjectProperty<String>(null, String.class); emailAddressProperty = new ObjectProperty<String>(null, String.class); final List<FieldDescriptor> fieldDescriptors = new ArrayList<FieldDescriptor>(); fieldDescriptors.add(new FieldDescriptor("pin", getSite().localize("input-password-reset-pin"), TextField.class, null, 150, null, String.class, null, true, true, true)); fieldDescriptors.add(new FieldDescriptor("emailAddress", getSite().localize("input-email-address"), TextField.class, null, 150, null, String.class, null, false, true, true) .addValidator(new EmailValidator("Email address is not valid."))); editor = new ValidatingEditor(fieldDescriptors); final Button resetPasswordButton = new Button(getSite().localize("button-reset-password")); resetPasswordButton.addListener(new ClickListener() { /** The default serial version ID. */ private static final long serialVersionUID = 1L; @Override/*from w w w .j a v a 2 s . co m*/ public void buttonClick(final ClickEvent event) { editor.commit(); final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class); final Company company = getSite().getSiteContext().getObject(Company.class); final User user = UserDao.getUser(entityManager, company, (String) emailAddressProperty.getValue()); if (user == null) { Notification.show(getSite().localize("message-user-email-address-not-registered"), Notification.Type.WARNING_MESSAGE); return; } final List<EmailPasswordReset> emailPasswordResets = UserDao .getEmailPasswordResetByEmailAddress(entityManager, user); final Date now = new Date(); for (final EmailPasswordReset emailPasswordReset : emailPasswordResets) { if (now.getTime() - emailPasswordReset.getCreated().getTime() < 24 * 60 * 60 * 1000) { Notification.show(getSite().localize("message-password-reset-email-already-sent"), Notification.Type.ERROR_MESSAGE); return; } else { entityManager.getTransaction().begin(); try { entityManager.remove(emailPasswordReset); entityManager.getTransaction().commit(); } catch (final Exception e) { if (entityManager.getTransaction().isActive()) { entityManager.getTransaction().rollback(); } throw new SiteException("Error removing old email password reset.", e); } } } try { final String pin = (String) pinProperty.getValue(); final byte[] pinAndSaltBytes = (user.getEmailAddress() + ":" + pin).getBytes("UTF-8"); final MessageDigest md = MessageDigest.getInstance("SHA-256"); final byte[] pinAndSaltDigest = md.digest(pinAndSaltBytes); final EmailPasswordReset emailPasswordReset = new EmailPasswordReset(); emailPasswordReset.setUser(user); emailPasswordReset.setPinHash(StringUtil.toHexString(pinAndSaltDigest)); emailPasswordReset.setCreated(now); entityManager.getTransaction().begin(); try { entityManager.persist(emailPasswordReset); entityManager.getTransaction().commit(); } catch (final Exception e) { if (entityManager.getTransaction().isActive()) { entityManager.getTransaction().rollback(); } throw new SiteException("Error saving email password reset", e); } final String url = company.getUrl() + "#!reset/" + emailPasswordReset.getEmailPasswordResetId(); final Thread emailThread = new Thread(new Runnable() { @Override public void run() { EmailUtil.send(PropertiesUtil.getProperty("site", "smtp-host"), user.getEmailAddress(), company.getSupportEmailAddress(), "Password Reset Link", "Password reset has been requested for your user account." + "You can perform the reset using the following link: " + url); } }); emailThread.start(); Notification.show( getSite().localize("message-password-reset-email-sent") + getSite().localize("message-your-password-reset-pin-is") + pin, Notification.Type.WARNING_MESSAGE); final HttpServletRequest request = ((VaadinServletRequest) VaadinService.getCurrentRequest()) .getHttpServletRequest(); LOGGER.info("Password reset email sent to " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); getFlow().back(); } catch (final Exception e) { LOGGER.error("Error preparing password reset.", e); Notification.show(getSite().localize("message-password-reset-prepare-error"), Notification.TYPE_WARNING_MESSAGE); } reset(); } }); editor.addListener(new ValidatingEditorStateListener() { @Override public void editorStateChanged(final ValidatingEditor source) { if (source.isValid()) { resetPasswordButton.setEnabled(true); } else { resetPasswordButton.setEnabled(false); } } }); reset(); final VerticalLayout panel = new VerticalLayout(); panel.addComponent(editor); panel.addComponent(resetPasswordButton); panel.setSpacing(true); final HorizontalLayout mainLayout = new HorizontalLayout(); mainLayout.addComponent(panel); setViewContent(mainLayout); }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.login.LoginFlowlet.java
License:Apache License
@Override public void onLogin(final LoginEvent event) { if (event.getLoginParameter("username") == null) { Notification.show(getSite().localize("message-login-failed"), Notification.TYPE_WARNING_MESSAGE); return;//from ww w .j av a 2s . c om } if (event.getLoginParameter("password") == null) { Notification.show(getSite().localize("message-login-failed"), Notification.TYPE_WARNING_MESSAGE); return; } final HttpServletRequest request = ((VaadinServletRequest) VaadinService.getCurrentRequest()) .getHttpServletRequest(); final String userEmailAddress = event.getLoginParameter("username"); try { final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class); final Company company = getSite().getSiteContext().getObject(Company.class); final User user = UserDao.getUser(entityManager, company, userEmailAddress); if (user == null) { LOGGER.warn("User login failed due to not registered email address: " + userEmailAddress + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); Notification.show(getSite().localize("message-login-failed"), Notification.TYPE_WARNING_MESSAGE); return; } if (user.isLockedOut()) { LOGGER.warn("User login failed due to user being locked out: " + userEmailAddress + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); Notification.show(getSite().localize("message-login-failed"), Notification.TYPE_WARNING_MESSAGE); return; } final List<UserDirectory> userDirectories = UserDirectoryDao.getUserDirectories(entityManager, company); final String remoteIpAddress = request.getRemoteAddr(); boolean directoryLoginAttempted = false; for (final UserDirectory userDirectory : userDirectories) { if (!userDirectory.isEnabled()) { continue; } final String[] subnets = userDirectory.getSubNetWhiteList().split(","); for (final String subnet : subnets) { final CidrUtil cidrUtils = new CidrUtil(subnet); if (cidrUtils.isInRange(remoteIpAddress)) { directoryLoginAttempted = attemptDirectoryLogin(event, request, entityManager, company, user, userDirectory); break; } } if (directoryLoginAttempted) { break; } } if (!directoryLoginAttempted) { attemptLocalLogin(event, request, entityManager, company, user); } } catch (final Exception e) { LOGGER.error("Error logging in user: " + userEmailAddress + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")", e); Notification.show(getSite().localize("message-login-error"), Notification.TYPE_ERROR_MESSAGE); } }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.login.LoginFlowlet.java
License:Apache License
private boolean attemptDirectoryLogin(final LoginEvent event, final HttpServletRequest request, final EntityManager entityManager, final Company company, final User user, final UserDirectory userDirectory) throws IOException, NoSuchAlgorithmException, Exception { final ProcessingContext processingContext = new ProcessingContext(entityManager, request, user, getSite().getSecurityProvider().getRoles()); LOGGER.info("Attempting LDAP login: address: " + userDirectory.getAddress() + ":" + userDirectory.getPort() + ") email: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); final byte[] passwordAndSaltBytes = (user.getEmailAddress() + ":" + ((String) event.getLoginParameter("password"))).getBytes("UTF-8"); final String password = ((String) event.getLoginParameter("password")); final LdapConnection connection = new LdapNetworkConnection(userDirectory.getAddress(), userDirectory.getPort());//from w ww .j av a 2 s . com boolean passwordMatch = false; try { final String ldapLoginDn = userDirectory.getLoginDn(); final String ldapLoginPassword = userDirectory.getLoginPassword(); final String userEmailAttribute = userDirectory.getUserEmailAttribute(); final String userSearchBaseDn = userDirectory.getUserSearchBaseDn(); final String groupSearchBaseDn = userDirectory.getGroupSearchBaseDn(); final String userFilter = "(" + userEmailAttribute + "=" + user.getEmailAddress() + ")"; connection.bind(ldapLoginDn, ldapLoginPassword); final EntryCursor userCursor = connection.search(userSearchBaseDn, userFilter, SearchScope.ONELEVEL); if (!userCursor.next()) { LOGGER.warn("User not found from LDAP address: " + userDirectory.getAddress() + ":" + userDirectory.getPort() + ") email: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); userCursor.close(); connection.unBind(); return false; } else { final Entry userEntry = userCursor.get(); userCursor.close(); connection.unBind(); connection.bind(userEntry.getDn(), password); if (!isInRemoteGroup(connection, groupSearchBaseDn, userEntry, userDirectory.getRequiredRemoteGroup())) { LOGGER.warn("User not in required remote group '" + userDirectory.getRequiredRemoteGroup() + "', LDAP address: " + userDirectory.getAddress() + ":" + userDirectory.getPort() + ") email: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); Notification.show(getSite().localize("message-login-failed"), Notification.TYPE_WARNING_MESSAGE); return true; } final List<Group> groups = UserDao.getUserGroups(entityManager, company, user); final Map<String, Group> localGroups = new HashMap<String, Group>(); for (final Group group : groups) { localGroups.put(group.getName(), group); } for (final String remoteLocalGroupPair : userDirectory.getRemoteLocalGroupMapping().split(",")) { final String[] parts = remoteLocalGroupPair.split("="); if (parts.length != 2) { continue; } final String remoteGroupName = parts[0].trim(); final String localGroupName = parts[1].trim(); final boolean remoteGroupMember = isInRemoteGroup(connection, groupSearchBaseDn, userEntry, remoteGroupName); final boolean localGroupMember = localGroups.containsKey(localGroupName); final Group localGroup = UserDao.getGroup(entityManager, company, localGroupName); if (localGroup == null) { LOGGER.warn("No local group '" + localGroupName + "'. Skipping group membership synchronization."); continue; } if (remoteGroupMember && !localGroupMember) { UserDao.addGroupMember(entityManager, localGroup, user); LOGGER.info("Added user '" + user.getEmailAddress() + "' to group '" + localGroupName + "' (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); } else if (!remoteGroupMember && localGroupMember) { UserDao.removeGroupMember(entityManager, localGroup, user); LOGGER.info("Removed user '" + user.getEmailAddress() + "' from group '" + localGroupName + "' (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); } } passwordMatch = true; connection.unBind(); } } catch (final LdapException exception) { LOGGER.error("LDAP error: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")", exception); } if (passwordMatch) { LOGGER.info("User login: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); AuditService.log(processingContext, "directory password login"); final List<Group> groups = UserDao.getUserGroups(entityManager, company, user); user.setFailedLoginCount(0); UserDao.updateUser(entityManager, user); ((SecurityProviderSessionImpl) getSite().getSecurityProvider()).setUser(user, groups); UI.getCurrent().getNavigator().navigateTo(getSite().getCurrentNavigationVersion().getDefaultPageName()); } else { LOGGER.warn("User login, password mismatch: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); AuditService.log(processingContext, "directory password login failed"); user.setFailedLoginCount(user.getFailedLoginCount() + 1); if (user.getFailedLoginCount() > company.getMaxFailedLoginCount()) { user.setLockedOut(true); LOGGER.warn("User locked out due to too many failed login attempts: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); } UserDao.updateUser(entityManager, user); Notification.show(getSite().localize("message-login-failed"), Notification.TYPE_WARNING_MESSAGE); } return true; }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.login.LoginFlowlet.java
License:Apache License
private void attemptLocalLogin(final LoginEvent event, final HttpServletRequest request, final EntityManager entityManager, final Company company, final User user) throws UnsupportedEncodingException, NoSuchAlgorithmException { final ProcessingContext processingContext = new ProcessingContext(entityManager, request, user, getSite().getSecurityProvider().getRoles()); final byte[] passwordAndSaltBytes = (user.getEmailAddress() + ":" + ((String) event.getLoginParameter("password"))).getBytes("UTF-8"); final MessageDigest md = MessageDigest.getInstance("SHA-256"); final String passwordAndSaltDigest = StringUtil.toHexString(md.digest(passwordAndSaltBytes)); final boolean passwordMatch = passwordAndSaltDigest.equals(user.getPasswordHash()); if (passwordMatch) { LOGGER.info("User login: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); AuditService.log(processingContext, "password login"); final List<Group> groups = UserDao.getUserGroups(entityManager, company, user); user.setFailedLoginCount(0);/*from w ww . java2 s.co m*/ UserDao.updateUser(entityManager, user); ((SecurityProviderSessionImpl) getSite().getSecurityProvider()).setUser(user, groups); UI.getCurrent().getNavigator().navigateTo(getSite().getCurrentNavigationVersion().getDefaultPageName()); } else { LOGGER.warn("User login, password mismatch: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); AuditService.log(processingContext, "password login failed"); user.setFailedLoginCount(user.getFailedLoginCount() + 1); if (user.getFailedLoginCount() > company.getMaxFailedLoginCount()) { user.setLockedOut(true); LOGGER.warn("User locked out due to too many failed login attempts: " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); } UserDao.updateUser(entityManager, user); Notification.show(getSite().localize("message-login-failed"), Notification.TYPE_WARNING_MESSAGE); } }
From source file:org.vaadin.addons.sitekit.viewlet.anonymous.login.RegisterFlowlet.java
License:Apache License
@Override public void initialize() { originalPasswordProperty = new ObjectProperty<String>(null, String.class); verifiedPasswordProperty = new ObjectProperty<String>(null, String.class); final List<FieldDescriptor> fieldDescriptors = new ArrayList<FieldDescriptor>(); final PasswordValidator passwordValidator = new PasswordValidator(getSite(), originalPasswordProperty, "password2"); //fieldDescriptors.addAll(SiteFields.getFieldDescriptors(Customer.class)); for (final FieldDescriptor fieldDescriptor : SiteFields.getFieldDescriptors(Customer.class)) { if (fieldDescriptor.getId().equals("adminGroup")) { continue; }// w w w .j a v a 2 s . c o m if (fieldDescriptor.getId().equals("memberGroup")) { continue; } if (fieldDescriptor.getId().equals("created")) { continue; } if (fieldDescriptor.getId().equals("modified")) { continue; } fieldDescriptors.add(fieldDescriptor); } //fieldDescriptors.remove(fieldDescriptors.size() - 1); //fieldDescriptors.remove(fieldDescriptors.size() - 1); fieldDescriptors .add(new FieldDescriptor("password1", getSite().localize("input-password"), PasswordField.class, null, 150, null, String.class, null, false, true, true).addValidator(passwordValidator)); fieldDescriptors.add(new FieldDescriptor("password2", getSite().localize("input-password-verification"), PasswordField.class, null, 150, null, String.class, null, false, true, true) .addValidator(new PasswordVerificationValidator(getSite(), originalPasswordProperty))); editor = new ValidatingEditor(fieldDescriptors); passwordValidator.setEditor(editor); final Button registerButton = new Button(getSite().localize("button-register")); registerButton.addListener(new ClickListener() { /** The default serial version ID. */ private static final long serialVersionUID = 1L; @Override public void buttonClick(final ClickEvent event) { editor.commit(); customer.setCreated(new Date()); customer.setModified(customer.getCreated()); final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class); final Company company = getSite().getSiteContext().getObject(Company.class); final PostalAddress invoicingAddress = new PostalAddress(); final PostalAddress deliveryAddress = new PostalAddress(); customer.setInvoicingAddress(invoicingAddress); customer.setDeliveryAddress(deliveryAddress); if (UserDao.getUser(entityManager, company, customer.getEmailAddress()) != null) { Notification.show(getSite().localize("message-user-email-address-registered"), Notification.Type.WARNING_MESSAGE); return; } final HttpServletRequest request = ((VaadinServletRequest) VaadinService.getCurrentRequest()) .getHttpServletRequest(); try { final byte[] passwordAndSaltBytes = (customer.getEmailAddress() + ":" + ((String) originalPasswordProperty.getValue())).getBytes("UTF-8"); final MessageDigest md = MessageDigest.getInstance("SHA-256"); final byte[] passwordAndSaltDigest = md.digest(passwordAndSaltBytes); customer.setOwner(company); final User user = new User(company, customer.getFirstName(), customer.getLastName(), customer.getEmailAddress(), customer.getPhoneNumber(), StringUtil.toHexString(passwordAndSaltDigest)); if (UserDao.getGroup(entityManager, company, "user") == null) { UserDao.addGroup(entityManager, new Group(company, "user", "Default user group.")); } UserDao.addUser(entityManager, user, UserDao.getGroup(entityManager, company, "user")); CustomerDao.saveCustomer(entityManager, customer); UserDao.addGroupMember(entityManager, customer.getAdminGroup(), user); UserDao.addGroupMember(entityManager, customer.getMemberGroup(), user); final String url = company.getUrl() + "#!validate/" + user.getUserId(); final Thread emailThread = new Thread(new Runnable() { @Override public void run() { EmailUtil.send(PropertiesUtil.getProperty("site", "smtp-host"), user.getEmailAddress(), company.getSupportEmailAddress(), "Email Validation", "Please validate your email by browsing to this URL: " + url); } }); emailThread.start(); LOGGER.info("User registered " + user.getEmailAddress() + " (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")"); Notification.show(getSite().localize("message-registration-success"), Notification.Type.HUMANIZED_MESSAGE); getFlow().back(); } catch (final Exception e) { LOGGER.error("Error adding user. (IP: " + request.getRemoteHost() + ":" + request.getRemotePort() + ")", e); Notification.show(getSite().localize("message-registration-error"), Notification.TYPE_WARNING_MESSAGE); } reset(); } }); editor.addListener(new ValidatingEditorStateListener() { @Override public void editorStateChanged(final ValidatingEditor source) { if (source.isValid()) { registerButton.setEnabled(true); } else { registerButton.setEnabled(false); } } }); reset(); final VerticalLayout panel = new VerticalLayout(); panel.addComponent(editor); panel.addComponent(registerButton); panel.setSpacing(true); final HorizontalLayout mainLayout = new HorizontalLayout(); mainLayout.addComponent(panel); setViewContent(mainLayout); }