Search in sources :

Example 1 with BadArgumentException

use of org.apache.accumulo.core.util.BadArgumentException in project accumulo by apache.

the class TransformingIterator method canSee.

/**
 * Indicates whether or not the user is able to see {@code key}. If the user has not supplied authorizations, or the iterator is not in the scan scope, then
 * this method simply returns {@code true}. Otherwise, {@code key}'s column visibility is tested against the user-supplied authorizations, and the test result
 * is returned. For performance, the test results are cached so that the same visibility is not tested multiple times.
 *
 * @param key
 *          the key to test
 * @return {@code true} if the key is visible or iterator is not scanning, and {@code false} if not
 */
protected boolean canSee(Key key) {
    // Ensure that the visibility (which could have been transformed) parses. Must always do this check, even if visibility is not evaluated.
    ByteSequence visibility = key.getColumnVisibilityData();
    ColumnVisibility colVis = null;
    Boolean parsed = (Boolean) parsedVisibilitiesCache.get(visibility);
    if (parsed == null) {
        try {
            colVis = new ColumnVisibility(visibility.toArray());
            parsedVisibilitiesCache.put(visibility, Boolean.TRUE);
        } catch (BadArgumentException e) {
            log.error("Parse error after transformation : {}", visibility);
            parsedVisibilitiesCache.put(visibility, Boolean.FALSE);
            if (scanning) {
                return false;
            } else {
                throw e;
            }
        }
    } else if (!parsed) {
        if (scanning)
            return false;
        else
            throw new IllegalStateException();
    }
    Boolean visible = canSeeColumnFamily(key);
    if (!scanning || !visible || ve == null || visibleCache == null || visibility.length() == 0)
        return visible;
    visible = (Boolean) visibleCache.get(visibility);
    if (visible == null) {
        try {
            if (colVis == null)
                colVis = new ColumnVisibility(visibility.toArray());
            visible = ve.evaluate(colVis);
            visibleCache.put(visibility, visible);
        } catch (VisibilityParseException | BadArgumentException e) {
            log.error("Parse Error", e);
            visible = Boolean.FALSE;
        }
    }
    return visible;
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ByteSequence(org.apache.accumulo.core.data.ByteSequence) VisibilityParseException(org.apache.accumulo.core.security.VisibilityParseException)

Example 2 with BadArgumentException

use of org.apache.accumulo.core.util.BadArgumentException 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 3 with BadArgumentException

use of org.apache.accumulo.core.util.BadArgumentException in project accumulo by apache.

the class ConfigCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceNotFoundException {
    reader = shellState.getReader();
    final String tableName = cl.getOptionValue(tableOpt.getOpt());
    if (tableName != null && !shellState.getConnector().tableOperations().exists(tableName)) {
        throw new TableNotFoundException(null, tableName, null);
    }
    final String namespace = cl.getOptionValue(namespaceOpt.getOpt());
    if (namespace != null && !shellState.getConnector().namespaceOperations().exists(namespace)) {
        throw new NamespaceNotFoundException(null, namespace, null);
    }
    if (cl.hasOption(deleteOpt.getOpt())) {
        // delete property from table
        String property = cl.getOptionValue(deleteOpt.getOpt());
        if (property.contains("=")) {
            throw new BadArgumentException("Invalid '=' operator in delete operation.", fullCommand, fullCommand.indexOf('='));
        }
        if (tableName != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().tableOperations().removeProperty(tableName, property);
            Shell.log.debug("Successfully deleted table configuration option.");
        } else if (namespace != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().namespaceOperations().removeProperty(namespace, property);
            Shell.log.debug("Successfully deleted namespace configuration option.");
        } else {
            if (!Property.isValidZooPropertyKey(property)) {
                Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
            }
            shellState.getConnector().instanceOperations().removeProperty(property);
            Shell.log.debug("Successfully deleted system configuration option");
        }
    } else if (cl.hasOption(setOpt.getOpt())) {
        // set property on table
        String property = cl.getOptionValue(setOpt.getOpt()), value = null;
        if (!property.contains("=")) {
            throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand, fullCommand.indexOf(property));
        }
        final String[] pair = property.split("=", 2);
        property = pair[0];
        value = pair[1];
        if (tableName != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property));
            }
            if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
                // validate that it is a valid expression
                new ColumnVisibility(value);
            }
            shellState.getConnector().tableOperations().setProperty(tableName, property, value);
            Shell.log.debug("Successfully set table configuration option.");
        } else if (namespace != null) {
            if (!Property.isValidTablePropertyKey(property)) {
                throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property));
            }
            if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
                // validate that it is a valid expression
                new ColumnVisibility(value);
            }
            shellState.getConnector().namespaceOperations().setProperty(namespace, property, value);
            Shell.log.debug("Successfully set table configuration option.");
        } else {
            if (!Property.isValidZooPropertyKey(property)) {
                throw new BadArgumentException("Property cannot be modified in zookeeper", fullCommand, fullCommand.indexOf(property));
            }
            shellState.getConnector().instanceOperations().setProperty(property, value);
            Shell.log.debug("Successfully set system configuration option");
        }
    } else {
        // display properties
        final TreeMap<String, String> systemConfig = new TreeMap<>();
        systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration());
        final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
        final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);
        final TreeMap<String, String> siteConfig = new TreeMap<>();
        siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration());
        final TreeMap<String, String> defaults = new TreeMap<>();
        for (Entry<String, String> defaultEntry : DefaultConfiguration.getInstance()) {
            defaults.put(defaultEntry.getKey(), defaultEntry.getValue());
        }
        final TreeMap<String, String> namespaceConfig = new TreeMap<>();
        if (tableName != null) {
            String n = Namespaces.getNamespaceName(shellState.getInstance(), Tables.getNamespaceId(shellState.getInstance(), Tables.getTableId(shellState.getInstance(), tableName)));
            for (Entry<String, String> e : shellState.getConnector().namespaceOperations().getProperties(n)) {
                namespaceConfig.put(e.getKey(), e.getValue());
            }
        }
        Iterable<Entry<String, String>> acuconf = shellState.getConnector().instanceOperations().getSystemConfiguration().entrySet();
        if (tableName != null) {
            acuconf = shellState.getConnector().tableOperations().getProperties(tableName);
        } else if (namespace != null) {
            acuconf = shellState.getConnector().namespaceOperations().getProperties(namespace);
        }
        final TreeMap<String, String> sortedConf = new TreeMap<>();
        for (Entry<String, String> propEntry : acuconf) {
            sortedConf.put(propEntry.getKey(), propEntry.getValue());
        }
        for (Entry<String, String> propEntry : acuconf) {
            final String key = propEntry.getKey();
            // specified, or all of them if none specified
            if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
                continue;
            }
            if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
                continue;
            }
            COL2 = Math.max(COL2, propEntry.getKey().length() + 3);
        }
        final ArrayList<String> output = new ArrayList<>();
        printConfHeader(output);
        for (Entry<String, String> propEntry : sortedConf.entrySet()) {
            final String key = propEntry.getKey();
            // specified, or all of them if none specified
            if (cl.hasOption(filterOpt.getOpt()) && !key.contains(cl.getOptionValue(filterOpt.getOpt()))) {
                continue;
            }
            if ((tableName != null || namespace != null) && !Property.isValidTablePropertyKey(key)) {
                continue;
            }
            String siteVal = siteConfig.get(key);
            String sysVal = systemConfig.get(key);
            String curVal = propEntry.getValue();
            String dfault = defaults.get(key);
            String nspVal = namespaceConfig.get(key);
            boolean printed = false;
            if (dfault != null && key.toLowerCase().contains("password")) {
                siteVal = sysVal = dfault = curVal = curVal.replaceAll(".", "*");
            }
            if (sysVal != null) {
                if (defaults.containsKey(key) && !Property.getPropertyByKey(key).isExperimental()) {
                    printConfLine(output, "default", key, dfault);
                    printed = true;
                }
                if (!defaults.containsKey(key) || !defaults.get(key).equals(siteVal)) {
                    printConfLine(output, "site", printed ? "   @override" : key, siteVal == null ? "" : siteVal);
                    printed = true;
                }
                if (!siteConfig.containsKey(key) || !siteVal.equals(sysVal)) {
                    printConfLine(output, "system", printed ? "   @override" : key, sysVal);
                    printed = true;
                }
            }
            if (nspVal != null) {
                if (!systemConfig.containsKey(key) || !sysVal.equals(nspVal)) {
                    printConfLine(output, "namespace", printed ? "   @override" : key, nspVal);
                    printed = true;
                }
            }
            // show per-table value only if it is different (overridden)
            if (tableName != null && !curVal.equals(nspVal)) {
                printConfLine(output, "table", printed ? "   @override" : key, curVal);
            } else if (namespace != null && !curVal.equals(sysVal)) {
                printConfLine(output, "namespace", printed ? "   @override" : key, curVal);
            }
        }
        printConfFooter(output);
        shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()), printFile);
        if (printFile != null) {
            printFile.close();
        }
    }
    return 0;
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) PrintFile(org.apache.accumulo.shell.Shell.PrintFile) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) TreeMap(java.util.TreeMap) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException)

Example 4 with BadArgumentException

use of org.apache.accumulo.core.util.BadArgumentException in project accumulo by apache.

the class ConditionalWriterImpl method isVisible.

private boolean isVisible(ByteSequence cv) {
    Text testVis = new Text(cv.toArray());
    if (testVis.getLength() == 0)
        return true;
    Boolean b = cache.get(testVis);
    if (b != null)
        return b;
    try {
        Boolean bb = ve.evaluate(new ColumnVisibility(testVis));
        cache.put(new Text(testVis), bb);
        return bb;
    } catch (VisibilityParseException | BadArgumentException e) {
        return false;
    }
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) VisibilityParseException(org.apache.accumulo.core.security.VisibilityParseException)

Example 5 with BadArgumentException

use of org.apache.accumulo.core.util.BadArgumentException in project accumulo by apache.

the class RevokeCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    user = cl.hasOption(userOpt.getOpt()) ? cl.getOptionValue(userOpt.getOpt()) : shellState.getConnector().whoami();
    permission = cl.getArgs()[0].split("\\.", 2);
    if (cl.hasOption(systemOpt.getOpt()) && permission[0].equalsIgnoreCase("System")) {
        try {
            shellState.getConnector().securityOperations().revokeSystemPermission(user, SystemPermission.valueOf(permission[1]));
            Shell.log.debug("Revoked from " + user + " the " + permission[1] + " permission");
        } catch (IllegalArgumentException e) {
            throw new BadArgumentException("No such system permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
        }
    } else if (permission[0].equalsIgnoreCase("Table")) {
        super.execute(fullCommand, cl, shellState);
    } else if (permission[0].equalsIgnoreCase("Namespace")) {
        if (cl.hasOption(optNamespace.getOpt())) {
            try {
                shellState.getConnector().securityOperations().revokeNamespacePermission(user, cl.getOptionValue(optNamespace.getOpt()), NamespacePermission.valueOf(permission[1]));
            } catch (IllegalArgumentException e) {
                throw new BadArgumentException("No such namespace permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
            }
        } else {
            throw new BadArgumentException("No namespace specified to apply permission to", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
        }
    } else {
        throw new BadArgumentException("Unrecognized permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
    }
    return 0;
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException)

Aggregations

BadArgumentException (org.apache.accumulo.core.util.BadArgumentException)10 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)6 VisibilityParseException (org.apache.accumulo.core.security.VisibilityParseException)5 ByteSequence (org.apache.accumulo.core.data.ByteSequence)3 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)2 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)2 ParameterException (com.beust.jcommander.ParameterException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 UserInterruptException (jline.console.UserInterruptException)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 ArrayByteSequence (org.apache.accumulo.core.data.ArrayByteSequence)1 ColumnUpdate (org.apache.accumulo.core.data.ColumnUpdate)1 VisibilityEvaluator (org.apache.accumulo.core.security.VisibilityEvaluator)1