Example usage for org.apache.cassandra.auth PasswordAuthenticator PasswordAuthenticator

List of usage examples for org.apache.cassandra.auth PasswordAuthenticator PasswordAuthenticator

Introduction

In this page you can find the example usage for org.apache.cassandra.auth PasswordAuthenticator PasswordAuthenticator.

Prototype

PasswordAuthenticator

Source Link

Usage

From source file:com.impetus.kundera.client.cassandra.pelops.crud.CassandraAuthenticationTest.java

License:Apache License

/**
 * Load cassandra specific data.//from   w w w .  ja  v a2s  .com
 * 
 * @throws TException
 *             the t exception
 * @throws InvalidRequestException
 *             the invalid request exception
 * @throws UnavailableException
 *             the unavailable exception
 * @throws TimedOutException
 *             the timed out exception
 * @throws SchemaDisagreementException
 *             the schema disagreement exception
 * @throws AuthorizationException
 * @throws AuthenticationException
 */
private void loadData() throws TException, InvalidRequestException, UnavailableException, TimedOutException,
        SchemaDisagreementException, AuthenticationException, AuthorizationException {

    KsDef ksDef = null;
    CfDef user_Def = new CfDef();
    user_Def.name = "PERSON";
    user_Def.keyspace = "KunderaAuthentication";
    user_Def.setComparator_type("UTF8Type");
    user_Def.setDefault_validation_class("UTF8Type");
    ColumnDef columnDef = new ColumnDef(ByteBuffer.wrap("PERSON_NAME".getBytes()), "UTF8Type");
    columnDef.index_type = IndexType.KEYS;
    user_Def.addToColumn_metadata(columnDef);
    ColumnDef columnDef1 = new ColumnDef(ByteBuffer.wrap("AGE".getBytes()), "UTF8Type");
    columnDef1.index_type = IndexType.KEYS;
    user_Def.addToColumn_metadata(columnDef1);

    List<CfDef> cfDefs = new ArrayList<CfDef>();
    cfDefs.add(user_Def);

    try {
        PasswordAuthenticator idAuth = new PasswordAuthenticator();
        Map<String, String> credentials = new HashMap<String, String>();
        credentials.put(idAuth.USERNAME_KEY, userName);
        credentials.put(idAuth.PASSWORD_KEY, password);
        CassandraCli.client.login(new AuthenticationRequest(credentials));

        CassandraCli.createKeySpace("KunderaAuthentication");

        ksDef = CassandraCli.client.describe_keyspace("KunderaAuthentication");
        CassandraCli.client.set_keyspace("KunderaAuthentication");

        List<CfDef> cfDefn = ksDef.getCf_defs();

        for (CfDef cfDef1 : cfDefn) {

            if (cfDef1.getName().equalsIgnoreCase("PERSON")) {

                CassandraCli.client.system_drop_column_family("PERSON");

            }
        }
        CassandraCli.client.system_add_column_family(user_Def);

    } catch (NotFoundException e) {

        ksDef = new KsDef("KunderaAuthentication", "org.apache.cassandra.locator.SimpleStrategy", cfDefs);
        ksDef.setReplication_factor(1);
        CassandraCli.client.system_add_keyspace(ksDef);
    }

    CassandraCli.client.set_keyspace("KunderaAuthentication");

}