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);
}
}
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;
}
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();
}
}
}
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();
}
}
}
Aggregations