Search in sources :

Example 1 with MinaSession

use of org.apache.sshd.common.io.mina.MinaSession in project gitblit by gitblit.

the class SshServerSessionFactory method createSession.

@Override
protected AbstractSession createSession(final IoSession io) throws Exception {
    log.info("creating ssh session from {}", io.getRemoteAddress());
    if (io instanceof MinaSession) {
        if (((MinaSession) io).getSession().getConfig() instanceof SocketSessionConfig) {
            ((SocketSessionConfig) ((MinaSession) io).getSession().getConfig()).setKeepAlive(true);
        }
    }
    final SshServerSession session = (SshServerSession) super.createSession(io);
    SocketAddress peer = io.getRemoteAddress();
    SshDaemonClient client = new SshDaemonClient(peer);
    session.setAttribute(SshDaemonClient.KEY, client);
    // TODO(davido): Log a session close without authentication as a
    // failure.
    session.addCloseSessionListener(new SshFutureListener<CloseFuture>() {

        @Override
        public void operationComplete(CloseFuture future) {
            log.info("closed ssh session from {}", io.getRemoteAddress());
        }
    });
    return session;
}
Also used : CloseFuture(org.apache.sshd.common.future.CloseFuture) MinaSession(org.apache.sshd.common.io.mina.MinaSession) SocketAddress(java.net.SocketAddress) SocketSessionConfig(org.apache.mina.transport.socket.SocketSessionConfig)

Example 2 with MinaSession

use of org.apache.sshd.common.io.mina.MinaSession in project gerrit by GerritCodeReview.

the class ShowCaches method sshSummary.

private void sshSummary() {
    IoAcceptor acceptor = daemon.getIoAcceptor();
    if (acceptor == null) {
        return;
    }
    long now = TimeUtil.nowMs();
    Collection<IoSession> list = acceptor.getManagedSessions().values();
    long oldest = now;
    for (IoSession s : list) {
        if (s instanceof MinaSession) {
            MinaSession minaSession = (MinaSession) s;
            oldest = Math.min(oldest, minaSession.getSession().getCreationTime());
        }
    }
    stdout.format("SSH:   %4d  users, oldest session started %s ago\n", list.size(), uptime(now - oldest));
}
Also used : IoAcceptor(org.apache.sshd.common.io.IoAcceptor) MinaSession(org.apache.sshd.common.io.mina.MinaSession) IoSession(org.apache.sshd.common.io.IoSession)

Example 3 with MinaSession

use of org.apache.sshd.common.io.mina.MinaSession in project gerrit by GerritCodeReview.

the class ShowConnections method run.

@Override
protected void run() throws Failure {
    final IoAcceptor acceptor = daemon.getIoAcceptor();
    if (acceptor == null) {
        throw new Failure(1, "fatal: sshd no longer running");
    }
    final List<IoSession> list = new ArrayList<>(acceptor.getManagedSessions().values());
    Collections.sort(list, new Comparator<IoSession>() {

        @Override
        public int compare(IoSession arg0, IoSession arg1) {
            if (arg0 instanceof MinaSession) {
                MinaSession mArg0 = (MinaSession) arg0;
                MinaSession mArg1 = (MinaSession) arg1;
                if (mArg0.getSession().getCreationTime() < mArg1.getSession().getCreationTime()) {
                    return -1;
                } else if (mArg0.getSession().getCreationTime() > mArg1.getSession().getCreationTime()) {
                    return 1;
                }
            }
            return (int) (arg0.getId() - arg1.getId());
        }
    });
    hostNameWidth = wide ? Integer.MAX_VALUE : columns - 9 - 9 - 10 - 32;
    if (getBackend().equals("mina")) {
        long now = TimeUtil.nowMs();
        stdout.print(String.format("%-8s %8s %8s   %-15s %s\n", "Session", "Start", "Idle", "User", "Remote Host"));
        stdout.print("--------------------------------------------------------------\n");
        for (final IoSession io : list) {
            checkState(io instanceof MinaSession, "expected MinaSession");
            MinaSession minaSession = (MinaSession) io;
            long start = minaSession.getSession().getCreationTime();
            long idle = now - minaSession.getSession().getLastIoTime();
            AbstractSession s = AbstractSession.getSession(io, true);
            SshSession sd = s != null ? s.getAttribute(SshSession.KEY) : null;
            stdout.print(String.format("%8s %8s %8s   %-15.15s %s\n", id(sd), time(now, start), age(idle), username(sd), hostname(io.getRemoteAddress())));
        }
    } else {
        stdout.print(String.format("%-8s   %-15s %s\n", "Session", "User", "Remote Host"));
        stdout.print("--------------------------------------------------------------\n");
        for (final IoSession io : list) {
            AbstractSession s = AbstractSession.getSession(io, true);
            SshSession sd = s != null ? s.getAttribute(SshSession.KEY) : null;
            stdout.print(String.format("%8s   %-15.15s %s\n", id(sd), username(sd), hostname(io.getRemoteAddress())));
        }
    }
    stdout.print("--\n");
    stdout.print("SSHD Backend: " + getBackend() + "\n");
}
Also used : IoAcceptor(org.apache.sshd.common.io.IoAcceptor) ArrayList(java.util.ArrayList) MinaSession(org.apache.sshd.common.io.mina.MinaSession) SshSession(com.google.gerrit.sshd.SshSession) IoSession(org.apache.sshd.common.io.IoSession) AbstractSession(org.apache.sshd.common.session.helpers.AbstractSession)

Aggregations

MinaSession (org.apache.sshd.common.io.mina.MinaSession)3 IoAcceptor (org.apache.sshd.common.io.IoAcceptor)2 IoSession (org.apache.sshd.common.io.IoSession)2 SshSession (com.google.gerrit.sshd.SshSession)1 SocketAddress (java.net.SocketAddress)1 ArrayList (java.util.ArrayList)1 SocketSessionConfig (org.apache.mina.transport.socket.SocketSessionConfig)1 CloseFuture (org.apache.sshd.common.future.CloseFuture)1 AbstractSession (org.apache.sshd.common.session.helpers.AbstractSession)1