Search in sources :

Example 1 with SecurityOperations

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);
    }
}
Also used : AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Method(java.lang.reflect.Method) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with SecurityOperations

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) ConsoleReader(jline.console.ConsoleReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 3 with SecurityOperations

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) ConsoleReader(jline.console.ConsoleReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 4 with SecurityOperations

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) ConsoleReader(jline.console.ConsoleReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 5 with SecurityOperations

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) ConsoleReader(jline.console.ConsoleReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Aggregations

SecurityOperations (org.apache.accumulo.core.client.admin.SecurityOperations)32 Test (org.junit.Test)12 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)10 Authorizations (org.apache.accumulo.core.security.Authorizations)10 Connector (org.apache.accumulo.core.client.Connector)9 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)8 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)6 RyaClient (org.apache.rya.api.client.RyaClient)6 IOException (java.io.IOException)4 ConsoleReader (jline.console.ConsoleReader)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)4 Scanner (org.apache.accumulo.core.client.Scanner)4 Shell (org.apache.accumulo.shell.Shell)4 CommandLine (org.apache.commons.cli.CommandLine)4 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)4 Entry (java.util.Map.Entry)3 RyaDetails (org.apache.rya.api.instance.RyaDetails)3 Before (org.junit.Before)3 ValueFactory (org.openrdf.model.ValueFactory)3