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.cws.esolutions.core.processors.impl.ServiceMessagingProcessorImpl.java

/**
 * @see com.cws.esolutions.core.processors.interfaces.IWebMessagingProcessor#addNewMessage(com.cws.esolutions.core.processors.dto.MessagingRequest)
 *//*from   www. j  a va 2 s .  co m*/
public MessagingResponse addNewMessage(final MessagingRequest request) throws MessagingServiceException {
    final String methodName = IWebMessagingProcessor.CNAME
            + "#addNewMessage(final MessagingRequest request) throws MessagingServiceException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("MessagingRequest: {}", request);
    }

    MessagingResponse response = new MessagingResponse();

    final UserAccount userAccount = request.getUserAccount();
    final RequestHostInfo reqInfo = request.getRequestInfo();
    final ServiceMessage message = request.getServiceMessage();

    if (DEBUG) {
        DEBUGGER.debug("UserAccount: {}", userAccount);
        DEBUGGER.debug("RequestHostInfo: {}", reqInfo);
        DEBUGGER.debug("ServiceMessage: {}", message);
    }

    try {
        String messageId = RandomStringUtils.randomAlphanumeric(appConfig.getMessageIdLength());

        if (DEBUG) {
            DEBUGGER.debug("messageId: {}", messageId);
        }

        List<Object> messageList = new ArrayList<Object>(Arrays.asList(messageId, message.getMessageTitle(),
                message.getMessageText(), userAccount.getGuid(), message.getIsActive(), message.isAlert(),
                message.getDoesExpire(), message.getExpiryDate()));

        // submit it
        boolean isSubmitted = webMessengerDAO.insertMessage(messageList);

        if (DEBUG) {
            DEBUGGER.debug("isSubmitted: {}", isSubmitted);
        }

        if (!(isSubmitted)) {
            response.setRequestStatus(CoreServicesStatus.FAILURE);
        } else {
            response.setRequestStatus(CoreServicesStatus.SUCCESS);
            response.setMessageId(messageId);
        }

        if (DEBUG) {
            DEBUGGER.debug("MessagingResponse: {}", response);
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);

        throw new MessagingServiceException(sqx.getMessage(), sqx);
    } finally {
        // audit
        try {
            AuditEntry auditEntry = new AuditEntry();
            auditEntry.setHostInfo(reqInfo);
            auditEntry.setAuditType(AuditType.ADDSVCMESSAGE);
            auditEntry.setUserAccount(userAccount);
            auditEntry.setAuthorized(Boolean.TRUE);
            auditEntry.setApplicationId(request.getApplicationId());
            auditEntry.setApplicationName(request.getApplicationName());

            if (DEBUG) {
                DEBUGGER.debug("AuditEntry: {}", auditEntry);
            }

            AuditRequest auditRequest = new AuditRequest();
            auditRequest.setAuditEntry(auditEntry);

            if (DEBUG) {
                DEBUGGER.debug("AuditRequest: {}", auditRequest);
            }

            auditor.auditRequest(auditRequest);
        } catch (AuditServiceException asx) {
            ERROR_RECORDER.error(asx.getMessage(), asx);
        }
    }

    return response;
}

From source file:it.unimi.di.big.mg4j.tool.URLMPHVirtualDocumentResolver.java

private static void makeUnique(final BloomFilter<Void> filter, final MutableString uri) {
    while (!filter.add(uri)) {
        LOGGER.debug("Duplicate URI " + uri);
        uri.append('/').append(RandomStringUtils.randomAlphanumeric(32));
    }//from   w  ww .ja v  a  2 s  .  c  o  m
}

From source file:models.JugUser.java

/**
 * An utility method to reset the user password.
 *///from w ww.  j  a  v  a  2  s  . c o m
public void changePassword() {
    this.password = RandomStringUtils.randomAlphanumeric(8);
    this.save();
}

From source file:com.highcharts.export.converter.SVGConverter.java

public String createUniqueFileName(String extension) throws IOException {
    return System.getProperty("java.io.tmpdir") + "/" + RandomStringUtils.randomAlphanumeric(8) + extension;
}

From source file:com.kixeye.chassis.scala.transport.serde.ScalaCaseClassTest.java

@Test
public void testBsonSerDe() throws Exception {
    final BsonJacksonMessageSerDe serDe = new BsonJacksonMessageSerDe();

    final TestObject obj = new TestObject(RandomStringUtils.randomAlphanumeric(64),
            new SomeOtherObject(RandomStringUtils.randomAlphanumeric(64)));

    final byte[] serializedObj = serDe.serialize(obj);

    dumpToLog(serDe, serializedObj);//w  w w  .j av  a  2  s  . c om

    final TestObject deserializedObj = serDe.deserialize(serializedObj, 0, serializedObj.length,
            TestObject.class);

    Assert.assertEquals(obj, deserializedObj);
}

From source file:com.streamsets.pipeline.stage.origin.jdbc.TestJdbcSource.java

@Before
public void setUp() throws SQLException {
    // Create a table in H2 and put some data in it for querying.
    connection = DriverManager.getConnection(h2ConnectionString, username, password);
    try (Statement statement = connection.createStatement()) {
        // Setup table
        statement.addBatch("CREATE SCHEMA IF NOT EXISTS TEST;");
        statement.addBatch("CREATE TABLE IF NOT EXISTS TEST.TEST_TABLE "
                + "(p_id INT NOT NULL, first_name VARCHAR(255), last_name VARCHAR(255), UNIQUE(p_id));");
        statement.addBatch("CREATE TABLE IF NOT EXISTS TEST.TEST_ARRAY "
                + "(p_id INT NOT NULL, non_scalar ARRAY, UNIQUE(p_id));");
        statement.addBatch("CREATE TABLE IF NOT EXISTS TEST.TEST_CLOB "
                + "(p_id INT NOT NULL, clob_col CLOB, UNIQUE(p_id));");
        // Add some data
        statement.addBatch("INSERT INTO TEST.TEST_TABLE VALUES (1, 'Adam', 'Kunicki')");
        statement.addBatch("INSERT INTO TEST.TEST_TABLE VALUES (2, 'Jon', 'Natkins')");
        statement.addBatch("INSERT INTO TEST.TEST_TABLE VALUES (3, 'Jon', 'Daulton')");
        statement.addBatch("INSERT INTO TEST.TEST_TABLE VALUES (4, 'Girish', 'Pancha')");
        statement.addBatch("INSERT INTO TEST.TEST_ARRAY VALUES (1, (1,2,3))");
        statement.addBatch("INSERT INTO TEST.TEST_CLOB VALUES  (1, 'short string for clob')");
        statement.addBatch("INSERT INTO TEST.TEST_CLOB VALUES  (2, 'long string for clob"
                + RandomStringUtils.randomAlphanumeric(CLOB_SIZE) + "')");

        statement.executeBatch();/*www .j a v  a 2s  . c o  m*/
    }
}

From source file:com.netscape.cmstools.client.ClientCertShowCLI.java

public void execute(String[] args) throws Exception {

    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("help")) {
        printHelp();/*  w w  w  .j ava 2s  .  com*/
        return;
    }

    String[] cmdArgs = cmd.getArgs();

    if (cmdArgs.length > 1) {
        throw new Exception("Too many arguments specified.");
    }

    if (cmdArgs.length == 0) {
        throw new Exception("Missing certificate nickname.");
    }

    MainCLI mainCLI = (MainCLI) parent.getParent();

    String nickname = cmdArgs[0];
    String certPath = cmd.getOptionValue("cert");
    String privateKeyPath = cmd.getOptionValue("private-key");
    String clientCertPath = cmd.getOptionValue("client-cert");
    String pkcs12Path = cmd.getOptionValue("pkcs12");
    String pkcs12Password = cmd.getOptionValue("pkcs12-password");

    File pkcs12File;

    if (pkcs12Path != null) {
        // exporting certificate to PKCS #12 file

        pkcs12File = new File(pkcs12Path);

        if (pkcs12Password == null) {
            throw new Exception("Missing PKCS #12 password");
        }

    } else if (clientCertPath != null || privateKeyPath != null) {
        // exporting private key to PEM file using temporary PKCS #12 file

        // prepare temporary PKCS #12 file
        pkcs12File = File.createTempFile("pki-client-cert-show-", ".p12");
        pkcs12File.deleteOnExit();

        // generate random password
        pkcs12Password = RandomStringUtils.randomAlphanumeric(16);

    } else {
        // displaying certificate info

        mainCLI.init();

        CryptoManager manager = CryptoManager.getInstance();
        X509Certificate cert = manager.findCertByNickname(nickname);

        if (certPath != null) {
            try (PrintWriter out = new PrintWriter(new FileWriter(certPath))) {
                out.println(Cert.HEADER);
                out.print(Utils.base64encode(cert.getEncoded(), true));
                out.println(Cert.FOOTER);
            }

        } else {
            ClientCLI.printCertInfo(cert);

        }
        return;
    }

    // store password into a temporary file
    File pkcs12PasswordFile = File.createTempFile("pki-client-cert-show-", ".pwd");
    pkcs12PasswordFile.deleteOnExit();

    try (PrintWriter out = new PrintWriter(new FileWriter(pkcs12PasswordFile))) {
        out.print(pkcs12Password);
    }

    if (verbose)
        System.out.println("Exporting certificate chain and private key to " + pkcs12File + ".");
    exportPKCS12(mainCLI.certDatabase.getAbsolutePath(), mainCLI.config.getNSSPassword(),
            pkcs12File.getAbsolutePath(), pkcs12PasswordFile.getAbsolutePath(), nickname);

    if (certPath != null) {
        if (verbose)
            System.out.println("Exporting certificate to " + certPath + ".");
        exportCertificate(pkcs12File.getAbsolutePath(), pkcs12PasswordFile.getAbsolutePath(), certPath);
    }

    if (privateKeyPath != null) {
        if (verbose)
            System.out.println("Exporting private key to " + privateKeyPath + ".");
        exportPrivateKey(pkcs12File.getAbsolutePath(), pkcs12PasswordFile.getAbsolutePath(), privateKeyPath);
    }

    if (clientCertPath != null) {
        if (verbose)
            System.out.println("Exporting client certificate and private key to " + clientCertPath + ".");
        exportClientCertificateAndPrivateKey(pkcs12File.getAbsolutePath(), pkcs12PasswordFile.getAbsolutePath(),
                clientCertPath);
    }
}

From source file:com.jslsolucoes.tagria.lib.tag.html.DetailTableTag.java

@Override
public void doTag() throws JspException, IOException {

    String body = TagUtil.getBody(getJspBody());

    Div detail = new Div();
    detail.add(Attribute.ID, TagUtil.getId());

    Textarea template = new Textarea();
    template.add(Attribute.CLASS, "hidden bs-detail-table-template");
    detail.add(template);/*from w  w w.ja va  2  s .co  m*/

    Div panel = new Div();
    panel.add(Attribute.CLASS, "panel panel-primary");

    if (!StringUtils.isEmpty(label)) {
        Div panelHead = new Div();
        panelHead.add(Attribute.CLASS, "panel-heading");
        H3 h3 = new H3();
        h3.add(Attribute.CLASS, "panel-title");
        h3.add(TagUtil.getLocalized(label, getJspContext()));
        panelHead.add(h3);
        panel.add(panelHead);
    }

    Div panelBody = new Div();
    panelBody.add(Attribute.CLASS, "panel-body");

    Div toolbar = new Div();
    Button button = new Button();
    button.add(Attribute.TYPE, "button");
    button.add(Attribute.CLASS, "btn btn-primary waves-effect waves-light bs-detail-table-plus");
    button.add(new Span().add(Attribute.CLASS, "glyphicon glyphicon-plus"));
    toolbar.add(button);
    panelBody.add(toolbar);

    Table table = new Table();
    table.add(Attribute.CLASS, "table table-striped table-hover bs-detail-table-table");

    Th th = new Th();
    this.ths.add(th);

    Thead thead = new Thead();
    Tr tr = new Tr();
    thead.add(tr);
    tr.add(this.ths);
    table.add(thead);

    Tbody tbody = new Tbody();

    if (!CollectionUtils.isEmpty(data)) {
        for (Object row : data) {
            getJspContext().setAttribute(var, row);
            Tr line = new Tr();
            line.add(TagUtil.getBody(getJspBody()));
            line.add(remove());
            tbody.add(line);
            iteration = RandomStringUtils.randomAlphanumeric(20);
        }
        getJspContext().setAttribute(var, null);
    } else {
        for (int i = 0; i < (atLeast > 0 ? atLeast : 1); i++) {
            Tr line = new Tr();
            line.add(body);
            line.add(remove());
            tbody.add(line);
            iteration = RandomStringUtils.randomAlphanumeric(20);
        }
    }

    table.add(tbody);

    panelBody.add(table);
    panel.add(panelBody);
    detail.add(panel);

    TagUtil.out(getJspContext(), detail);

    Script script = new Script();
    script.add(Attribute.TYPE, "text/javascript");
    script.add("$('#" + detail.get(Attribute.ID) + "').detail({ atLeast : " + atLeast + " , empty : " + empty
            + ", afterInsert : function (tr) { " + afterInsert + " } });");
    TagUtil.out(getJspContext(), script);

}

From source file:com.haulmont.cuba.gui.components.filter.condition.FtsCondition.java

protected String generateQueryKeyParamName() {
    return "__queryKey" + RandomStringUtils.randomAlphanumeric(6);
}

From source file:com.cws.esolutions.core.processors.impl.ServerManagementProcessorImplTest.java

@Test
public void addNewServerAsDmgr() {
    for (int x = 0; x < 3; x++) {
        String name = RandomStringUtils.randomAlphanumeric(8).toLowerCase();

        Service service = new Service();
        service.setGuid("1fe90f9d-0ead-4caf-92f6-a64be1dcc6aa");

        Server server = new Server();
        server.setOsName("CentOS");
        server.setDomainName("caspersbox.corp");
        server.setOperIpAddress("192.168.10.60");
        server.setOperHostName(name);//w w w  .j  a  v a 2 s  .c o m
        server.setMgmtIpAddress("192.168.10.160");
        server.setMgmtHostName(name + "-mgt");
        server.setBkIpAddress("172.16.10.60");
        server.setBkHostName(name + "-dmgr-bak");
        server.setNasIpAddress("172.15.10.61");
        server.setNasHostName(name + "-dmgr-nas");

        if (x == 0) {
            server.setServerRegion(ServiceRegion.DEV);
        } else if (x == 1) {
            server.setServerRegion(ServiceRegion.QA);
        } else if (x == 2) {
            server.setServerRegion(ServiceRegion.PRD);
        }

        server.setServerStatus(ServerStatus.ONLINE);
        server.setServerType(ServerType.DMGRSERVER);
        server.setServerComments("dmgr server");
        server.setAssignedEngineer(userAccount);
        server.setCpuType("AMD 1.0 GHz");
        server.setCpuCount(1);
        server.setServerModel("Virtual Server");
        server.setSerialNumber("1YU341");
        server.setInstalledMemory(4096);
        server.setMgrUrl("https://dmgr.myserver.org:18003/console");
        server.setDmgrPort(18003);
        server.setService(service);
        server.setNetworkPartition(NetworkPartition.DRN);

        ServerManagementRequest request = new ServerManagementRequest();
        request.setRequestInfo(hostInfo);
        request.setUserAccount(userAccount);
        request.setServiceId("45F6BC9E-F45C-4E2E-B5BF-04F93C8F512E");
        request.setTargetServer(server);
        request.setApplicationId("6236B840-88B0-4230-BCBC-8EC33EE837D9");
        request.setApplicationName("eSolutions");

        try {
            ServerManagementResponse response = processor.addNewServer(request);

            Assert.assertEquals(CoreServicesStatus.SUCCESS, response.getRequestStatus());
        } catch (ServerManagementException smx) {
            Assert.fail(smx.getMessage());
        }
    }
}