use of dmg.util.AclException in project dcache by dCache.
the class UserAdminShell method sendToMany.
/**
* Concurrently sends a command to several cells and collects the result from each.
*/
private String sendToMany(Iterable<String> destinations, Serializable object) throws AclException {
/* Check permissions */
try {
checkPermission("cell.*.execute");
} catch (AclException e) {
for (String cell : destinations) {
checkPermission("cell." + cell + ".execute");
}
}
/* Submit */
List<Map.Entry<String, ListenableFuture<Serializable>>> futures = new ArrayList<>();
for (String cell : destinations) {
futures.add(immutableEntry(cell, _cellStub.send(new CellPath(cell), object, Serializable.class, _timeout)));
}
/* Collect results */
StringBuilder result = new StringBuilder();
for (Map.Entry<String, ListenableFuture<Serializable>> entry : futures) {
result.append(Ansi.ansi().bold().a(entry.getKey()).boldOff()).append(":");
try {
String reply = Objects.toString(entry.getValue().get(), "");
if (reply.isEmpty()) {
result.append(Ansi.ansi().fg(GREEN).a(" OK").reset()).append("\n");
} else {
result.append("\n");
for (String s : reply.split("\n")) {
result.append(" ").append(s).append("\n");
}
}
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NoRouteToCellException) {
result.append(Ansi.ansi().fg(RED).a(" Cell is unreachable.").reset()).append("\n");
} else {
result.append(" ").append(Ansi.ansi().fg(RED).a(cause.getMessage()).reset()).append("\n");
}
} catch (InterruptedException e) {
result.append(" ^C\n");
/* Cancel all uncompleted tasks. Doesn't actually cancel any requests, but will cause
* the remaining uncompleted futures to throw a CancellationException.
*/
for (Map.Entry<String, ListenableFuture<Serializable>> entry2 : futures) {
entry2.getValue().cancel(true);
}
} catch (CancellationException e) {
result.append(" ^C\n");
}
}
return result.toString();
}
use of dmg.util.AclException in project dcache by dCache.
the class UserAdminShell method checkPermission.
/**
* Checks that the current effective user has the given acl.
*
* @throws AclException if the current user does not have the given {@code aclName}
*/
public void checkPermission(String aclName) throws AclException {
Object[] request = new Object[5];
request[0] = "request";
request[1] = "<nobody>";
request[2] = "check-permission";
request[3] = getUser();
request[4] = aclName;
Object[] r;
try {
r = _acmStub.sendAndWait(request, Object[].class);
} catch (TimeoutCacheException | NoRouteToCellException e) {
throw new AclException(e.getMessage());
} catch (CacheException | InterruptedException e) {
throw new AclException("Problem: " + e.getMessage());
}
if (r.length < 6 || !(r[5] instanceof Boolean)) {
throw new AclException("Protocol violation 4456");
}
if (!((Boolean) r[5])) {
throw new AclException(getUser(), aclName);
}
}
use of dmg.util.AclException in project dcache by dCache.
the class LegacyAdminShell method checkCdPermission.
private void checkCdPermission(String remoteName) throws AclException {
int pos = remoteName.indexOf('-');
String prefix = null;
if (pos > 0) {
prefix = remoteName.substring(0, pos);
}
try {
checkPermission("cell.*.execute");
} catch (AclException acle) {
try {
checkPermission("cell." + remoteName + ".execute");
} catch (AclException acle2) {
if (prefix == null) {
throw acle2;
}
try {
checkPermission("cell." + prefix + "-pools.execute");
} catch (AclException acle3) {
throw new AclException(getUser(), remoteName);
}
}
}
}
use of dmg.util.AclException in project dcache by dCache.
the class RemotePermission method checkPermission.
@Override
public void checkPermission(Authorizable auth, String aclName) throws AclException {
Object[] request = new Object[5];
request[0] = "request";
request[1] = "<nobody>";
request[2] = "check-permission";
request[3] = auth.getAuthorizedPrincipal();
request[4] = aclName;
CellMessage reply;
try {
reply = _cell.getNucleus().sendAndWait(new CellMessage(_path, request), _timeout);
if (reply == null) {
throw new AclException("Request timed out (" + _path + ')');
}
} catch (Exception ee) {
throw new AclException("Problem : " + ee.getMessage());
}
Object r = reply.getMessageObject();
if ((r == null) || (!(r instanceof Object[])) || (((Object[]) r).length < 6) || (!(((Object[]) r)[5] instanceof Boolean))) {
throw new AclException("Protocol violation 4456");
}
if (!((Boolean) ((Object[]) r)[5])) {
throw new AclException(auth, aclName);
}
}
use of dmg.util.AclException in project dcache by dCache.
the class UserAdminShell method completeRemote.
/**
* Completes remote commands using a particular cell as a source for completion candidates.
*/
private int completeRemote(CellPath cell, String buffer, int cursor, List<CharSequence> candidates) {
try {
Serializable help = sendObject(cell, "help");
if (help == null) {
return -1;
}
HelpCompleter completer = new HelpCompleter(String.valueOf(help));
return completer.complete(buffer, cursor, candidates);
} catch (NoRouteToCellException | CommandException | AclException e) {
LOGGER.info("Completion failed: {}", e.toString());
return -1;
} catch (InterruptedException e) {
return -1;
}
}
Aggregations