use of org.apache.accumulo.core.client.admin.SecurityOperations in project hive by apache.
the class HiveAccumuloHelper method getDelegationToken.
/**
* Obtain a DelegationToken from Accumulo in a backwards compatible manner.
*
* @param conn
* The Accumulo connector
* @return The DelegationToken instance
* @throws IOException
* If the token cannot be obtained
*/
public AuthenticationToken getDelegationToken(Connector conn) throws IOException {
try {
Class<?> clz = JavaUtils.loadClass(DELEGATION_TOKEN_CONFIG_CLASS_NAME);
// DelegationTokenConfig delegationTokenConfig = new DelegationTokenConfig();
Object delegationTokenConfig = clz.newInstance();
SecurityOperations secOps = conn.securityOperations();
Method getDelegationTokenMethod = secOps.getClass().getMethod(GET_DELEGATION_TOKEN_METHOD_NAME, clz);
// secOps.getDelegationToken(delegationTokenConfig)
return (AuthenticationToken) getDelegationTokenMethod.invoke(secOps, delegationTokenConfig);
} catch (Exception e) {
throw new IOException("Failed to obtain DelegationToken from Accumulo", e);
}
}
use of org.apache.accumulo.core.client.admin.SecurityOperations in project accumulo by apache.
the class DeleteAuthsCommandTest method deleteAllAuth.
@Test
public void deleteAllAuth() throws Exception {
Connector conn = EasyMock.createMock(Connector.class);
CommandLine cli = EasyMock.createMock(CommandLine.class);
Shell shellState = EasyMock.createMock(Shell.class);
ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
EasyMock.expect(shellState.getConnector()).andReturn(conn);
// We're the root user
EasyMock.expect(conn.whoami()).andReturn("root");
EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
EasyMock.expect(cli.getOptionValue("s")).andReturn("abc,123");
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
secOps.changeUserAuthorizations("foo", new Authorizations());
EasyMock.expectLastCall();
EasyMock.replay(conn, cli, shellState, reader, secOps);
cmd.execute("deleteauths -u foo -s abc,123", cli, shellState);
EasyMock.verify(conn, cli, shellState, reader, secOps);
}
use of org.apache.accumulo.core.client.admin.SecurityOperations in project accumulo by apache.
the class DeleteAuthsCommandTest method deleteExistingAuth.
@Test
public void deleteExistingAuth() throws Exception {
Connector conn = EasyMock.createMock(Connector.class);
CommandLine cli = EasyMock.createMock(CommandLine.class);
Shell shellState = EasyMock.createMock(Shell.class);
ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
EasyMock.expect(shellState.getConnector()).andReturn(conn);
// We're the root user
EasyMock.expect(conn.whoami()).andReturn("root");
EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
EasyMock.expect(cli.getOptionValue("s")).andReturn("abc");
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
secOps.changeUserAuthorizations("foo", new Authorizations("123"));
EasyMock.expectLastCall();
EasyMock.replay(conn, cli, shellState, reader, secOps);
cmd.execute("deleteauths -u foo -s abc", cli, shellState);
EasyMock.verify(conn, cli, shellState, reader, secOps);
}
use of org.apache.accumulo.core.client.admin.SecurityOperations in project accumulo by apache.
the class DeleteAuthsCommandTest method deleteNonExistingAuth.
@Test
public void deleteNonExistingAuth() throws Exception {
Connector conn = EasyMock.createMock(Connector.class);
CommandLine cli = EasyMock.createMock(CommandLine.class);
Shell shellState = EasyMock.createMock(Shell.class);
ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
EasyMock.expect(shellState.getConnector()).andReturn(conn);
// We're the root user
EasyMock.expect(conn.whoami()).andReturn("root");
EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
EasyMock.expect(cli.getOptionValue("s")).andReturn("def");
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
secOps.changeUserAuthorizations("foo", new Authorizations("abc", "123"));
EasyMock.expectLastCall();
EasyMock.replay(conn, cli, shellState, reader, secOps);
cmd.execute("deleteauths -u foo -s def", cli, shellState);
EasyMock.verify(conn, cli, shellState, reader, secOps);
}
use of org.apache.accumulo.core.client.admin.SecurityOperations in project accumulo by apache.
the class DropUserCommandTest method dropUserWithoutForcePrompts.
@Test
public void dropUserWithoutForcePrompts() throws Exception {
Connector conn = EasyMock.createMock(Connector.class);
CommandLine cli = EasyMock.createMock(CommandLine.class);
Shell shellState = EasyMock.createMock(Shell.class);
ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
EasyMock.expect(shellState.getConnector()).andReturn(conn);
// The user we want to remove
EasyMock.expect(cli.getArgs()).andReturn(new String[] { "user" });
// We're the root user
EasyMock.expect(conn.whoami()).andReturn("root");
// Force option was not provided
EasyMock.expect(cli.hasOption("f")).andReturn(false);
EasyMock.expect(shellState.getReader()).andReturn(reader);
reader.flush();
EasyMock.expectLastCall().once();
// Fake a "yes" response
EasyMock.expect(shellState.getReader()).andReturn(reader);
EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("yes");
EasyMock.expect(shellState.getConnector()).andReturn(conn);
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
secOps.dropLocalUser("user");
EasyMock.expectLastCall();
EasyMock.replay(conn, cli, shellState, reader, secOps);
cmd.execute("dropuser foo -f", cli, shellState);
EasyMock.verify(conn, cli, shellState, reader, secOps);
}
Aggregations