List of usage examples for org.apache.commons.validator.routines EmailValidator getInstance
public static EmailValidator getInstance()
From source file:com.google.gerrit.pgm.init.InitAdminUser.java
private String readEmail(AccountSshKey sshKey) { String defaultEmail = "admin@example.com"; if (sshKey != null && sshKey.getComment() != null) { String c = sshKey.getComment().trim(); if (EmailValidator.getInstance().isValid(c)) { defaultEmail = c;//from w w w.j a v a 2s .c om } } return readEmail(defaultEmail); }
From source file:com.google.gerrit.server.account.CreateAccount.java
@Override public Response<AccountInfo> apply(TopLevelResource rsrc, AccountInput input) throws BadRequestException, ResourceConflictException, UnprocessableEntityException, OrmException, IOException, ConfigInvalidException { if (input == null) { input = new AccountInput(); }/*www . j a v a 2 s . c o m*/ if (input.username != null && !username.equals(input.username)) { throw new BadRequestException("username must match URL"); } if (!username.matches(Account.USER_NAME_PATTERN)) { throw new BadRequestException( "Username '" + username + "'" + " must contain only letters, numbers, _, - or ."); } Set<AccountGroup.Id> groups = parseGroups(input.groups); Account.Id id = new Account.Id(db.nextAccountId()); AccountExternalId extUser = new AccountExternalId(id, new AccountExternalId.Key(AccountExternalId.SCHEME_USERNAME, username)); if (input.httpPassword != null) { extUser.setPassword(input.httpPassword); } if (db.accountExternalIds().get(extUser.getKey()) != null) { throw new ResourceConflictException("username '" + username + "' already exists"); } if (input.email != null) { if (db.accountExternalIds().get(getEmailKey(input.email)) != null) { throw new UnprocessableEntityException("email '" + input.email + "' already exists"); } if (!EmailValidator.getInstance().isValid(input.email)) { throw new BadRequestException("invalid email address"); } } LinkedList<AccountExternalId> externalIds = new LinkedList<>(); externalIds.add(extUser); for (AccountExternalIdCreator c : externalIdCreators) { externalIds.addAll(c.create(id, username, input.email)); } try { db.accountExternalIds().insert(externalIds); } catch (OrmDuplicateKeyException duplicateKey) { throw new ResourceConflictException("username '" + username + "' already exists"); } if (input.email != null) { AccountExternalId extMailto = new AccountExternalId(id, getEmailKey(input.email)); extMailto.setEmailAddress(input.email); try { db.accountExternalIds().insert(Collections.singleton(extMailto)); } catch (OrmDuplicateKeyException duplicateKey) { try { db.accountExternalIds().delete(Collections.singleton(extUser)); } catch (OrmException cleanupError) { // Ignored } throw new UnprocessableEntityException("email '" + input.email + "' already exists"); } } Account a = new Account(id, TimeUtil.nowTs()); a.setFullName(input.name); a.setPreferredEmail(input.email); db.accounts().insert(Collections.singleton(a)); for (AccountGroup.Id groupId : groups) { AccountGroupMember m = new AccountGroupMember(new AccountGroupMember.Key(id, groupId)); auditService.dispatchAddAccountsToGroup(currentUser.get().getAccountId(), Collections.singleton(m)); db.accountGroupMembers().insert(Collections.singleton(m)); } if (input.sshKey != null) { try { authorizedKeys.addKey(id, input.sshKey); sshKeyCache.evict(username); } catch (InvalidSshKeyException e) { throw new BadRequestException(e.getMessage()); } } accountCache.evictByUsername(username); byEmailCache.evict(input.email); indexer.index(id); AccountLoader loader = infoLoader.create(true); AccountInfo info = loader.get(id); loader.fill(); return Response.created(info); }
From source file:$.UserAction.java
private void validateUser(DefaultUser user, String confirmPassword) { User u = userManager.getUserById(user.getId()); String username = u == null ? "" : u.getUsername(); String email = u == null ? "" : u.getEmail(); if (StringUtils.isBlank(user.getUsername())) { addFieldError("user.username", getText("message.admin.user.username.notempty")); } else {/*www . j ava 2 s . c o m*/ if (!StringUtils.equals(username, user.getUsername())) { if (userManager.getUserByUsername(user.getUsername()) != null) addFieldError("user.username", getText("message.admin.user.username.exist")); } } if (StringUtils.isBlank(user.getEmail())) { addFieldError("user.email", getText("message.admin.user.email.notempty")); } else if (!EmailValidator.getInstance().isValid(user.getEmail())) { addFieldError("user.email", getText("message.admin.user.username.notvalid")); } else { if (StringUtils.isNotBlank(user.getId())) { if (!StringUtils.equals(email, user.getEmail())) { if (userManager.getUserByEmail(user.getEmail()) != null) addFieldError("user.email", getText("message.admin.user.username.exist")); } } else { if (userManager.getUserByEmail(user.getEmail()) != null) addFieldError("user.email", getText("message.admin.user.username.exist")); } } if (StringUtils.isBlank(user.getPassword()) && StringUtils.isBlank(user.getId())) { addFieldError("user.password", getText("message.admin.user.password.notempty")); } if (!StringUtils.equals(user.getPassword(), confirmPassword)) { addFieldError("confirmPassword", getText("message.admin.user.password.notmatch")); } }
From source file:de.jost_net.JVerein.server.MitgliedImpl.java
@SuppressWarnings("unused") private void plausi() throws RemoteException, ApplicationException { checkExterneMitgliedsnummer();/*from w ww .j a v a 2 s . co m*/ if (getPersonenart() == null || (!getPersonenart().equals("n") && !getPersonenart().equals("j"))) { throw new ApplicationException("Personenstatus ist nicht 'n' oder 'j'"); } if (getName() == null || getName().length() == 0) { throw new ApplicationException("Bitte Namen eingeben"); } if (getPersonenart().equals("n") && (getVorname() == null || getVorname().length() == 0)) { throw new ApplicationException("Bitte Vornamen eingeben"); } if (getAdresstyp().getJVereinid() == 1 && getPersonenart().equals("n") && getGeburtsdatum().getTime() == Einstellungen.NODATE.getTime() && Einstellungen.getEinstellung().getGeburtsdatumPflicht()) { throw new ApplicationException("Bitte Geburtsdatum eingeben"); } if (getAdresstyp().getJVereinid() == 1 && getPersonenart().equals("n") && Einstellungen.getEinstellung().getGeburtsdatumPflicht()) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(getGeburtsdatum()); Calendar cal2 = Calendar.getInstance(); if (cal1.after(cal2)) { throw new ApplicationException("Geburtsdatum liegt in der Zukunft"); } if (getSterbetag() != null) { cal2.setTime(getSterbetag()); } cal2.add(Calendar.YEAR, -150); if (cal1.before(cal2)) { throw new ApplicationException("Ist das Mitglied wirklich lter als 150 Jahre?"); } } if (getPersonenart().equals("n") && getGeschlecht() == null) { throw new ApplicationException("Bitte Geschlecht auswhlen"); } if (getEmail() != null && getEmail().length() > 0) { if (!EmailValidator.getInstance().isValid(getEmail())) { throw new ApplicationException("Ungltige Email-Adresse."); } } if (getAdresstyp().getJVereinid() == 1 && getEintritt().getTime() == Einstellungen.NODATE.getTime() && Einstellungen.getEinstellung().getEintrittsdatumPflicht()) { throw new ApplicationException("Bitte Eintrittsdatum eingeben"); } if (getAdresstyp().getJVereinid() == 1 && getZahlungsweg() == Zahlungsweg.BASISLASTSCHRIFT && BeitragsUtil.getBeitrag(Einstellungen.getEinstellung().getBeitragsmodel(), this.getZahlungstermin(), this.getZahlungsrhythmus().getKey(), this.getBeitragsgruppe(), new Date(), getEintritt(), getAustritt()) > 0) { if (getBic() == null || getBic().length() == 0 || getIban() == null || getIban().length() == 0) { throw new ApplicationException("Bitte BIC und IBAN eingeben"); } } if (getIban() != null && getIban().length() != 0) { try { new IBAN(getIban()); } catch (SEPAException e) { if (e.getFehler() != Fehler.UNGUELTIGES_LAND) { throw new ApplicationException(e.getMessage()); } } } if (getBic() != null && getBic().length() != 0) { try { new BIC(getBic()); } catch (SEPAException e) { if (!e.getMessage().startsWith("Ungltiges Land")) { throw new ApplicationException(e.getMessage()); } } } if (getZahlungsrhythmus() == null) { throw new ApplicationException("Ungltiger Zahlungsrhytmus: " + getZahlungsrhythmus()); } if (getSterbetag() != null && getAustritt() == null) { throw new ApplicationException("Bei verstorbenem Mitglied muss das Austrittsdatum gefllt sein!"); } if (getAustritt() != null || getKuendigung() != null) { // Person ist ausgetreten // Hat das Mitglied fr andere gezahlt? if (getBeitragsgruppe().getBeitragsArt() == ArtBeitragsart.FAMILIE_ZAHLER) { // ja DBIterator<Mitglied> famang = Einstellungen.getDBService().createList(Mitglied.class); famang.addFilter("zahlerid = " + getID()); famang.addFilter("austritt is null"); if (famang.hasNext()) { throw new ApplicationException( "Dieses Mitglied zahlt noch fr andere Mitglieder. Zunchst Beitragsart der Angehrigen ndern!"); } } } if (getBeitragsgruppe() != null && getBeitragsgruppe().getBeitragsArt() == ArtBeitragsart.FAMILIE_ANGEHOERIGER && getZahlerID() == null) { throw new ApplicationException("Bitte Zahler auswhlen!"); } }
From source file:com.google.gerrit.pgm.init.InitAdminUser.java
private String readEmail(String defaultEmail) { String email = ui.readString(defaultEmail, "email"); if (email != null && !EmailValidator.getInstance().isValid(email)) { ui.message("error: invalid email address\n"); return readEmail(defaultEmail); }// w ww. j av a 2s. c om return email; }
From source file:$.ProfileAction.java
private void validateUser(DefaultUser user) { User currentUser = sessionCredential.getCurrentUser(); if (StringUtils.isBlank(user.getUsername())) addFieldError("user.username", getText("message.profile.username.notempty")); else {/*from w w w . j a v a 2s . c o m*/ String username = currentUser.getUsername(); if (!StringUtils.equals(username, user.getUsername())) if (userManager.getUserByUsername(user.getUsername()) != null) addFieldError("user.username", getText("message.profile.username.exist")); } if (StringUtils.isBlank(user.getEmail())) addFieldError("user.email", getText("message.profile.email.notempty")); else if (!EmailValidator.getInstance().isValid(user.getEmail())) addFieldError("user.email", getText("message.profile.email.notvalid")); else { String email = currentUser.getEmail(); if (!StringUtils.equals(email, user.getEmail())) { if (userManager.getUserByEmail(user.getEmail()) != null) addFieldError("user.email", getText("message.profile.email.exist")); } } }
From source file:eu.vranckaert.worktime.activities.account.AccountRegisterActivity.java
/** * * @return/*from w w w . ja v a 2s. c o m*/ */ private boolean validateInput() { registrationError.setVisibility(View.GONE); ContextUtils.hideKeyboard(AccountRegisterActivity.this, email); ContextUtils.hideKeyboard(AccountRegisterActivity.this, firstName); ContextUtils.hideKeyboard(AccountRegisterActivity.this, lastName); ContextUtils.hideKeyboard(AccountRegisterActivity.this, password); ContextUtils.hideKeyboard(AccountRegisterActivity.this, passwordConfirmation); String firstName = this.firstName.getText().toString().trim(); String lastName = this.lastName.getText().toString().trim(); String email = this.email.getText().toString(); String password = this.password.getText().toString(); String passwordConfirmation = this.passwordConfirmation.getText().toString(); if (StringUtils.isBlank(firstName) || StringUtils.isBlank(lastName) || StringUtils.isBlank(email) || StringUtils.isBlank(password) || StringUtils.isBlank(passwordConfirmation)) { registrationError.setText(R.string.lbl_account_register_error_all_fields_required); registrationError.setVisibility(View.VISIBLE); return false; } if (!EmailValidator.getInstance().isValid(email)) { registrationError.setText(R.string.lbl_account_register_error_invalid_email); registrationError.setVisibility(View.VISIBLE); return false; } RegexValidator rv = new RegexValidator("[A-Za-z0-9_\\-]*"); if (!rv.isValid(password)) { registrationError.setText(R.string.lbl_account_register_error_password_characters); registrationError.setVisibility(View.VISIBLE); return false; } if (password.length() < 6 || password.length() > 30) { registrationError.setText(R.string.lbl_account_register_error_password_invalid_length); registrationError.setVisibility(View.VISIBLE); return false; } if (!password.equals(passwordConfirmation)) { registrationError.setText(R.string.lbl_account_register_error_password_confirmation); registrationError.setVisibility(View.VISIBLE); return false; } return true; }
From source file:com.email.SendEmail.java
/** * Sends a single email and uses account based off of the section that the * email comes from after email is sent the attachments are gathered * together and collated into a single PDF file and a history entry is * created based off of that entry/*from w w w .ja v a 2s. c o m*/ * * @param eml EmailOutModel */ public static void sendEmails(EmailOutModel eml) { SystemEmailModel account = null; String section = eml.getSection(); if (eml.getSection().equalsIgnoreCase("Hearings") && (eml.getCaseType().equalsIgnoreCase("MED") || eml.getCaseType().equalsIgnoreCase("REP") || eml.getCaseType().equalsIgnoreCase("ULP"))) { section = eml.getCaseType(); } //Get Account for (SystemEmailModel acc : Global.getSystemEmailParams()) { if (acc.getSection().equals(section)) { account = acc; break; } } //Account Exists? if (account != null) { //Case Location String casePath = (eml.getCaseType().equals("CSC") || eml.getCaseType().equals("ORG")) ? FileService.getCaseFolderORGCSCLocation(eml) : FileService.getCaseFolderLocation(eml); //Attachment List boolean allFilesExists = true; List<EmailOutAttachmentModel> attachmentList = EmailOutAttachment.getAttachmentsByEmail(eml.getId()); for (EmailOutAttachmentModel attach : attachmentList) { File attachment = new File(casePath + attach.getFileName()); boolean exists = attachment.exists(); if (exists == false) { allFilesExists = false; SECExceptionsModel item = new SECExceptionsModel(); item.setClassName("SendEmail"); item.setMethodName("sendEmails"); item.setExceptionType("FileMissing"); item.setExceptionDescription("Can't Send Email, File Missing for EmailID: " + eml.getId() + System.lineSeparator() + "EmailSubject: " + eml.getSubject() + System.lineSeparator() + "File: " + attachment); ExceptionHandler.HandleNoException(item); break; } else { if ("docx".equalsIgnoreCase(FilenameUtils.getExtension(attach.getFileName())) || "doc".equalsIgnoreCase(FilenameUtils.getExtension(attach.getFileName()))) { if (!attachment.renameTo(attachment)) { allFilesExists = false; SECExceptionsModel item = new SECExceptionsModel(); item.setClassName("SendEmail"); item.setMethodName("sendEmails"); item.setExceptionType("File In Use"); item.setExceptionDescription("Can't Send Email, File In Use for EmailID: " + eml.getId() + System.lineSeparator() + "EmailSubject: " + eml.getSubject() + System.lineSeparator() + "File: " + attachment); ExceptionHandler.HandleNoException(item); break; } } } } if (allFilesExists) { //Set up Initial Merge Utility PDFMergerUtility ut = new PDFMergerUtility(); //List ConversionPDFs To Delete Later List<String> tempPDFList = new ArrayList<>(); //create email message body Date emailSentTime = new Date(); String emailPDFname = EmailBodyToPDF.createEmailOutBody(eml, attachmentList, emailSentTime); //Add Email Body To PDF Merge try { ut.addSource(casePath + emailPDFname); tempPDFList.add(casePath + emailPDFname); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //Get parts String FromAddress = account.getEmailAddress(); String[] TOAddressess = ((eml.getTo() == null) ? "".split(";") : eml.getTo().split(";")); String[] CCAddressess = ((eml.getCc() == null) ? "".split(";") : eml.getCc().split(";")); String[] BCCAddressess = ((eml.getBcc() == null) ? "".split(";") : eml.getBcc().split(";")); String emailSubject = eml.getSubject(); String emailBody = eml.getBody(); //Set Email Parts Authenticator auth = EmailAuthenticator.setEmailAuthenticator(account); Properties properties = EmailProperties.setEmailOutProperties(account); Session session = Session.getInstance(properties, auth); MimeMessage smessage = new MimeMessage(session); Multipart multipart = new MimeMultipart(); //Add Parts to Email Message try { smessage.addFrom(new InternetAddress[] { new InternetAddress(FromAddress) }); for (String To : TOAddressess) { if (EmailValidator.getInstance().isValid(To)) { smessage.addRecipient(Message.RecipientType.TO, new InternetAddress(To)); } } for (String CC : CCAddressess) { if (EmailValidator.getInstance().isValid(CC)) { smessage.addRecipient(Message.RecipientType.CC, new InternetAddress(CC)); } } for (String BCC : BCCAddressess) { if (EmailValidator.getInstance().isValid(BCC)) { smessage.addRecipient(Message.RecipientType.BCC, new InternetAddress(BCC)); } } smessage.setSubject(emailSubject); MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(emailBody, "text/plain"); multipart.addBodyPart(messageBodyPart); //get attachments for (EmailOutAttachmentModel attachment : attachmentList) { String fileName = attachment.getFileName(); String extension = FilenameUtils.getExtension(fileName); //Convert attachments to PDF //If Image if (FileService.isImageFormat(fileName)) { fileName = ImageToPDF.createPDFFromImageNoDelete(casePath, fileName); //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); tempPDFList.add(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //If Word Doc } else if (extension.equals("docx") || extension.equals("doc")) { fileName = WordToPDF.createPDFNoDelete(casePath, fileName); //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); tempPDFList.add(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //If Text File } else if ("txt".equals(extension)) { fileName = TXTtoPDF.createPDFNoDelete(casePath, fileName); //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); tempPDFList.add(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //If PDF } else if (FilenameUtils.getExtension(fileName).equals("pdf")) { //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } } DataSource source = new FileDataSource(casePath + fileName); messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(fileName); multipart.addBodyPart(messageBodyPart); } smessage.setContent(multipart); //Send Message if (Global.isOkToSendEmail()) { Transport.send(smessage); } else { Audit.addAuditEntry("Email Not Actually Sent: " + eml.getId() + " - " + emailSubject); } //DocumentFileName String savedDoc = (String.valueOf(new Date().getTime()) + "_" + eml.getSubject()) .replaceAll("[:\\\\/*?|<>]", "_") + ".pdf"; //Set Merge File Destination ut.setDestinationFileName(casePath + savedDoc); //Try to Merge try { ut.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); } catch (IOException ex) { ExceptionHandler.Handle(ex); } //Add emailBody Activity addEmailActivity(eml, savedDoc, emailSentTime); //Copy to related case folders if (section.equals("MED")) { List<RelatedCaseModel> relatedMedList = RelatedCase.getRelatedCases(eml); if (relatedMedList.size() > 0) { for (RelatedCaseModel related : relatedMedList) { //Copy finalized document to proper folder File srcFile = new File(casePath + savedDoc); File destPath = new File((section.equals("CSC") || section.equals("ORG")) ? FileService.getCaseFolderORGCSCLocation(related) : FileService.getCaseFolderLocationRelatedCase(related)); destPath.mkdirs(); try { FileUtils.copyFileToDirectory(srcFile, destPath); } catch (IOException ex) { Logger.getLogger(SendEmail.class.getName()).log(Level.SEVERE, null, ex); } //Add Related Case Activity Entry addEmailActivityRelatedCase(eml, related, savedDoc, emailSentTime); } } } else { //This is blanket and should grab all related cases. (UNTESTED outside of CMDS) List<EmailOutRelatedCaseModel> relatedList = EmailOutRelatedCase.getRelatedCases(eml); if (relatedList.size() > 0) { for (EmailOutRelatedCaseModel related : relatedList) { //Copy finalized document to proper folder File srcFile = new File(casePath + savedDoc); File destPath = new File((section.equals("CSC") || section.equals("ORG")) ? FileService.getCaseFolderORGCSCLocation(related) : FileService.getCaseFolderLocationEmailOutRelatedCase(related)); destPath.mkdirs(); try { FileUtils.copyFileToDirectory(srcFile, destPath); } catch (IOException ex) { Logger.getLogger(SendEmail.class.getName()).log(Level.SEVERE, null, ex); } //Add Related Case Activity Entry addEmailOutActivityRelatedCase(eml, related, savedDoc, emailSentTime); } } } //Clean SQL entries EmailOut.deleteEmailEntry(eml.getId()); EmailOutAttachment.deleteAttachmentsForEmail(eml.getId()); EmailOutRelatedCase.deleteEmailOutRelatedForEmail(eml.getId()); //Clean up temp PDFs for (String tempPDF : tempPDFList) { new File(tempPDF).delete(); } } catch (AddressException ex) { ExceptionHandler.Handle(ex); } catch (MessagingException ex) { ExceptionHandler.Handle(ex); } } } }
From source file:com.intuit.wasabi.email.impl.EmailTextProcessorImpl.java
/** * Returns the email adresses of the experiment admins. * * @param appName the application we want the admins from * @return a set of their valid email addresses *///from ww w . j av a2 s . c o m private Set<String> getAdminEmails(Application.Name appName) { Set<String> adressors = new HashSet<>(); UserRoleList usersRoles = authorizationRepository.getApplicationUsers(appName); for (UserRole user : usersRoles.getRoleList()) { if (user.getRole() == Role.ADMIN) { String email = user.getUserEmail(); if (EmailValidator.getInstance().isValid(email)) { adressors.add(email); } else { LOGGER.warn("\"" + email + "\" is not a valid email address for one of the administrators of " + appName); } } } //no admins, no email! if (adressors.isEmpty()) { throw new WasabiEmailException("No Admins with an valid email registered for this Application"); } return adressors; }
From source file:com.formkiq.core.form.service.FormValidatorServiceImpl.java
@Override public void validateEmail(final String email) throws InvalidEmailException { if (!EmailValidator.getInstance().isValid(email)) { throw new InvalidEmailException(email); }//from w ww . ja va 2s . c o m }