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:org.alfresco.repo.security.authentication.BasicPasswordGenerator.java

/**
 * Returns a generated password
 * 
 * @return generated password
 */
public String generatePassword() {
    return RandomStringUtils.randomAlphanumeric(passwordLength);
}

From source file:org.alfresco.repo.web.scripts.invite.InviteServiceTest.java

private JSONObject startInvite(String inviteeFirstName, String inviteeLastName, String inviteeSiteRole,
        String siteShortName, int expectedStatus) throws Exception {
    String inviteeEmail = INVITEE_EMAIL_PREFIX + RandomStringUtils.randomAlphanumeric(6) + "@"
            + INVITEE_EMAIL_DOMAIN;/*from w  w  w.ja v  a2  s .  c  o m*/

    return startInvite(inviteeFirstName, inviteeLastName, inviteeEmail, inviteeSiteRole, siteShortName,
            expectedStatus);
}

From source file:org.alfresco.repo.web.scripts.invite.InviteServiceTest.java

public void testStartInviteForSameInviteeButTwoDifferentSites() throws Exception {
    final String inviteeUsername = INVITEE_FIRSTNAME + "_" + INVITEE_LASTNAME;
    final String inviteeEmail = INVITEE_EMAIL_PREFIX + RandomStringUtils.randomAlphanumeric(6) + "@"
            + INVITEE_EMAIL_DOMAIN;//from  w w  w.j  av a2 s.c om

    // Create person
    AuthenticationUtil.runAs(new RunAsWork<Object>() {
        public Object doWork() throws Exception {
            createPerson(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeUsername, inviteeEmail);
            return null;
        }

    }, AuthenticationUtil.getSystemUserName());

    JSONObject result = startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE,
            SITE_SHORT_NAME_INVITE_1, Status.STATUS_OK);

    startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_2,
            Status.STATUS_OK);
}

From source file:org.alfresco.repo.web.scripts.invite.InviteServiceTest.java

public void testInviteeResourcesNotDeletedUponRejectWhenInvitesPending() throws Exception {
    // Test only applies to legacy invite workflow
    this.invitationServiceImpl.setNominatedInvitationWorkflowId(
            WorkflowModelNominatedInvitation.WORKFLOW_DEFINITION_NAME_ACTIVITI_INVITE);

    // Create invitee person
    final String inviteeEmail = INVITEE_EMAIL_PREFIX + RandomStringUtils.randomAlphanumeric(6) + "@"
            + INVITEE_EMAIL_DOMAIN;/*from  ww w  .  ja  v  a 2  s. c o  m*/
    AuthenticationUtil.runAs(new RunAsWork<Object>() {
        public Object doWork() throws Exception {
            createPerson(INVITEE_FIRSTNAME, INVITEE_LASTNAME, INVITEE_FIRSTNAME + "_" + INVITEE_LASTNAME,
                    inviteeEmail);
            return null;
        }
    }, AuthenticationUtil.getSystemUserName());

    // inviter invites invitee to site 1
    JSONObject result = startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE,
            SITE_SHORT_NAME_INVITE_1, Status.STATUS_OK);

    // get hold of properties of started invite
    String invite1Id = result.getString("inviteId");
    String invite1Ticket = result.getString("inviteTicket");
    final String inviteeUserName = result.getString("inviteeUserName");

    // inviter invites invitee to site 2
    startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_2,
            Status.STATUS_OK);

    rejectInvite(invite1Id, invite1Ticket, Status.STATUS_OK);

    boolean inviteeUserExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>() {
        public Boolean doWork() throws Exception {
            RetryingTransactionHelper tranHelper = transactionService.getRetryingTransactionHelper();
            Boolean result = tranHelper.doInTransaction(new RetryingTransactionCallback<Boolean>() {
                public Boolean execute() throws Throwable {
                    Boolean result = mutableAuthenticationDao.userExists(inviteeUserName);
                    return result;
                }
            });

            return result;
        }
    }, AuthenticationUtil.getSystemUserName());

    // test that the invitee's user account still exists (has not been deleted
    assertEquals(true, inviteeUserExists);

    boolean inviteePersonExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>() {
        public Boolean doWork() throws Exception {
            Boolean result = personService.personExists(inviteeUserName);

            return result;
        }
    }, AuthenticationUtil.getSystemUserName());

    assertEquals(true, inviteePersonExists);

    // Reset back to default
    this.invitationServiceImpl.setNominatedInvitationWorkflowId(
            WorkflowModelNominatedInvitation.WORKFLOW_DEFINITION_NAME_ACTIVITI_ADD_DIRECT);
}

From source file:org.alfresco.sync.DesktopSyncTest.java

/**
 * private method which will create a site and upload just one file so that as part of initial sync process
 * we can find out it was successful/*from  www . j  a va2  s  .  c  om*/
 */
private void initialSiteSetUp() {
    try {
        File initialShareFile = getRandomFile("initialShareFile", "txt");
        siteName = "desktopsyncsite" + RandomStringUtils.randomAlphanumeric(2);
        shareLogin.loginToShare(drone, userInfo, shareUrl);
        share.createSite(drone, siteName, siteName, "public");
        logger.info("site created - successful" + siteName);
        share.openSitesDocumentLibrary(drone, siteName);
        initialShareFile = share.newFile(initialShareFile.getName(), "Initial file uploaded in share");
        share.uploadFile(drone, initialShareFile);
        shareLogin.logout(drone);
    } catch (Exception e) {
        logger.error("Failed to create file in share :" + this.getClass(), e);
    }
}

From source file:org.alfresco.sync.DesktopSyncTest.java

/**
 * Generate a new random filename using prefix and extension
 * //from  w  w  w .  j a va  2  s  . co m
 * @param prefix
 * @param extension
 * @return a new random File
 */
protected File getRandomFile(String prefix, String extension) {
    return new File(String.format("%s-%s.%s", prefix, RandomStringUtils.randomAlphanumeric(5), extension));
}

From source file:org.alfresco.sync.DesktopSyncTest.java

/**
 * Returns a random values using the prefix provided
 * //from   www .  j  a  va  2 s .co m
 * @param prefix
 * @return
 */
protected String getRandomValue(String prefix) {
    return String.format("%s-%s", prefix, RandomStringUtils.randomAlphanumeric(5));
}

From source file:org.apache.airavata.credential.store.credential.impl.ssh.SSHCredentialGenerator.java

private String generateRandomString() {
    return RandomStringUtils.randomAlphanumeric(16);
}

From source file:org.apache.ambari.server.configuration.Configuration.java

/**
 * This constructor is called from default constructor and
 * also from most tests./*from  ww  w.  j ava  2  s  . c o m*/
 * @param properties properties to use for testing and in production using
 * the Conf object.
 */
public Configuration(Properties properties) {
    this.properties = properties;

    configsMap = new HashMap<String, String>();
    configsMap.put(AMBARI_PYTHON_WRAP_KEY,
            properties.getProperty(AMBARI_PYTHON_WRAP_KEY, AMBARI_PYTHON_WRAP_DEFAULT));
    configsMap.put(SRVR_TWO_WAY_SSL_KEY,
            properties.getProperty(SRVR_TWO_WAY_SSL_KEY, SRVR_TWO_WAY_SSL_DEFAULT));
    configsMap.put(SRVR_TWO_WAY_SSL_PORT_KEY,
            properties.getProperty(SRVR_TWO_WAY_SSL_PORT_KEY, SRVR_TWO_WAY_SSL_PORT_DEFAULT));
    configsMap.put(SRVR_ONE_WAY_SSL_PORT_KEY,
            properties.getProperty(SRVR_ONE_WAY_SSL_PORT_KEY, SRVR_ONE_WAY_SSL_PORT_DEFAULT));
    configsMap.put(SRVR_KSTR_DIR_KEY, properties.getProperty(SRVR_KSTR_DIR_KEY, SRVR_KSTR_DIR_DEFAULT));
    configsMap.put(SRVR_CRT_NAME_KEY, properties.getProperty(SRVR_CRT_NAME_KEY, SRVR_CRT_NAME_DEFAULT));
    configsMap.put(SRVR_KEY_NAME_KEY, properties.getProperty(SRVR_KEY_NAME_KEY, SRVR_KEY_NAME_DEFAULT));
    configsMap.put(SRVR_CSR_NAME_KEY, properties.getProperty(SRVR_CSR_NAME_KEY, SRVR_CSR_NAME_DEFAULT));
    configsMap.put(KSTR_NAME_KEY, properties.getProperty(KSTR_NAME_KEY, KSTR_NAME_DEFAULT));
    configsMap.put(SRVR_CRT_PASS_FILE_KEY,
            properties.getProperty(SRVR_CRT_PASS_FILE_KEY, SRVR_CRT_PASS_FILE_DEFAULT));
    configsMap.put(PASSPHRASE_ENV_KEY, properties.getProperty(PASSPHRASE_ENV_KEY, PASSPHRASE_ENV_DEFAULT));
    configsMap.put(PASSPHRASE_KEY, System.getenv(configsMap.get(PASSPHRASE_ENV_KEY)));
    configsMap.put(RESOURCES_DIR_KEY, properties.getProperty(RESOURCES_DIR_KEY, RESOURCES_DIR_DEFAULT));
    configsMap.put(SRVR_CRT_PASS_LEN_KEY,
            properties.getProperty(SRVR_CRT_PASS_LEN_KEY, SRVR_CRT_PASS_LEN_DEFAULT));
    configsMap.put(SRVR_DISABLED_CIPHERS,
            properties.getProperty(SRVR_DISABLED_CIPHERS, SRVR_DISABLED_CIPHERS_DEFAULT));
    configsMap.put(SRVR_DISABLED_PROTOCOLS,
            properties.getProperty(SRVR_DISABLED_PROTOCOLS, SRVR_DISABLED_PROTOCOLS_DEFAULT));

    configsMap.put(CLIENT_API_SSL_KSTR_DIR_NAME_KEY,
            properties.getProperty(CLIENT_API_SSL_KSTR_DIR_NAME_KEY, configsMap.get(SRVR_KSTR_DIR_KEY)));
    configsMap.put(CLIENT_API_SSL_KSTR_NAME_KEY,
            properties.getProperty(CLIENT_API_SSL_KSTR_NAME_KEY, CLIENT_API_SSL_KSTR_NAME_DEFAULT));
    configsMap.put(CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY, properties
            .getProperty(CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY, CLIENT_API_SSL_CRT_PASS_FILE_NAME_DEFAULT));
    configsMap.put(CLIENT_API_SSL_KEY_NAME_KEY,
            properties.getProperty(CLIENT_API_SSL_KEY_NAME_KEY, CLIENT_API_SSL_KEY_NAME_DEFAULT));
    configsMap.put(CLIENT_API_SSL_CRT_NAME_KEY,
            properties.getProperty(CLIENT_API_SSL_CRT_NAME_KEY, CLIENT_API_SSL_CRT_NAME_DEFAULT));
    configsMap.put(JAVA_HOME_KEY, properties.getProperty(JAVA_HOME_KEY));
    configsMap.put(PARALLEL_STAGE_EXECUTION_KEY,
            properties.getProperty(PARALLEL_STAGE_EXECUTION_KEY, PARALLEL_STAGE_EXECUTION_DEFAULT));
    configsMap.put(SERVER_TMP_DIR_KEY, properties.getProperty(SERVER_TMP_DIR_KEY, SERVER_TMP_DIR_DEFAULT));
    configsMap.put(EXTERNAL_SCRIPT_TIMEOUT_KEY,
            properties.getProperty(EXTERNAL_SCRIPT_TIMEOUT_KEY, EXTERNAL_SCRIPT_TIMEOUT_DEFAULT));

    configsMap.put(SHARED_RESOURCES_DIR_KEY,
            properties.getProperty(SHARED_RESOURCES_DIR_KEY, SHARED_RESOURCES_DIR_DEFAULT));

    configsMap.put(KDC_PORT_KEY, properties.getProperty(KDC_PORT_KEY, KDC_PORT_KEY_DEFAULT));

    File passFile = new File(
            configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator + configsMap.get(SRVR_CRT_PASS_FILE_KEY));
    String password = null;

    if (!passFile.exists()) {
        LOG.info("Generation of file with password");
        try {
            password = RandomStringUtils
                    .randomAlphanumeric(Integer.parseInt(configsMap.get(SRVR_CRT_PASS_LEN_KEY)));
            FileUtils.writeStringToFile(passFile, password);
            ShellCommandUtil.setUnixFilePermissions(ShellCommandUtil.MASK_OWNER_ONLY_RW,
                    passFile.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("Error reading certificate password from file");
        }
    } else {
        LOG.info("Reading password from existing file");
        try {
            password = FileUtils.readFileToString(passFile);
            password = password.replaceAll("\\p{Cntrl}", "");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    configsMap.put(SRVR_CRT_PASS_KEY, password);

    if (getApiSSLAuthentication()) {
        LOG.info("API SSL Authentication is turned on.");
        File httpsPassFile = new File(configsMap.get(CLIENT_API_SSL_KSTR_DIR_NAME_KEY) + File.separator
                + configsMap.get(CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY));

        if (httpsPassFile.exists()) {
            LOG.info("Reading password from existing file");
            try {
                password = FileUtils.readFileToString(httpsPassFile);
                password = password.replaceAll("\\p{Cntrl}", "");
            } catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException(
                        "Error reading certificate password from" + " file " + httpsPassFile.getAbsolutePath());
            }
        } else {
            LOG.error("There is no keystore for https UI connection.");
            LOG.error("Run \"tbds-server setup-https\" or set " + Configuration.API_USE_SSL + " = false.");
            throw new RuntimeException(
                    "Error reading certificate password from " + "file " + httpsPassFile.getAbsolutePath());

        }

        configsMap.put(CLIENT_API_SSL_CRT_PASS_KEY, password);
    }

    loadSSLParams();
}

From source file:org.apache.asterix.test.common.TestTupleGenerator.java

public ITupleReference next() throws HyracksDataException {
    if (reuseObject) {
        for (int i = 0; i < types.length; i++) {
            fields[i].reset();/* ww w .ja  v a 2 s . com*/
        }
    } else {
        this.fields = new GrowableArray[types.length];
        for (int i = 0; i < types.length; i++) {
            fields[i] = new GrowableArray();
        }
        tuple = new TestTupleReference(fields);
    }
    for (int i = 0; i < types.length; i++) {
        FieldType type = types[i];
        switch (type) {
        case Boolean:
            Boolean aBoolean = random.nextBoolean();
            BooleanSerializerDeserializer.INSTANCE.serialize(aBoolean, fields[i].getDataOutput());
            break;
        case Double:
            double aDouble = random.nextDouble();
            DoubleSerializerDeserializer.INSTANCE.serialize(aDouble, fields[i].getDataOutput());
            break;
        case Integer64:
            long aLong = random.nextLong();
            Integer64SerializerDeserializer.INSTANCE.serialize(aLong, fields[i].getDataOutput());
            break;
        case String:
            String aString = RandomStringUtils.randomAlphanumeric(stringFieldSizes);
            stringSerde.serialize(aString, fields[i].getDataOutput());
            break;
        default:
            break;
        }
    }
    return tuple;
}