Example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric

List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric.

Prototype

public static String randomAlphanumeric(int count) 

Source Link

Document

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters.

Usage

From source file:com.duroty.application.open.manager.OpenManager.java

/**
 * DOCUMENT ME!/*from  w w  w .  j a v a2 s. com*/
 *
 * @param hsession DOCUMENT ME!
 * @param msession DOCUMENT ME!
 * @param userObj DOCUMENT ME!
 *
 * @throws Exception DOCUMENT ME!
 * @throws MailException DOCUMENT ME!
 */
public void register(org.hibernate.Session hsession, Session msession, UserObj userObj,
        String defaultEmailDomain) throws Exception {
    try {
        Users users = new Users();
        users.setUseActive(false);
        users.setUseEmail(userObj.getEmail());
        users.setUseLanguage(userObj.getLanguage());
        users.setUseName(userObj.getName());
        users.setUsePassword(userObj.getPassword());
        users.setUseRegisterDate(new Date());
        users.setUseUsername(userObj.getUsername());

        hsession.save(users);
        hsession.flush();

        MailPreferences mailPreferences = new MailPreferences();
        mailPreferences.setUsers(users);
        mailPreferences.setMaprHtmlMessage(true);
        mailPreferences.setMaprMessagesByPage(20);
        mailPreferences.setMaprQuotaSize(0);
        mailPreferences.setMaprSignature("--\n" + userObj.getName());
        mailPreferences.setMaprSpamTolerance(100);
        mailPreferences.setMaprVacationActive(false);

        hsession.save(mailPreferences);
        hsession.flush();

        Identity identity = new Identity();
        identity.setIdeActive(true);
        identity.setIdeCode(RandomStringUtils.randomAlphanumeric(25));
        identity.setIdeDefault(true);
        identity.setIdeEmail(userObj.getUsername() + "@" + defaultEmailDomain);
        identity.setIdeName(userObj.getName());
        identity.setIdeReplyTo(userObj.getUsername() + "@" + defaultEmailDomain);
        identity.setUsers(users);

        hsession.save(identity);
        hsession.flush();

        InternetAddress from = new InternetAddress(userObj.getEmail(), userObj.getName());

        Criteria crit = hsession.createCriteria(Roles.class);
        crit.add(Restrictions.eq("rolName", "admin"));

        Roles role = (Roles) crit.uniqueResult();

        InternetAddress[] to = new InternetAddress[role.getUserRoles().size()];
        Iterator it = role.getUserRoles().iterator();
        int i = 0;

        while (it.hasNext()) {
            UserRole userRole = (UserRole) it.next();
            Users aux = userRole.getId().getUsers();
            Criteria criteria = hsession.createCriteria(Identity.class);
            criteria.add(Restrictions.eq("ideDefault", new Boolean(true)));
            criteria.add(Restrictions.eq("ideActive", new Boolean(true)));
            criteria.add(Restrictions.eq("users", aux));

            Identity id = (Identity) criteria.uniqueResult();

            to[i] = new InternetAddress(id.getIdeEmail(), id.getIdeName());
            i++;
        }

        notifyToAdmins(msession, from, to, userObj.getUsername() + " (" + userObj.getName() + ")");
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.LDAPUserManagerTest.java

@Test
public void modifyUserPassword() {
    try {/*  w  w w. j ava2s .co m*/
        Assert.assertTrue(
                manager.modifyUserPassword(LDAPUserManagerTest.GUID, RandomStringUtils.randomAlphanumeric(64)));
    } catch (UserManagementException umx) {
        Assert.fail(umx.getMessage());
    }
}

From source file:fr.xebia.demo.amazon.aws.AmazonAwsIamAccountCreator.java

/**
 * Create an Amazon IAM account with a password, a secret key and member of
 * "Admins". The password, access key and secret key are sent by email.
 * /*from  w  w w. java 2s.c o  m*/
 * @param userName
 *            valid email used as userName of the created account.
 */
public void createUsers(String userName) {

    CreateUserRequest createUserRequest = new CreateUserRequest(userName);
    CreateUserResult createUserResult = iam.createUser(createUserRequest);
    User user = createUserResult.getUser();

    String password = RandomStringUtils.randomAlphanumeric(8);

    iam.createLoginProfile(new CreateLoginProfileRequest(user.getUserName(), password));
    iam.addUserToGroup(new AddUserToGroupRequest("Admins", user.getUserName()));
    CreateAccessKeyResult createAccessKeyResult = iam
            .createAccessKey(new CreateAccessKeyRequest().withUserName(user.getUserName()));
    AccessKey accessKey = createAccessKeyResult.getAccessKey();

    System.out.println("CREATED userName=" + user.getUserName() + "\tpassword=" + password + "\taccessKeyId="
            + accessKey.getAccessKeyId() + "\tsecretAccessKey=" + accessKey.getSecretAccessKey());

    String subject = "Xebia France Amazon EC2 Credentials";

    String body = "Hello,\n";
    body += "\n";
    body += "Here are the credentials to connect to Xebia Amazon AWS/EC2 training infrastructure:\n";
    body += "\n";
    body += "User Name: " + user.getUserName() + "\n";
    body += "Password: " + password + "\n";
    body += "Access Key Id: " + accessKey.getAccessKeyId() + "\n";
    body += "Secret Access Key: " + accessKey.getSecretAccessKey() + "\n";
    body += "\n";
    body += "The authentication page is https://xebia-france.signin.aws.amazon.com/console";
    body += "\n";
    body += "Don't hesitate to connect to Amazon AWS, to play with it but please DO NOT FORGET TO STOP INSTANCES OR IF POSSIBLE TERMINATE THEM AFTER USING THEM.\n";
    body += "Letting instances started would cost unnecessary money to Xebia.\n";
    body += "\n";
    body += "\n";
    body += "Thanks,\n";
    body += "\n";
    body += "Cyrille";
    try {
        sendEmail(subject, body, "cyrille@cyrilleleclerc.com", user.getUserName());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.spotify.docker.client.DockerConfigReaderTest.java

@Test
public void testFromDockerConfig_MissingConfigFile() throws Exception {
    final Path randomPath = Paths.get(RandomStringUtils.randomAlphanumeric(16) + ".json");
    expectedException.expect(FileNotFoundException.class);
    reader.anyRegistryAuth(randomPath);/*from   w w w  . j ava 2 s . com*/
}

From source file:de.hybris.platform.btgcockpit.service.BTGCockpitServiceTest.java

@Before
public void setUp() throws Exception {
    LOG.info("Creating btg test data ..");
    initApplicationContext();// w w w  .  j a v  a  2s.co  m
    cockpitTypeService = (TypeService) applicationContex.getBean("cockpitTypeService");

    createNumberSeries(BTGSegmentModel._TYPECODE);
    createNumberSeries(BTGRuleModel._TYPECODE);
    createNumberSeries(BTGAssignToGroupDefinitionModel._TYPECODE);
    createNumberSeries(BTGOutputActionDefinitionModel._TYPECODE);
    createNumberSeries(AbstractRestrictionModel._TYPECODE);
    createNumberSeries(AbstractPageModel._TYPECODE);

    JaloSession.getCurrentSession().setUser(UserManager.getInstance().getAdminEmployee());
    final long startTime = System.currentTimeMillis();
    new CoreBasicDataCreator().createEssentialData(Collections.EMPTY_MAP, null);
    Cms2Manager.getInstance().createEssentialData(Collections.EMPTY_MAP, null);

    importCsv("/test/btgCockpitTestData.csv", "utf-8");
    LOG.info("Finished creating btg test data " + (System.currentTimeMillis() - startTime) + "ms");

    btgCockpitService = (BTGCockpitService) applicationContex.getBean("btgCockpitService");

    final CatalogVersionModel catalogVersionModel = getSampleCatalogVersion();
    segmentModel = new BTGSegmentModel();
    segmentModel.setCatalogVersion(catalogVersionModel);
    segmentModel.setName("BTG Sample Segment");
    segmentModel.setUid(RandomStringUtils.randomAlphanumeric(10));
    modelService.save(segmentModel);
    cmsAdminSiteService.setActiveCatalogVersion(catalogVersionModel);
    componentModel = cmsComponentService.getAbstractCMSComponent("test_component1",
            Collections.singletonList(catalogVersionModel));
    altComponentModel = cmsComponentService.getAbstractCMSComponent("test_component2",
            Collections.singletonList(catalogVersionModel));
    catalogService.setSessionCatalogVersions(Collections.singleton(catalogVersionModel));
    pageModel = cmsPageService.getPageByLabelOrId("test_homepage_default");

}

From source file:com.xtructure.xutil.valid.UTestValidateUtils.java

public void validateBehavesAsExpected() {
    String objectName = RandomStringUtils.randomAlphanumeric(10);
    Object object = new Object();
    DummyValidationStrategy vs = new DummyValidationStrategy();
    validate(objectName, object, vs);/*w ww  . j  a  va  2  s .com*/
    if (vs.calls != 1 || vs.method != "validateOS" || vs.object != object || vs.objectName != objectName
            || vs.predicate != null) {
        throw new AssertionError();
    }
}

From source file:fm.last.moji.integration.MojiFileIT.java

@Test(expected = UnknownStorageClassException.class)
public void updateStorageClassToUnknown() throws IOException {
    MojiFile fileToUpdate = getFile(newKey("updateStorageClassToUnknown"));
    fileToUpdate.modifyStorageClass("madeup" + RandomStringUtils.randomAlphanumeric(8));
}

From source file:com.edgenius.wiki.SpaceSetting.java

/**
 * @param password// w w  w.j av  a  2  s  .co  m
 * @return
 * @throws UnsupportedEncodingException 
 * @throws InvalidAlgorithmParameterException 
 * @throws BadPaddingException 
 * @throws IllegalBlockSizeException 
 * @throws NoSuchPaddingException 
 * @throws NoSuchAlgorithmException 
 * @throws InvalidKeyException 
 */

public String createSecurityKey(String plainPassword)
        throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException,
        BadPaddingException, InvalidAlgorithmParameterException, UnsupportedEncodingException {
    if (StringUtils.isBlank(plainPassword))
        return null;

    String secValue = CryptUtil.genSecurityKey(plainPassword);

    //save this security key into list
    Map<String, String> securityKeys = this.getSecurityKeys();
    if (securityKeys == null) {
        securityKeys = new HashMap<String, String>();
        this.setSecurityKeys(securityKeys);
    }
    String secKey;
    do {
        //ensure this security key is brand new in security key list
        secKey = RandomStringUtils.randomAlphanumeric(WikiConstants.UUID_KEY_SIZE).toLowerCase();
    } while (securityKeys.get(secKey) != null);

    securityKeys.put(secKey, secValue);

    return secKey;
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManagerTest.java

@Test
public void modifyUserSecurity() {
    try {//  ww  w  .j  a  va 2s  . c  o  m
        Assert.assertTrue(manager.modifyUserSecurity(SQLUserManagerTest.GUID,
                new ArrayList<String>(Arrays.asList(RandomStringUtils.randomAlphanumeric(64),
                        RandomStringUtils.randomAlphanumeric(64), RandomStringUtils.randomAlphanumeric(64),
                        RandomStringUtils.randomAlphanumeric(64)))));
    } catch (UserManagementException umx) {
        Assert.fail(umx.getMessage());
    }
}

From source file:com.google.code.ssm.test.dao.TestDAOImpl.java

@Override
@ReadThroughMultiCache(namespace = CacheConst.DELTA, expiration = 1000)
public List<String> getRandomStrings(@ParameterValueKeyProvider final List<Long> keys) {
    try {/*  w  ww  .ja v  a 2 s .co  m*/
        Thread.sleep(500);
    } catch (InterruptedException ex) {
    }
    final String series = RandomStringUtils.randomAlphabetic(6);
    final List<String> results = new ArrayList<String>(keys.size());
    for (final Long key : keys) {
        results.add(series + "-" + key.toString() + "-"
                + RandomStringUtils.randomAlphanumeric(25 + RandomUtils.nextInt(30)));
    }
    return results;
}