Search in sources :

Example 6 with BadArgumentException

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

the class GrantCommand 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().grantSystemPermission(user, SystemPermission.valueOf(permission[1]));
            Shell.log.debug("Granted " + 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().grantNamespacePermission(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)

Example 7 with BadArgumentException

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

the class QuotedStringTokenizer method createTokens.

private void createTokens() throws BadArgumentException, UnsupportedEncodingException {
    boolean inQuote = false;
    boolean inEscapeSequence = false;
    String hexChars = null;
    char inQuoteChar = '"';
    final byte[] token = new byte[input.length()];
    int tokenLength = 0;
    final byte[] inputBytes = input.getBytes(UTF_8);
    for (int i = 0; i < input.length(); ++i) {
        final char ch = input.charAt(i);
        // if I ended up in an escape sequence, check for valid escapable character, and add it as a literal
        if (inEscapeSequence) {
            inEscapeSequence = false;
            if (ch == 'x') {
                hexChars = "";
            } else if (ch == ' ' || ch == '\'' || ch == '"' || ch == '\\') {
                token[tokenLength++] = inputBytes[i];
            } else {
                throw new BadArgumentException("can only escape single quotes, double quotes, the space character, the backslash, and hex input", input, i);
            }
        } else if (hexChars != null) {
            // in a hex escape sequence
            final int digit = Character.digit(ch, 16);
            if (digit < 0) {
                throw new BadArgumentException("expected hex character", input, i);
            }
            hexChars += ch;
            if (hexChars.length() == 2) {
                byte b;
                try {
                    b = (byte) (0xff & Short.parseShort(hexChars, 16));
                    if (!Character.isValidCodePoint(0xff & b))
                        throw new NumberFormatException();
                } catch (NumberFormatException e) {
                    throw new BadArgumentException("unsupported non-ascii character", input, i);
                }
                token[tokenLength++] = b;
                hexChars = null;
            }
        } else if (inQuote) {
            // in a quote, either end the quote, start escape, or continue a token
            if (ch == inQuoteChar) {
                inQuote = false;
                tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
                tokenLength = 0;
            } else if (ch == '\\') {
                inEscapeSequence = true;
            } else {
                token[tokenLength++] = inputBytes[i];
            }
        } else {
            // not in a quote, either enter a quote, end a token, start escape, or continue a token
            if (ch == '\'' || ch == '"') {
                if (tokenLength > 0) {
                    tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
                    tokenLength = 0;
                }
                inQuote = true;
                inQuoteChar = ch;
            } else if (ch == ' ' && tokenLength > 0) {
                tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
                tokenLength = 0;
            } else if (ch == '\\') {
                inEscapeSequence = true;
            } else if (ch != ' ') {
                token[tokenLength++] = inputBytes[i];
            }
        }
    }
    if (inQuote) {
        throw new BadArgumentException("missing terminating quote", input, input.length());
    } else if (inEscapeSequence || hexChars != null) {
        throw new BadArgumentException("escape sequence not complete", input, input.length());
    }
    if (tokenLength > 0) {
        tokens.add(new String(token, 0, tokenLength, Shell.CHARSET));
    }
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException)

Example 8 with BadArgumentException

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

the class VisibilityFilter method accept.

@Override
protected boolean accept(Key k, Value v) {
    ByteSequence testVis = k.getColumnVisibilityData();
    if (testVis.length() == 0 && defaultVisibility.length() == 0)
        return true;
    else if (testVis.length() == 0)
        testVis = defaultVisibility;
    Boolean b = (Boolean) cache.get(testVis);
    if (b != null)
        return b;
    try {
        Boolean bb = ve.evaluate(new ColumnVisibility(testVis.toArray()));
        cache.put(testVis, bb);
        return bb;
    } catch (VisibilityParseException | BadArgumentException e) {
        log.error("Parse Error", e);
        return false;
    }
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) VisibilityParseException(org.apache.accumulo.core.security.VisibilityParseException)

Example 9 with BadArgumentException

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

the class VisibilityConstraint method check.

@Override
public List<Short> check(Environment env, Mutation mutation) {
    List<ColumnUpdate> updates = mutation.getUpdates();
    HashSet<String> ok = null;
    if (updates.size() > 1)
        ok = new HashSet<>();
    VisibilityEvaluator ve = null;
    for (ColumnUpdate update : updates) {
        byte[] cv = update.getColumnVisibility();
        if (cv.length > 0) {
            String key = null;
            if (ok != null && ok.contains(key = new String(cv, UTF_8)))
                continue;
            try {
                if (ve == null)
                    ve = new VisibilityEvaluator(env.getAuthorizationsContainer());
                if (!ve.evaluate(new ColumnVisibility(cv)))
                    return Collections.singletonList((short) 2);
            } catch (BadArgumentException | VisibilityParseException bae) {
                return Collections.singletonList((short) 1);
            }
            if (ok != null)
                ok.add(key);
        }
    }
    return null;
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) VisibilityEvaluator(org.apache.accumulo.core.security.VisibilityEvaluator) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) VisibilityParseException(org.apache.accumulo.core.security.VisibilityParseException) HashSet(java.util.HashSet)

Example 10 with BadArgumentException

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

the class VisibilityFilter method accept.

@Override
public boolean accept(Key k, Value v) {
    ByteSequence testVis = k.getColumnVisibilityData();
    if (filterInvalid) {
        Boolean b = (Boolean) cache.get(testVis);
        if (b != null)
            return b;
        try {
            new ColumnVisibility(testVis.toArray());
            cache.put(testVis, true);
            return true;
        } catch (BadArgumentException e) {
            cache.put(testVis, false);
            return false;
        }
    } else {
        if (testVis.length() == 0) {
            return true;
        }
        Boolean b = (Boolean) cache.get(testVis);
        if (b != null)
            return b;
        try {
            Boolean bb = ve.evaluate(new ColumnVisibility(testVis.toArray()));
            cache.put(testVis, bb);
            return bb;
        } catch (VisibilityParseException | BadArgumentException e) {
            log.error("Parse Error", e);
            return false;
        }
    }
}
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)

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