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();
}
}
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();
}
}
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);
}
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);
}
}
});
}
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);
}
Aggregations