List of usage examples for org.apache.commons.lang RandomStringUtils randomNumeric
public static String randomNumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of numeric characters.
From source file:org.cgiar.ccafs.marlo.action.crp.admin.CrpAdminManagmentAction.java
/** * This method will validate if the user is deactivated. If so, it will send an email indicating the credentials to * access./*from w ww .j a v a 2 s .c om*/ * * @param user is a User object that could be the leader. */ private void notifyNewUserCreated(User user) { user = userManager.getUser(user.getId()); if (!user.isActive()) { String toEmail = user.getEmail(); String ccEmail = null; String bbcEmails = this.config.getEmailNotification(); String subject = this.getText("email.newUser.subject", new String[] { user.getFirstName() }); // Setting the password String password = this.getText("email.outlookPassword"); if (!user.isCgiarUser()) { // Generating a random password. password = RandomStringUtils.randomNumeric(6); } // Building the Email message: StringBuilder message = new StringBuilder(); message.append(this.getText("email.dear", new String[] { user.getFirstName() })); // get CRPAdmin contacts String crpAdmins = ""; long adminRol = Long.parseLong((String) this.getSession().get(APConstants.CRP_ADMIN_ROLE)); Role roleAdmin = roleManager.getRoleById(adminRol); List<UserRole> userRoles = roleAdmin.getUserRoles().stream() .filter(ur -> ur.getUser() != null && ur.getUser().isActive()).collect(Collectors.toList()); for (UserRole userRole : userRoles) { if (crpAdmins.isEmpty()) { crpAdmins += userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } else { crpAdmins += ", " + userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } } message.append(this.getText("email.newUser.part1", new String[] { this.getText("email.newUser.listRoles"), config.getBaseUrl(), user.getEmail(), password, this.getText("email.support", new String[] { crpAdmins }) })); message.append(this.getText("email.bye")); // Saving the new user configuration. /** Leaving this for now as there is some strangeness in regards to the active/inactive flag for users. **/ user.setActive(true); user = userManager.saveUser(user); Map<String, Object> mapUser = new HashMap<>(); mapUser.put("user", user); mapUser.put("password", password); this.getUsersToActive().add(mapUser); // Send UserManual.pdf String contentType = "application/pdf"; String fileName = "Introduction_To_MARLO_v2.2.pdf"; byte[] buffer = null; InputStream inputStream = null; try { inputStream = this.getClass().getResourceAsStream("/manual/Introduction_To_MARLO_v2.2.pdf"); buffer = readFully(inputStream); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (buffer != null && fileName != null && contentType != null) { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), buffer, contentType, fileName, true); } else { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), null, null, null, true); } } }
From source file:org.cgiar.ccafs.marlo.action.crp.admin.CrpPpaPartnersAction.java
/** * This method will validate if the user is deactivated. If so, it will send an email indicating the credentials to * access.// www. j a v a2 s . c o m * * @param user is a User object that could be the leader. */ private void notifyNewUserCreated(User user) { user = userManager.getUser(user.getId()); if (!user.isActive()) { String toEmail = user.getEmail(); String ccEmail = null; String bbcEmails = this.config.getEmailNotification(); String subject = this.getText("email.newUser.subject", new String[] { user.getFirstName() }); // Setting the password String password = this.getText("email.outlookPassword"); if (!user.isCgiarUser()) { // Generating a random password. password = RandomStringUtils.randomNumeric(6); // Applying the password to the user. } // Building the Email message: StringBuilder message = new StringBuilder(); message.append(this.getText("email.dear", new String[] { user.getFirstName() })); // get CRPAdmin contacts String crpAdmins = ""; long adminRol = Long.parseLong((String) this.getSession().get(APConstants.CRP_ADMIN_ROLE)); Role roleAdmin = roleManager.getRoleById(adminRol); List<UserRole> userRoles = roleAdmin.getUserRoles().stream() .filter(ur -> ur.getUser() != null && ur.getUser().isActive()).collect(Collectors.toList()); for (UserRole userRole : userRoles) { if (crpAdmins.isEmpty()) { crpAdmins += userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } else { crpAdmins += ", " + userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } } message.append(this.getText("email.newUser.part1", new String[] { this.getText("email.newUser.listRoles"), config.getBaseUrl(), user.getEmail(), password, this.getText("email.support", new String[] { crpAdmins }) })); message.append(this.getText("email.bye")); // Saving crpUser Map<String, Object> mapUser = new HashMap<>(); mapUser.put("user", user); mapUser.put("password", password); this.getUsersToActive().add(mapUser); this.addCrpUserIfNotExist(user); // Send UserManual.pdf String contentType = "application/pdf"; String fileName = "Introduction_To_MARLO_v2.2.pdf"; byte[] buffer = null; InputStream inputStream = null; try { inputStream = this.getClass().getResourceAsStream("/manual/Introduction_To_MARLO_v2.2.pdf"); buffer = readFully(inputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } if (buffer != null && fileName != null && contentType != null) { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), buffer, contentType, fileName, true); } else { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), null, null, null, true); } } }
From source file:org.cgiar.ccafs.marlo.action.crp.admin.CrpProgamRegionsAction.java
/** * This method will validate if the user is deactivated. If so, it will send an email indicating the credentials to * access.// w w w. j av a 2 s . co m * * @param user is a User object that could be the leader. */ private void notifyNewUserCreated(User user) { user = userManager.getUser(user.getId()); if (!user.isActive()) { String toEmail = user.getEmail(); String ccEmail = null; String bbcEmails = this.config.getEmailNotification(); String subject = this.getText("email.newUser.subject", new String[] { user.getFirstName() }); // Setting the password String password = this.getText("email.outlookPassword"); if (!user.isCgiarUser()) { // Generating a random password. password = RandomStringUtils.randomNumeric(6); } // Building the Email message: StringBuilder message = new StringBuilder(); message.append(this.getText("email.dear", new String[] { user.getFirstName() })); // get CRPAdmin contacts String crpAdmins = ""; long adminRol = Long.parseLong((String) this.getSession().get(APConstants.CRP_ADMIN_ROLE)); Role roleAdmin = roleManager.getRoleById(adminRol); List<UserRole> userRoles = roleAdmin.getUserRoles().stream() .filter(ur -> ur.getUser() != null && ur.getUser().isActive()).collect(Collectors.toList()); for (UserRole userRole : userRoles) { if (crpAdmins.isEmpty()) { crpAdmins += userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } else { crpAdmins += ", " + userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } } message.append(this.getText("email.newUser.part1", new String[] { this.getText("email.newUser.listRoles"), config.getBaseUrl(), user.getEmail(), password, this.getText("email.support", new String[] { crpAdmins }) })); message.append(this.getText("email.bye")); Map<String, Object> mapUser = new HashMap<>(); mapUser.put("user", user); mapUser.put("password", password); this.getUsersToActive().add(mapUser); // Send UserManual.pdf String contentType = "application/pdf"; String fileName = "Introduction_To_MARLO_v2.2.pdf"; byte[] buffer = null; InputStream inputStream = null; try { inputStream = this.getClass().getResourceAsStream("/manual/Introduction_To_MARLO_v2.2.pdf"); buffer = readFully(inputStream); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (buffer != null && fileName != null && contentType != null) { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), buffer, contentType, fileName, true); } else { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), null, null, null, true); } } }
From source file:org.cgiar.ccafs.marlo.action.crp.admin.CrpSiteIntegrationAction.java
/** * This method will validate if the user is deactivated. If so, it will send an email indicating the credentials to * access.//from w ww . ja v a2s.co m * * @param user is a User object that could be the leader. */ private void notifyNewUserCreated(User user) { user = userManager.getUser(user.getId()); if (!user.isActive()) { String toEmail = user.getEmail(); String ccEmail = null; String bbcEmails = this.config.getEmailNotification(); String subject = this.getText("email.newUser.subject", new String[] { user.getFirstName() }); // Setting the password String password = this.getText("email.outlookPassword"); if (!user.isCgiarUser()) { // Generating a random password. password = RandomStringUtils.randomNumeric(6); } // Building the Email message: StringBuilder message = new StringBuilder(); message.append(this.getText("email.dear", new String[] { user.getFirstName() })); // get CRPAdmin contacts String crpAdmins = ""; long adminRol = Long.parseLong((String) this.getSession().get(APConstants.CRP_ADMIN_ROLE)); Role roleAdmin = roleManager.getRoleById(adminRol); List<UserRole> userRoles = roleAdmin.getUserRoles().stream() .filter(ur -> ur.getUser() != null && ur.getUser().isActive()).collect(Collectors.toList()); for (UserRole userRole : userRoles) { if (crpAdmins.isEmpty()) { crpAdmins += userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } else { crpAdmins += ", " + userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } } message.append(this.getText("email.newUser.part1", new String[] { this.getText("email.newUser.listRoles"), config.getBaseUrl(), user.getEmail(), password, this.getText("email.support", new String[] { crpAdmins }) })); message.append(this.getText("email.bye")); Map<String, Object> mapUser = new HashMap<>(); mapUser.put("user", user); mapUser.put("password", password); this.getUsersToActive().add(mapUser); // Send UserManual.pdf String contentType = "application/pdf"; String fileName = "Introduction_To_MARLO_v2.2.pdf"; byte[] buffer = null; InputStream inputStream = null; try { inputStream = this.getClass().getResourceAsStream("/custom/Introduction_To_MARLO_v2.2.pdf"); buffer = readFully(inputStream); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (buffer != null && fileName != null && contentType != null) { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), buffer, contentType, fileName, true); } else { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), null, null, null, true); } } }
From source file:org.cgiar.ccafs.marlo.action.projects.ProjectPartnerAction.java
/** * This method will validate if the user is deactivated. If so, it will send an email indicating the credentials to * access./*from www . jav a 2 s .com*/ * * @param leader is a PartnerPerson object that could be the leader or the coordinator. */ private void notifyNewUserCreated(User user) { if (user != null && user.getId() != null) { user = userManager.getUser(user.getId()); if (!user.isActive()) { String toEmail = user.getEmail(); String ccEmail = ""; String bbcEmails = this.config.getEmailNotification(); String subject = this.getText("email.newUser.subject", new String[] { user.getFirstName() }); // Setting the password String password = this.getText("email.outlookPassword"); if (!user.isCgiarUser()) { // Generating a random password. password = RandomStringUtils.randomNumeric(6); } // Building the Email message: StringBuilder message = new StringBuilder(); message.append(this.getText("email.dear", new String[] { user.getFirstName() })); // get CRPAdmin contacts String crpAdmins = ""; long adminRol = Long.parseLong((String) this.getSession().get(APConstants.CRP_ADMIN_ROLE)); Role roleAdmin = roleManager.getRoleById(adminRol); List<UserRole> userRoles = roleAdmin.getUserRoles().stream() .filter(ur -> ur.getUser() != null && ur.getUser().isActive()).collect(Collectors.toList()); for (UserRole userRole : userRoles) { if (crpAdmins.isEmpty()) { crpAdmins += userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } else { crpAdmins += ", " + userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } } message.append(this.getText("email.newUser.part1", new String[] { this.getText("email.newUser.listRoles"), config.getBaseUrl(), user.getEmail(), password, this.getText("email.support", new String[] { crpAdmins }) })); message.append(this.getText("email.bye")); Map<String, Object> mapUser = new HashMap<>(); mapUser.put("user", user); mapUser.put("password", password); this.getUsersToActive().add(mapUser); // Send UserManual.pdf String contentType = "application/pdf"; String fileName = "Introduction_To_MARLO_v2.2.pdf"; byte[] buffer = null; InputStream inputStream = null; try { inputStream = this.getClass().getResourceAsStream("/manual/Introduction_To_MARLO_v2.2.pdf"); buffer = readFully(inputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } if (buffer != null && fileName != null && contentType != null) { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), buffer, contentType, fileName, true); } else { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), null, null, null, true); } } } }
From source file:org.cgiar.ccafs.marlo.utils.SendEmails.java
private static void notifyNewUserCreated(User user) { if (user != null && user.getId() != null) { user = userDAO.getUser(user.getId()); if (!user.isActive()) { /**//from w w w . j a v a2s . c om * So inactive users are being set to active once they are notified???? */ user.setActive(true); // user = userDAO.saveUser(user); String toEmail = user.getEmail(); String ccEmail = ""; String bbcEmails = action.getConfig().getEmailNotification(); String subject = action.getText("email.newUser.subject", new String[] { user.getFirstName() }); // Setting the password String password = action.getText("email.outlookPassword"); if (!user.isCgiarUser()) { // Generating a random password. password = RandomStringUtils.randomNumeric(6); } // Building the Email message: StringBuilder message = new StringBuilder(); message.append(action.getText("email.dear", new String[] { user.getFirstName() })); // get CRPAdmin contacts String crpAdmins = ""; long adminRol = Long.parseLong((String) action.getSession().get(APConstants.CRP_ADMIN_ROLE)); Role roleAdmin = roleDAO.find(adminRol); List<UserRole> userRoles = roleAdmin.getUserRoles().stream() .filter(ur -> ur.getUser() != null && ur.getUser().isActive()).collect(Collectors.toList()); for (UserRole userRole : userRoles) { if (crpAdmins.isEmpty()) { crpAdmins += userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } else { crpAdmins += ", " + userRole.getUser().getComposedCompleteName() + " (" + userRole.getUser().getEmail() + ")"; } } message.append(action.getText("email.newUser.part1", new String[] { action.getText("email.newUser.listRoles"), action.getConfig().getBaseUrl(), user.getEmail(), password, action.getText("email.support", new String[] { crpAdmins }) })); // message.append(action); Map<String, Object> mapUser = new HashMap<>(); mapUser.put("user", user); mapUser.put("password", password); action.getUsersToActive().add(mapUser); usersEmail.add(user.getEmail()); users.add(user); // Send UserManual.pdf String contentType = "application/pdf"; String fileName = "Introduction_To_MARLO_v2.2.pdf"; byte[] buffer = null; InputStream inputStream = null; try { inputStream = action.getClass().getResourceAsStream("/manual/Introduction_To_MARLO_v2.2.pdf"); buffer = readFully(inputStream); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (buffer != null && fileName != null && contentType != null) { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), buffer, contentType, fileName, true); } else { sendMail.send(toEmail, ccEmail, bbcEmails, subject, message.toString(), null, null, null, true); } } } }
From source file:org.codelabor.system.remoting.strategies.TransactionIdStrategy.java
public String getProcessId() { return RandomStringUtils.randomNumeric(8); }
From source file:org.craftercms.studio.controller.services.rest.AbstractControllerTest.java
protected Version createVersionMock() { Version version = new Version(); version.setLabel(RandomStringUtils.randomNumeric(1) + "." + RandomStringUtils.randomNumeric(2)); version.setComment(RandomStringUtils.randomAlphabetic(100)); return version; }
From source file:org.craftercms.studio.impl.AbstractManagerTest.java
protected DeploymentChannel createDeploymentChannelMock() { DeploymentChannel channel = new DeploymentChannel(); channel.setVersionUrl(RandomStringUtils.randomAlphabetic(150)); channel.setType(RandomStringUtils.randomAlphabetic(10)); channel.setTarget(RandomStringUtils.randomAlphanumeric(20)); channel.setStatusUrl(RandomStringUtils.randomAlphabetic(150)); channel.setDisabled(false);//from w w w. j a va 2s .co m channel.setId(UUID.randomUUID().toString()); channel.setName(RandomStringUtils.randomAlphabetic(15)); channel.setExcludePatterns(createStringListMock()); channel.setIncludePatterns(createStringListMock()); channel.setHost(RandomStringUtils.randomAlphabetic(10)); channel.setPort(RandomStringUtils.randomNumeric(4)); channel.setPublishingUrl(RandomStringUtils.randomAlphabetic(150)); channel.setPublishMetadata(false); return channel; }
From source file:org.ejbca.core.model.ca.caadmin.CVCCA.java
/** * @see CA#createRequest(Collection, String, Certificate, int) *//* ww w .j a v a2 s . c o m*/ public byte[] createRequest(Collection<DEREncodable> attributes, String signAlg, Certificate cacert, int signatureKeyPurpose) throws CATokenOfflineException { if (log.isTraceEnabled()) { log.trace(">createRequest: " + signAlg + ", " + CertTools.getSubjectDN(cacert) + ", " + signatureKeyPurpose); } byte[] ret = null; // Create a CVC request. // No outer signature on this self signed request KeyPair keyPair; try { CATokenContainer catoken = getCAToken(); keyPair = new KeyPair(catoken.getPublicKey(signatureKeyPurpose), catoken.getPrivateKey(signatureKeyPurpose)); if (keyPair == null) { throw new IllegalArgumentException( "Keys for key purpose " + signatureKeyPurpose + " does not exist."); } String subject = getCAInfo().getSubjectDN(); String country = CertTools.getPartFromDN(subject, "C"); String mnemonic = CertTools.getPartFromDN(subject, "CN"); String seq = getCAToken().getCATokenInfo().getKeySequence(); if (signatureKeyPurpose == SecConst.CAKEYPURPOSE_CERTSIGN_NEXT) { // See if we have a next sequence to put in the holder reference instead of the current one, // since we are using the next key we should use the next sequence String propdata = catoken.getCATokenInfo().getProperties(); Properties prop = new Properties(); if (propdata != null) { prop.load(new ByteArrayInputStream(propdata.getBytes())); } String nextSequence = (String) prop.get(ICAToken.NEXT_SEQUENCE_PROPERTY); // Only use next sequence if we also use previous key if (nextSequence != null) { seq = nextSequence; log.debug("Using next sequence in holderRef: " + seq); } else { log.debug( "Using current sequence in holderRef, although we are using the next key...no next sequence was found: " + seq); } } if (seq == null) { log.info("No sequence found in ca token info, using random 5 number sequence."); seq = RandomStringUtils.randomNumeric(5); } if (seq.length() > 5) { log.info("Sequence " + seq + " is too long, only using first 5."); seq = seq.substring(0, 4); } if (seq.length() < 5) { log.info("Sequence " + seq + " is too short, padding with zeroes."); for (int i = seq.length(); i < 5; i++) { seq = "0" + seq; } } HolderReferenceField holderRef = new HolderReferenceField(country, mnemonic, seq); CAReferenceField caRef = null; if (cacert != null) { if (cacert instanceof CardVerifiableCertificate) { CardVerifiableCertificate cvcacert = (CardVerifiableCertificate) cacert; try { HolderReferenceField href = cvcacert.getCVCertificate().getCertificateBody() .getHolderReference(); caRef = new CAReferenceField(href.getCountry(), href.getMnemonic(), href.getSequence()); log.debug("Using caRef from the CA certificate: " + caRef.getConcatenated()); } catch (NoSuchFieldException e) { log.debug("CA certificate does not contain a Holder reference to use as CARef in request."); } } else { log.debug("CA certificate is not a CardVerifiableCertificate."); } } else { caRef = new CAReferenceField(holderRef.getCountry(), holderRef.getMnemonic(), holderRef.getSequence()); log.debug("No CA cert, using caRef from the holder itself: " + caRef.getConcatenated()); } log.debug("Creating request with signature alg: " + signAlg + ", using provider " + catoken.getProvider()); CVCertificate request = CertificateGenerator.createRequest(keyPair, signAlg, caRef, holderRef, catoken.getProvider()); ret = request.getDEREncoded(); } catch (IllegalKeyStoreException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (NoSuchProviderException e) { throw new RuntimeException(e); } catch (SignatureException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (ConstructionException e) { throw new RuntimeException(e); } log.trace("<createRequest"); return ret; }