Search in sources :

Example 66 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.

the class CredentialsTest method roundtripThrift.

@Test
public void roundtripThrift() throws DestroyFailedException {
    Credentials creds = new Credentials("test", new PasswordToken("testing"));
    TCredentials tCreds = creds.toThrift(inst);
    Credentials roundtrip = Credentials.fromThrift(tCreds);
    assertEquals("Roundtrip through thirft changed credentials equality", creds, roundtrip);
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) Credentials(org.apache.accumulo.core.client.impl.Credentials) Test(org.junit.Test)

Example 67 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.

the class CredentialsTest method testToThrift.

@Test
public void testToThrift() throws DestroyFailedException {
    // verify thrift serialization
    Credentials creds = new Credentials("test", new PasswordToken("testing"));
    TCredentials tCreds = creds.toThrift(inst);
    assertEquals("test", tCreds.getPrincipal());
    assertEquals(PasswordToken.class.getName(), tCreds.getTokenClassName());
    assertArrayEquals(AuthenticationTokenSerializer.serialize(new PasswordToken("testing")), tCreds.getToken());
    // verify that we can't serialize if it's destroyed
    creds.getToken().destroy();
    try {
        creds.toThrift(inst);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof RuntimeException);
        assertTrue(e.getCause() instanceof AccumuloSecurityException);
        assertTrue(AccumuloSecurityException.class.cast(e.getCause()).getSecurityErrorCode().equals(SecurityErrorCode.TOKEN_EXPIRED));
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TCredentials(org.apache.accumulo.core.security.thrift.TCredentials) Credentials(org.apache.accumulo.core.client.impl.Credentials) DestroyFailedException(javax.security.auth.DestroyFailedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Test(org.junit.Test)

Example 68 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.

the class AccumuloReplicaSystem method replicate.

@Override
public Status replicate(final Path p, final Status status, final ReplicationTarget target, final ReplicaSystemHelper helper) {
    final Instance localInstance = HdfsZooInstance.getInstance();
    final AccumuloConfiguration localConf = new ServerConfigurationFactory(localInstance).getSystemConfiguration();
    log.debug("Replication RPC timeout is {}", localConf.get(Property.REPLICATION_RPC_TIMEOUT.getKey()));
    final String principal = getPrincipal(localConf, target);
    final File keytab;
    final String password;
    if (localConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
        String keytabPath = getKeytab(localConf, target);
        keytab = new File(keytabPath);
        if (!keytab.exists() || !keytab.isFile()) {
            log.error("{} is not a regular file. Cannot login to replicate", keytabPath);
            return status;
        }
        password = null;
    } else {
        keytab = null;
        password = getPassword(localConf, target);
    }
    if (null != keytab) {
        try {
            final UserGroupInformation accumuloUgi = UserGroupInformation.getCurrentUser();
            // Get a UGI with the principal + keytab
            UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab.getAbsolutePath());
            // Run inside a doAs to avoid nuking the Tserver's user
            return ugi.doAs(new PrivilegedAction<Status>() {

                @Override
                public Status run() {
                    KerberosToken token;
                    try {
                        // Do *not* replace the current user
                        token = new KerberosToken(principal, keytab);
                    } catch (IOException e) {
                        log.error("Failed to create KerberosToken", e);
                        return status;
                    }
                    ClientContext peerContext = getContextForPeer(localConf, target, principal, token);
                    return _replicate(p, status, target, helper, localConf, peerContext, accumuloUgi);
                }
            });
        } catch (IOException e) {
            // Can't log in, can't replicate
            log.error("Failed to perform local login", e);
            return status;
        }
    } else {
        // Simple case: make a password token, context and then replicate
        PasswordToken token = new PasswordToken(password);
        ClientContext peerContext = getContextForPeer(localConf, target, principal, token);
        return _replicate(p, status, target, helper, localConf, peerContext, null);
    }
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) IOException(java.io.IOException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) File(java.io.File) RFile(org.apache.accumulo.core.file.rfile.RFile) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 69 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.

the class Shell method execCommand.

public void execCommand(String input, boolean ignoreAuthTimeout, boolean echoPrompt) throws IOException {
    audit.log(Level.INFO, getDefaultPrompt() + input);
    if (echoPrompt) {
        reader.print(getDefaultPrompt());
        reader.println(input);
    }
    if (input.startsWith(COMMENT_PREFIX)) {
        return;
    }
    String[] fields;
    try {
        fields = new QuotedStringTokenizer(input).getTokens();
    } catch (BadArgumentException e) {
        printException(e);
        ++exitCode;
        return;
    }
    if (fields.length == 0)
        return;
    String command = fields[0];
    fields = fields.length > 1 ? Arrays.copyOfRange(fields, 1, fields.length) : new String[] {};
    Command sc = null;
    if (command.length() > 0) {
        try {
            // Obtain the command from the command table
            sc = commandFactory.get(command);
            if (sc == null) {
                reader.println(String.format("Unknown command \"%s\".  Enter \"help\" for a list possible commands.", command));
                reader.flush();
                return;
            }
            long duration = System.nanoTime() - lastUserActivity;
            if (!(sc instanceof ExitCommand) && !ignoreAuthTimeout && (duration < 0 || duration > authTimeout)) {
                reader.println("Shell has been idle for too long. Please re-authenticate.");
                boolean authFailed = true;
                do {
                    String pwd = readMaskedLine("Enter current password for '" + connector.whoami() + "': ", '*');
                    if (pwd == null) {
                        reader.println();
                        return;
                    }
                    try {
                        authFailed = !connector.securityOperations().authenticateUser(connector.whoami(), new PasswordToken(pwd));
                    } catch (Exception e) {
                        ++exitCode;
                        printException(e);
                    }
                    if (authFailed)
                        reader.print("Invalid password. ");
                } while (authFailed);
                lastUserActivity = System.nanoTime();
            }
            // Get the options from the command on how to parse the string
            Options parseOpts = sc.getOptionsWithHelp();
            // Parse the string using the given options
            CommandLine cl = new BasicParser().parse(parseOpts, fields);
            int actualArgLen = cl.getArgs().length;
            int expectedArgLen = sc.numArgs();
            if (cl.hasOption(helpOption)) {
                // Display help if asked to; otherwise execute the command
                sc.printHelp(this);
            } else if (expectedArgLen != NO_FIXED_ARG_LENGTH_CHECK && actualArgLen != expectedArgLen) {
                ++exitCode;
                // Check for valid number of fixed arguments (if not
                // negative; negative means it is not checked, for
                // vararg-like commands)
                printException(new IllegalArgumentException(String.format("Expected %d argument%s. There %s %d.", expectedArgLen, expectedArgLen == 1 ? "" : "s", actualArgLen == 1 ? "was" : "were", actualArgLen)));
                sc.printHelp(this);
            } else {
                int tmpCode = sc.execute(input, cl, this);
                exitCode += tmpCode;
                reader.flush();
            }
        } catch (ConstraintViolationException e) {
            ++exitCode;
            printConstraintViolationException(e);
        } catch (TableNotFoundException e) {
            ++exitCode;
            if (getTableName().equals(e.getTableName()))
                setTableName("");
            printException(e);
        } catch (ParseException e) {
            // option when the user is asking for help
            if (!(e instanceof MissingOptionException && (Arrays.asList(fields).contains("-" + helpOption) || Arrays.asList(fields).contains("--" + helpLongOption)))) {
                ++exitCode;
                printException(e);
            }
            if (sc != null)
                sc.printHelp(this);
        } catch (UserInterruptException e) {
            ++exitCode;
        } catch (Exception e) {
            ++exitCode;
            printException(e);
        }
    } else {
        ++exitCode;
        printException(new BadArgumentException("Unrecognized empty command", command, -1));
    }
    reader.flush();
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) Options(org.apache.commons.cli.Options) ExitCommand(org.apache.accumulo.shell.commands.ExitCommand) UserInterruptException(jline.console.UserInterruptException) UserInterruptException(jline.console.UserInterruptException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) FileSystemException(org.apache.commons.vfs2.FileSystemException) BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) IOException(java.io.IOException) MissingOptionException(org.apache.commons.cli.MissingOptionException) ParameterException(com.beust.jcommander.ParameterException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) BasicParser(org.apache.commons.cli.BasicParser) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) CommandLine(org.apache.commons.cli.CommandLine) QuotedStringTokenizer(org.apache.accumulo.shell.commands.QuotedStringTokenizer) WhoAmICommand(org.apache.accumulo.shell.commands.WhoAmICommand) SetAuthsCommand(org.apache.accumulo.shell.commands.SetAuthsCommand) InsertCommand(org.apache.accumulo.shell.commands.InsertCommand) SystemPermissionsCommand(org.apache.accumulo.shell.commands.SystemPermissionsCommand) CreateNamespaceCommand(org.apache.accumulo.shell.commands.CreateNamespaceCommand) CloneTableCommand(org.apache.accumulo.shell.commands.CloneTableCommand) DropTableCommand(org.apache.accumulo.shell.commands.DropTableCommand) CreateTableCommand(org.apache.accumulo.shell.commands.CreateTableCommand) DUCommand(org.apache.accumulo.shell.commands.DUCommand) DeleteAuthsCommand(org.apache.accumulo.shell.commands.DeleteAuthsCommand) CreateUserCommand(org.apache.accumulo.shell.commands.CreateUserCommand) InterpreterCommand(org.apache.accumulo.shell.commands.InterpreterCommand) SetIterCommand(org.apache.accumulo.shell.commands.SetIterCommand) OfflineCommand(org.apache.accumulo.shell.commands.OfflineCommand) ScanCommand(org.apache.accumulo.shell.commands.ScanCommand) TablePermissionsCommand(org.apache.accumulo.shell.commands.TablePermissionsCommand) UserCommand(org.apache.accumulo.shell.commands.UserCommand) GetGroupsCommand(org.apache.accumulo.shell.commands.GetGroupsCommand) DeleteTableCommand(org.apache.accumulo.shell.commands.DeleteTableCommand) DeleteUserCommand(org.apache.accumulo.shell.commands.DeleteUserCommand) AddAuthsCommand(org.apache.accumulo.shell.commands.AddAuthsCommand) ListBulkCommand(org.apache.accumulo.shell.commands.ListBulkCommand) TablesCommand(org.apache.accumulo.shell.commands.TablesCommand) AuthenticateCommand(org.apache.accumulo.shell.commands.AuthenticateCommand) HistoryCommand(org.apache.accumulo.shell.commands.HistoryCommand) SummariesCommand(org.apache.accumulo.shell.commands.SummariesCommand) SetScanIterCommand(org.apache.accumulo.shell.commands.SetScanIterCommand) SleepCommand(org.apache.accumulo.shell.commands.SleepCommand) ImportTableCommand(org.apache.accumulo.shell.commands.ImportTableCommand) DropUserCommand(org.apache.accumulo.shell.commands.DropUserCommand) FormatterCommand(org.apache.accumulo.shell.commands.FormatterCommand) ExecfileCommand(org.apache.accumulo.shell.commands.ExecfileCommand) InfoCommand(org.apache.accumulo.shell.commands.InfoCommand) ConstraintCommand(org.apache.accumulo.shell.commands.ConstraintCommand) DebugCommand(org.apache.accumulo.shell.commands.DebugCommand) DeleteManyCommand(org.apache.accumulo.shell.commands.DeleteManyCommand) DeleteShellIterCommand(org.apache.accumulo.shell.commands.DeleteShellIterCommand) CompactCommand(org.apache.accumulo.shell.commands.CompactCommand) GetSplitsCommand(org.apache.accumulo.shell.commands.GetSplitsCommand) DeleteScanIterCommand(org.apache.accumulo.shell.commands.DeleteScanIterCommand) FateCommand(org.apache.accumulo.shell.commands.FateCommand) HelpCommand(org.apache.accumulo.shell.commands.HelpCommand) GrantCommand(org.apache.accumulo.shell.commands.GrantCommand) ConfigCommand(org.apache.accumulo.shell.commands.ConfigCommand) ExitCommand(org.apache.accumulo.shell.commands.ExitCommand) RenameNamespaceCommand(org.apache.accumulo.shell.commands.RenameNamespaceCommand) AboutCommand(org.apache.accumulo.shell.commands.AboutCommand) DeleteCommand(org.apache.accumulo.shell.commands.DeleteCommand) SetGroupsCommand(org.apache.accumulo.shell.commands.SetGroupsCommand) UserPermissionsCommand(org.apache.accumulo.shell.commands.UserPermissionsCommand) SetShellIterCommand(org.apache.accumulo.shell.commands.SetShellIterCommand) ScriptCommand(org.apache.accumulo.shell.commands.ScriptCommand) ImportDirectoryCommand(org.apache.accumulo.shell.commands.ImportDirectoryCommand) OnlineCommand(org.apache.accumulo.shell.commands.OnlineCommand) ListScansCommand(org.apache.accumulo.shell.commands.ListScansCommand) DeleteRowsCommand(org.apache.accumulo.shell.commands.DeleteRowsCommand) PasswdCommand(org.apache.accumulo.shell.commands.PasswdCommand) ExtensionCommand(org.apache.accumulo.shell.commands.ExtensionCommand) MaxRowCommand(org.apache.accumulo.shell.commands.MaxRowCommand) ByeCommand(org.apache.accumulo.shell.commands.ByeCommand) GrepCommand(org.apache.accumulo.shell.commands.GrepCommand) MergeCommand(org.apache.accumulo.shell.commands.MergeCommand) NoTableCommand(org.apache.accumulo.shell.commands.NoTableCommand) ListCompactionsCommand(org.apache.accumulo.shell.commands.ListCompactionsCommand) PingCommand(org.apache.accumulo.shell.commands.PingCommand) ClsCommand(org.apache.accumulo.shell.commands.ClsCommand) ListIterCommand(org.apache.accumulo.shell.commands.ListIterCommand) DeleteIterCommand(org.apache.accumulo.shell.commands.DeleteIterCommand) GetAuthsCommand(org.apache.accumulo.shell.commands.GetAuthsCommand) TraceCommand(org.apache.accumulo.shell.commands.TraceCommand) RenameTableCommand(org.apache.accumulo.shell.commands.RenameTableCommand) NamespacePermissionsCommand(org.apache.accumulo.shell.commands.NamespacePermissionsCommand) UsersCommand(org.apache.accumulo.shell.commands.UsersCommand) DeleteNamespaceCommand(org.apache.accumulo.shell.commands.DeleteNamespaceCommand) TableCommand(org.apache.accumulo.shell.commands.TableCommand) ClearCommand(org.apache.accumulo.shell.commands.ClearCommand) HiddenCommand(org.apache.accumulo.shell.commands.HiddenCommand) FlushCommand(org.apache.accumulo.shell.commands.FlushCommand) ExportTableCommand(org.apache.accumulo.shell.commands.ExportTableCommand) ClasspathCommand(org.apache.accumulo.shell.commands.ClasspathCommand) RevokeCommand(org.apache.accumulo.shell.commands.RevokeCommand) ListShellIterCommand(org.apache.accumulo.shell.commands.ListShellIterCommand) QuitCommand(org.apache.accumulo.shell.commands.QuitCommand) EGrepCommand(org.apache.accumulo.shell.commands.EGrepCommand) AddSplitsCommand(org.apache.accumulo.shell.commands.AddSplitsCommand) NamespacesCommand(org.apache.accumulo.shell.commands.NamespacesCommand) QuestionCommand(org.apache.accumulo.shell.commands.QuestionCommand) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) ParseException(org.apache.commons.cli.ParseException) MissingOptionException(org.apache.commons.cli.MissingOptionException)

Example 70 with PasswordToken

use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.

the class ReplicationProcessorTest method peerTypeExtractionFromConfiguration.

@Test
public void peerTypeExtractionFromConfiguration() {
    Instance inst = EasyMock.createMock(Instance.class);
    VolumeManager fs = EasyMock.createMock(VolumeManager.class);
    Credentials creds = new Credentials("foo", new PasswordToken("bar"));
    ClientContext context = new ClientContext(inst, creds, ClientConfiguration.create());
    Map<String, String> data = new HashMap<>();
    String peerName = "peer";
    String configuration = "java.lang.String,foo";
    data.put(Property.REPLICATION_PEERS + peerName, configuration);
    ConfigurationCopy conf = new ConfigurationCopy(data);
    ReplicationProcessor proc = new ReplicationProcessor(context, conf, fs);
    Assert.assertEquals(configuration, proc.getPeerType(peerName));
}
Also used : VolumeManager(org.apache.accumulo.server.fs.VolumeManager) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) Instance(org.apache.accumulo.core.client.Instance) HashMap(java.util.HashMap) ClientContext(org.apache.accumulo.core.client.impl.ClientContext) Credentials(org.apache.accumulo.core.client.impl.Credentials) Test(org.junit.Test)

Aggregations

PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)232 Test (org.junit.Test)104 Connector (org.apache.accumulo.core.client.Connector)96 MockInstance (org.apache.accumulo.core.client.mock.MockInstance)53 Instance (org.apache.accumulo.core.client.Instance)46 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)43 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)40 Authorizations (org.apache.accumulo.core.security.Authorizations)38 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)32 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)30 Value (org.apache.accumulo.core.data.Value)30 Key (org.apache.accumulo.core.data.Key)29 Mutation (org.apache.accumulo.core.data.Mutation)29 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Scanner (org.apache.accumulo.core.client.Scanner)27 Configuration (org.apache.hadoop.conf.Configuration)27 IOException (java.io.IOException)26 BatchWriter (org.apache.accumulo.core.client.BatchWriter)26 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)24