Search in sources :

Example 1 with AuthorizedString

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

the class UserSecurityCell method messageArrived.

@Override
public void messageArrived(CellMessage msg) {
    Serializable obj = msg.getMessageObject();
    Serializable answer;
    try {
        _log.info("Message type : {}", obj.getClass());
        if ((obj instanceof Object[]) && (((Object[]) obj).length >= 3) && (((Object[]) obj)[0].equals("request"))) {
            Object[] request = (Object[]) obj;
            String user = request[1] == null ? "unknown" : (String) request[1];
            String command = (String) request[2];
            _log.info('>' + command + "< request from " + user);
            // FIXME: refactoring required
            try {
                if (command.equals("check-password")) {
                    answer = acl_check_password(request);
                } else {
                    throw new Exception("Command not found : " + command);
                }
            } catch (Exception xe) {
                throw new Exception("Problem : " + xe);
            }
        } else if (obj instanceof AuthorizedString) {
            String command = obj.toString();
            String user = ((Authorizable) obj).getAuthorizedPrincipal();
            answer = execAuthorizedString(user, command);
        } else {
            String r = "Illegal message object received from : " + msg.getSourcePath();
            _log.warn(r);
            throw new Exception(r);
        }
    } catch (Exception iex) {
        answer = iex;
    }
    if (answer instanceof Object[]) {
        ((Object[]) answer)[0] = "response";
    }
    msg.revertDirection();
    msg.setMessageObject(answer);
    try {
        sendMessage(msg);
    } catch (RuntimeException ioe) {
        _log.warn("Can't send acl_response : " + ioe, ioe);
    }
}
Also used : Serializable(java.io.Serializable) AuthorizedString(dmg.util.AuthorizedString) AuthorizedString(dmg.util.AuthorizedString) CommandThrowableException(dmg.util.CommandThrowableException) CommandPanicException(dmg.util.CommandPanicException) CommandSyntaxException(dmg.util.CommandSyntaxException)

Example 2 with AuthorizedString

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

the class UserAdminShell method executeCommand.

public Object executeCommand(String str) throws CommandException, InterruptedException, NoRouteToCellException, AclException {
    LOGGER.info("String command (super) {}", str);
    if (str.trim().isEmpty()) {
        return "";
    }
    Args args = new Args(str);
    Optional<CellPath> destination = _currentPosition == null || str.startsWith("\\") ? Optional.empty() : Optional.ofNullable(_currentPosition.remote);
    new NetLoggerBuilder(NetLoggerBuilder.Level.INFO, "org.dcache.services.ssh2.exec").omitNullValues().onLogger(ACCESS_LOGGER).add("session", _session).add("cmd.destination", destination.map(Object::toString).orElse(null)).add("cmd.args", str).log();
    if (destination.isPresent()) {
        return sendObject(destination.get(), new AuthorizedString(_user, str));
    } else {
        return localCommand(args);
    }
}
Also used : CellPath(dmg.cells.nucleus.CellPath) Args(org.dcache.util.Args) AuthorizedString(dmg.util.AuthorizedString) NetLoggerBuilder(org.dcache.util.NetLoggerBuilder)

Example 3 with AuthorizedString

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

the class LegacyAdminShell method executeCommand.

public Object executeCommand(String str) throws CommandException, InterruptedException, NoRouteToCellException {
    LOGGER.info("String command (super) {}", str);
    if (str.trim().isEmpty()) {
        return "";
    }
    if (str.equals("..")) {
        _currentPosition.clearHyperMode();
        _currentPosition.gotoLocal();
        return "";
    }
    Args args = new Args(str);
    if (_currentPosition.remote == null) {
        return localCommand(args);
    } else {
        if (_currentPosition.hyperMode) {
            if ((args.argc() == 1) && (args.argv(0).equals("cd"))) {
                _currentPosition.gotoLocal();
                return "";
            } else if ((args.argc() > 1) && (args.argv(0).equals("cd"))) {
                return localCommand(args);
            }
            String prefix = _currentPosition.getPrefix();
            if (!prefix.isEmpty()) {
                if ((args.argc() >= 1) && (args.argv(0).equals("help"))) {
                    if (args.argc() == 1) {
                        str = "help " + prefix;
                    }
                } else {
                    str = prefix + " " + str;
                }
            }
        }
        return sendObject(_currentPosition.remote, new AuthorizedString(_user, str));
    }
}
Also used : Args(org.dcache.util.Args) AuthorizedString(dmg.util.AuthorizedString) AuthorizedString(dmg.util.AuthorizedString)

Example 4 with AuthorizedString

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

the class SystemCell method messageArrived.

@Override
public void messageArrived(CellMessage msg) {
    _log.info("Message arrived : {}", msg);
    _packetsReceived++;
    if (msg.isReply()) {
        _log.warn("Seems to a bounce : {}", msg);
        return;
    }
    Object obj = msg.getMessageObject();
    Serializable reply;
    if (obj instanceof String) {
        String command = (String) obj;
        if (command.isEmpty()) {
            return;
        }
        _log.info("Command: {}", command);
        if (command.equals("xyzzy")) {
            reply = "Nothing happens.";
        } else {
            reply = _cellShell.objectCommand2(command);
        }
    } else if (obj instanceof AuthorizedString) {
        AuthorizedString as = (AuthorizedString) obj;
        String command = as.toString();
        if (command.length() < 1) {
            return;
        }
        _log.info("Command(p={}) : {}", as.getAuthorizedPrincipal(), command);
        reply = _cellShell.objectCommand2(command);
    } else {
        return;
    }
    _log.debug("Reply : {}", reply);
    _packetsAnswered++;
    try {
        if (reply instanceof Reply) {
            ((Reply) reply).deliver(this, msg);
        } else {
            msg.revertDirection();
            msg.setMessageObject(reply);
            sendMessage(msg);
            _log.debug("Sending : {}", msg);
        }
        _packetsReplied++;
    } catch (RuntimeException e) {
        _exceptionCounter++;
    }
}
Also used : Serializable(java.io.Serializable) AuthorizedString(dmg.util.AuthorizedString) AuthorizedString(dmg.util.AuthorizedString)

Example 5 with AuthorizedString

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

the class CellAdapter method messageArrived.

/**
 * belongs to the Cell Interface. If this method is overwritten, the messageArrived(CellMessage
 * cm) and the messageToForward(CellMessage) methods are never called.
 */
@Override
public void messageArrived(MessageEvent me) {
    CellMessage msg = me.getMessage();
    Serializable obj = msg.getMessageObject();
    if (msg.isFinalDestination()) {
        if (!msg.isReply() && msg.getLocalAge() > msg.getAdjustedTtl()) {
            _log.warn("Discarding {} because its age of {} ms exceeds its time to live of {} ms.", (obj instanceof CharSequence) ? '\'' + Ascii.truncate((CharSequence) obj, 50, "...") + '\'' : obj.getClass().getSimpleName(), msg.getLocalAge(), msg.getAdjustedTtl());
            return;
        }
        if (_useInterpreter && (!msg.isReply()) && ((obj instanceof String) || (obj instanceof AuthorizedString))) {
            Serializable o;
            UOID uoid = msg.getUOID();
            EventLogger.deliverBegin(msg);
            try {
                o = executeLocalCommand(obj);
                if (o == null) {
                    return;
                }
            } catch (CommandPanicException e) {
                o = e;
                _log.error("Command failed due to a bug, please contact support@dcache.org.", e);
            } catch (CommandException ce) {
                o = ce;
            } finally {
                EventLogger.deliverEnd(msg.getSession(), uoid);
            }
            if (o instanceof Reply) {
                Reply reply = (Reply) o;
                reply.deliver(this, msg);
            } else {
                msg.revertDirection();
                msg.setMessageObject(o);
                _nucleus.sendMessage(msg, true, true, true);
            }
        } else if ((obj instanceof PingMessage) && _answerPing) {
            PingMessage ping = (PingMessage) obj;
            if (ping.isWayBack()) {
                messageArrived(msg);
                return;
            }
            ping.setWayBack();
            ping.setOutboundPath(msg.getSourcePath());
            msg.revertDirection();
            _nucleus.sendMessage(msg, true, true, true);
        } else {
            UOID uoid = msg.getUOID();
            EventLogger.deliverBegin(msg);
            try {
                messageArrived(msg);
            } finally {
                EventLogger.deliverEnd(msg.getSession(), uoid);
            }
        }
    } else if (obj instanceof PingMessage) {
        _nucleus.sendMessage(msg, true, true, true);
    } else {
        UOID uoid = msg.getUOID();
        EventLogger.deliverBegin(msg);
        try {
            messageToForward(msg);
        } finally {
            EventLogger.deliverEnd(msg.getSession(), uoid);
        }
    }
}
Also used : Serializable(java.io.Serializable) AuthorizedString(dmg.util.AuthorizedString) AuthorizedString(dmg.util.AuthorizedString) CommandException(dmg.util.CommandException) PingMessage(dmg.cells.network.PingMessage) CommandPanicException(dmg.util.CommandPanicException)

Aggregations

AuthorizedString (dmg.util.AuthorizedString)5 Serializable (java.io.Serializable)3 CommandPanicException (dmg.util.CommandPanicException)2 Args (org.dcache.util.Args)2 PingMessage (dmg.cells.network.PingMessage)1 CellPath (dmg.cells.nucleus.CellPath)1 CommandException (dmg.util.CommandException)1 CommandSyntaxException (dmg.util.CommandSyntaxException)1 CommandThrowableException (dmg.util.CommandThrowableException)1 NetLoggerBuilder (org.dcache.util.NetLoggerBuilder)1