Search in sources :

Example 16 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class NioCommand method writeAuth.

private final void writeAuth(byte[] token) throws IOException {
    state = AsyncCommand.AUTH_WRITE;
    command.initBuffer();
    AdminCommand admin = new AdminCommand(command.dataBuffer);
    command.dataOffset = admin.setAuthenticate(cluster, token);
    byteBuffer.clear();
    byteBuffer.put(command.dataBuffer, 0, command.dataOffset);
    byteBuffer.flip();
    command.putBuffer();
    if (conn.write(byteBuffer)) {
        byteBuffer.clear();
        byteBuffer.limit(8);
        state = AsyncCommand.AUTH_READ_HEADER;
        // Socket timeout applies only to read events.
        // Reset event received because we are switching from a write to a read state.
        // This handles case where write succeeds and read event does not occur.  If we didn't reset,
        // the socket timeout would go through two iterations (double the timeout) because a write
        // event occurred in the first timeout period.
        eventReceived = false;
        conn.registerRead();
    } else {
        conn.registerWrite();
    }
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 17 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class NioConnector method writeAuth.

private final void writeAuth(byte[] token) throws IOException {
    state = AsyncCommand.AUTH_WRITE;
    byte[] dataBuffer = new byte[256];
    AdminCommand admin = new AdminCommand(dataBuffer);
    int dataOffset = admin.setAuthenticate(cluster, token);
    byteBuffer = eventLoop.getByteBuffer();
    byteBuffer.clear();
    byteBuffer.put(dataBuffer, 0, dataOffset);
    byteBuffer.flip();
    if (conn.write(byteBuffer)) {
        byteBuffer.clear();
        byteBuffer.limit(8);
        state = AsyncCommand.AUTH_READ_HEADER;
        conn.registerRead();
    } else {
        state = AsyncCommand.AUTH_WRITE;
        conn.registerWrite();
    }
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 18 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class AerospikeClient method setWhitelist.

/**
 * Set IP address whitelist for a role.  If whitelist is null or empty, remove existing whitelist from role.
 *
 * @param policy				admin configuration parameters, pass in null for defaults
 * @param roleName				role name
 * @param whitelist				list of allowable IP addresses or null.
 * 								IP addresses can contain wildcards (ie. 10.1.2.0/24).
 * @throws AerospikeException	if command fails
 */
public final void setWhitelist(AdminPolicy policy, String roleName, List<String> whitelist) throws AerospikeException {
    AdminCommand command = new AdminCommand();
    command.setWhitelist(cluster, policy, roleName, whitelist);
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 19 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class NettyConnector method writeAuth.

private void writeAuth(byte[] token) {
    state = AsyncCommand.AUTH_WRITE;
    AdminCommand admin = new AdminCommand(dataBuffer);
    dataOffset = admin.setAuthenticate(cluster, token);
    ByteBuf byteBuffer = PooledByteBufAllocator.DEFAULT.directBuffer(dataOffset);
    byteBuffer.clear();
    byteBuffer.writeBytes(dataBuffer, 0, dataOffset);
    ChannelFuture cf = conn.channel.writeAndFlush(byteBuffer);
    cf.addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) {
            if (state == AsyncCommand.AUTH_WRITE) {
                state = AsyncCommand.AUTH_READ_HEADER;
                dataOffset = 0;
                conn.channel.config().setAutoRead(true);
            }
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) AdminCommand(com.aerospike.client.admin.AdminCommand) ByteBuf(io.netty.buffer.ByteBuf) ChannelFutureListener(io.netty.channel.ChannelFutureListener)

Example 20 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class AerospikeClient method createUser.

// -------------------------------------------------------
// User administration
// -------------------------------------------------------
/**
 * Create user with password and roles.  Clear-text password will be hashed using bcrypt
 * before sending to server.
 *
 * @param policy				admin configuration parameters, pass in null for defaults
 * @param user					user name
 * @param password				user password in clear-text format
 * @param roles					variable arguments array of role names.  Predefined roles are listed in {@link com.aerospike.client.admin.Role}
 * @throws AerospikeException	if command fails
 */
public final void createUser(AdminPolicy policy, String user, String password, List<String> roles) throws AerospikeException {
    String hash = AdminCommand.hashPassword(password);
    AdminCommand command = new AdminCommand();
    command.createUser(cluster, policy, user, hash, roles);
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Aggregations

AdminCommand (com.aerospike.client.admin.AdminCommand)22 AerospikeException (com.aerospike.client.AerospikeException)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 AsyncConnection (com.aerospike.client.async.AsyncConnection)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1