Search in sources :

Example 1 with CommandAclException

use of dmg.util.CommandAclException in project dcache by dCache.

the class CellAdapter method checkAclPermission.

protected void checkAclPermission(String user, Object command, String acl) throws CommandException {
    Object[] request = new Object[5];
    request[0] = "request";
    request[1] = "<nobody>";
    request[2] = "check-permission";
    request[3] = user;
    request[4] = acl;
    CellMessage reply;
    try {
        reply = _nucleus.sendAndWait(new CellMessage(_aclPath, request), ACL_TIMEOUT);
        if (reply == null) {
            throw new CommandException("Error in acl handling : Acl Request timed out (" + _aclPath + ')');
        }
    } catch (NoRouteToCellException | ExecutionException | InterruptedException e) {
        throw new CommandException("Error in acl handling: " + e.getMessage(), e);
    }
    Object r = reply.getMessageObject();
    if ((r == null) || (!(r instanceof Object[])) || (((Object[]) r).length < 6) || (!(((Object[]) r)[5] instanceof Boolean))) {
        throw new CommandException("Error in acl handling: illegal reply arrived");
    }
    if (!((Boolean) ((Object[]) r)[5])) {
        throw new CommandAclException(user, acl);
    }
}
Also used : CommandException(dmg.util.CommandException) ExecutionException(java.util.concurrent.ExecutionException) CommandAclException(dmg.util.CommandAclException)

Example 2 with CommandAclException

use of dmg.util.CommandAclException in project dcache by dCache.

the class CellAdapter method checkAclPermission.

protected void checkAclPermission(Authorizable auth, Object command, String[] acls) throws CommandException {
    String user = auth.getAuthorizedPrincipal();
    if (user.equals("admin") || acls.length == 0) {
        return;
    }
    CommandException recentException = null;
    for (String acl : acls) {
        try {
            checkAclPermission(user, command, acl);
            return;
        } catch (CommandAclException ce) {
            recentException = ce;
        }
    }
    throw recentException;
}
Also used : AuthorizedString(dmg.util.AuthorizedString) CommandException(dmg.util.CommandException) CommandAclException(dmg.util.CommandAclException)

Example 3 with CommandAclException

use of dmg.util.CommandAclException in project dcache by dCache.

the class DirectCommand method executeCommands.

private void executeCommands() {
    for (String command : commands) {
        Object error = null;
        try {
            Object result = shell.executeCommand(command);
            String s = Strings.toString(result);
            if (!s.isEmpty()) {
                outWriter.println(s);
            }
            outWriter.flush();
        } catch (IllegalArgumentException e) {
            error = e.toString();
        } catch (SerializationException e) {
            error = "There is a bug here, please report to support@dcache.org";
            LOGGER.error("This must be a bug, please report to support@dcache.org.", e);
        } catch (CommandSyntaxException e) {
            error = e;
        } catch (CommandEvaluationException | CommandAclException e) {
            error = e.getMessage();
        } catch (CommandExitException e) {
            break;
        } catch (CommandPanicException e) {
            error = String.format("Command '%s' triggered a bug (%s);" + "the service log file contains additional information. Please " + "contact support@dcache.org.", command, e.getTargetException());
        } catch (CommandException e) {
            error = e.getMessage();
        } catch (NoRouteToCellException e) {
            error = "Cell name does not exist or cell is not started: " + e.getMessage();
            LOGGER.warn("Command cannot be executed in the cell, cell is gone {}", e.getMessage());
        } catch (RuntimeException e) {
            error = String.format("Command '%s' triggered a bug (%s); please" + " locate this message in the log file of the admin service and" + " send an email to support@dcache.org with this line and the" + " following stack-trace", command, e);
            LOGGER.error((String) error, e);
        } catch (Exception e) {
            error = e.getMessage();
            if (error == null) {
                error = e.getClass().getSimpleName() + ": (null)";
            }
        }
        if (error != null) {
            if (error instanceof CommandSyntaxException) {
                CommandSyntaxException e = (CommandSyntaxException) error;
                errorWriter.append("Syntax error: ").println(e.getMessage());
            } else {
                errorWriter.println(error);
            }
            errorWriter.flush();
        }
    }
}
Also used : SerializationException(dmg.cells.nucleus.SerializationException) CommandEvaluationException(dmg.util.CommandEvaluationException) CommandException(dmg.util.CommandException) CommandExitException(dmg.util.CommandExitException) CommandException(dmg.util.CommandException) CommandAclException(dmg.util.CommandAclException) CommandPanicException(dmg.util.CommandPanicException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CommandSyntaxException(dmg.util.CommandSyntaxException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandEvaluationException(dmg.util.CommandEvaluationException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandAclException(dmg.util.CommandAclException) CommandPanicException(dmg.util.CommandPanicException)

Example 4 with CommandAclException

use of dmg.util.CommandAclException in project dcache by dCache.

the class NoTerminalCommand method repl.

private void repl() throws IOException {
    Ansi.setEnabled(false);
    while (true) {
        Object error = null;
        try {
            String str = _reader.readLine();
            try {
                if (str == null) {
                    throw new CommandExitException();
                }
                Object result = _userAdminShell.executeCommand(str);
                String s = Strings.toString(result);
                if (!s.isEmpty()) {
                    _writer.println(s);
                }
                _writer.flush();
            } catch (IllegalArgumentException e) {
                error = e.toString();
            } catch (SerializationException e) {
                error = "There is a bug here, please report to support@dcache.org";
                LOGGER.error("This must be a bug, please report to support@dcache.org.", e);
            } catch (CommandSyntaxException e) {
                error = e;
            } catch (CommandEvaluationException | CommandAclException e) {
                error = e.getMessage();
            } catch (CommandExitException e) {
                break;
            } catch (CommandPanicException e) {
                error = "Command '" + str + "' triggered a bug (" + e.getTargetException() + "); the service log file contains additional information. Please " + "contact support@dcache.org.";
            } catch (CommandException e) {
                error = e.getMessage();
            } catch (NoRouteToCellException e) {
                error = "Cell name does not exist or cell is not started: " + e.getMessage();
                LOGGER.warn("The cell the command was sent to is no " + "longer there: {}", e.getMessage());
            } catch (RuntimeException e) {
                error = String.format("Command '%s' triggered a bug (%s); please" + " locate this message in the log file of the admin service and" + " send an email to support@dcache.org with this line and the" + " following stack-trace", str, e);
                LOGGER.error((String) error, e);
            }
        } catch (InterruptedException e) {
            error = null;
        } catch (IOException e) {
            throw e;
        } catch (Exception e) {
            error = e.getMessage();
            if (error == null) {
                error = e.getClass().getSimpleName() + ": (null)";
            }
        }
        if (error != null) {
            if (error instanceof CommandSyntaxException) {
                CommandSyntaxException e = (CommandSyntaxException) error;
                _error.append("Syntax error: ").println(e.getMessage());
            } else {
                _error.println(error);
            }
            _error.flush();
        }
    }
}
Also used : SerializationException(dmg.cells.nucleus.SerializationException) CommandEvaluationException(dmg.util.CommandEvaluationException) CommandException(dmg.util.CommandException) IOException(java.io.IOException) CommandExitException(dmg.util.CommandExitException) CommandException(dmg.util.CommandException) CommandAclException(dmg.util.CommandAclException) IOException(java.io.IOException) CommandPanicException(dmg.util.CommandPanicException) CommandExitException(dmg.util.CommandExitException) SerializationException(dmg.cells.nucleus.SerializationException) CommandSyntaxException(dmg.util.CommandSyntaxException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandEvaluationException(dmg.util.CommandEvaluationException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) CommandSyntaxException(dmg.util.CommandSyntaxException) CommandAclException(dmg.util.CommandAclException) CommandPanicException(dmg.util.CommandPanicException)

Aggregations

CommandAclException (dmg.util.CommandAclException)4 CommandException (dmg.util.CommandException)4 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)2 SerializationException (dmg.cells.nucleus.SerializationException)2 CommandEvaluationException (dmg.util.CommandEvaluationException)2 CommandExitException (dmg.util.CommandExitException)2 CommandPanicException (dmg.util.CommandPanicException)2 CommandSyntaxException (dmg.util.CommandSyntaxException)2 AuthorizedString (dmg.util.AuthorizedString)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1