Search in sources :

Example 1 with MinaSession

use of org.apache.sshd.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.mina.MinaSession) IoSession(org.apache.sshd.common.io.IoSession)

Example 2 with MinaSession

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

the class ShowConnections method run.

@Override
protected void run() throws Failure {
    enableGracefulStop();
    final IoAcceptor acceptor = daemon.getIoAcceptor();
    if (acceptor == null) {
        throw new Failure(1, "fatal: sshd no longer running");
    }
    final ImmutableList<IoSession> list = acceptor.getManagedSessions().values().stream().sorted((arg0, 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());
    }).collect(toImmutableList());
    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 (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 (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(String.format(" %d connections; SSHD Backend: %s\n", list.size(), getBackend()));
}
Also used : CommandMetaData(com.google.gerrit.sshd.CommandMetaData) IoAcceptor(org.apache.sshd.common.io.IoAcceptor) SocketAddress(java.net.SocketAddress) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) RequiresCapability(com.google.gerrit.extensions.annotations.RequiresCapability) Inject(com.google.inject.Inject) AbstractSession(org.apache.sshd.common.session.helpers.AbstractSession) InetAddress(java.net.InetAddress) Nio2Acceptor(org.apache.sshd.common.io.nio2.Nio2Acceptor) ImmutableList(com.google.common.collect.ImmutableList) MASTER_OR_SLAVE(com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE) MinaSession(org.apache.sshd.mina.MinaSession) CurrentUser(com.google.gerrit.server.CurrentUser) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) IoSession(org.apache.sshd.common.io.IoSession) Environment(org.apache.sshd.server.Environment) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) ZoneId(java.time.ZoneId) Preconditions.checkState(com.google.common.base.Preconditions.checkState) HexFormat(com.google.gerrit.server.ioutil.HexFormat) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) SshCommand(com.google.gerrit.sshd.SshCommand) DateTimeFormatter(java.time.format.DateTimeFormatter) MinaAcceptor(org.apache.sshd.mina.MinaAcceptor) SshDaemon(com.google.gerrit.sshd.SshDaemon) Optional(java.util.Optional) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) SshSession(com.google.gerrit.sshd.SshSession) ChannelSession(org.apache.sshd.server.channel.ChannelSession) IoAcceptor(org.apache.sshd.common.io.IoAcceptor) MinaSession(org.apache.sshd.mina.MinaSession) SshSession(com.google.gerrit.sshd.SshSession) IoSession(org.apache.sshd.common.io.IoSession) AbstractSession(org.apache.sshd.common.session.helpers.AbstractSession)

Example 3 with MinaSession

use of org.apache.sshd.mina.MinaSession in project karaf by apache.

the class KarafJaasAuthenticatorTest method init.

@Before
public void init() throws Exception {
    configuration = Configuration.getConfiguration();
    Configuration.setConfiguration(new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            return new AppConfigurationEntry[] { new AppConfigurationEntry(SayYes.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, emptyMap()) };
        }
    });
    final SshServer server = new SshServer();
    IoHandler ioHandler = new IoHandler() {

        @Override
        public void sessionCreated(IoSession ioSession) throws Exception {
        }

        @Override
        public void sessionClosed(IoSession ioSession) throws Exception {
        }

        @Override
        public void exceptionCaught(IoSession ioSession, Throwable throwable) throws Exception {
        }

        @Override
        public void messageReceived(IoSession ioSession, Readable readable) throws Exception {
        }
    };
    IoProcessor ioProcessor = new IoProcessor() {

        @Override
        public boolean isDisposing() {
            return false;
        }

        @Override
        public boolean isDisposed() {
            return false;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void add(org.apache.mina.core.session.IoSession ioSession) {
        }

        @Override
        public void flush(org.apache.mina.core.session.IoSession ioSession) {
        }

        @Override
        public void write(org.apache.mina.core.session.IoSession ioSession, WriteRequest writeRequest) {
        }

        @Override
        public void updateTrafficControl(org.apache.mina.core.session.IoSession ioSession) {
        }

        @Override
        public void remove(org.apache.mina.core.session.IoSession ioSession) {
        }
    };
    server.setRandomFactory(new SingletonRandomFactory(SecurityUtils.getRandomFactory()));
    this.session = new ServerSessionImpl(server, new MinaSession(new MinaConnector(server, ioHandler, ioProcessor), new DummySession(), SshdSocketAddress.LOCALHOST_ADDRESS));
}
Also used : Configuration(javax.security.auth.login.Configuration) WriteRequest(org.apache.mina.core.write.WriteRequest) SingletonRandomFactory(org.apache.sshd.common.random.SingletonRandomFactory) IoProcessor(org.apache.mina.core.service.IoProcessor) MinaSession(org.apache.sshd.mina.MinaSession) SshServer(org.apache.sshd.server.SshServer) IoHandler(org.apache.sshd.common.io.IoHandler) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) MinaConnector(org.apache.sshd.mina.MinaConnector) ServerSessionImpl(org.apache.sshd.server.session.ServerSessionImpl) Readable(org.apache.sshd.common.util.Readable) DummySession(org.apache.mina.core.session.DummySession) IoSession(org.apache.sshd.common.io.IoSession) Before(org.junit.Before)

Aggregations

IoSession (org.apache.sshd.common.io.IoSession)3 MinaSession (org.apache.sshd.mina.MinaSession)3 IoAcceptor (org.apache.sshd.common.io.IoAcceptor)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 GlobalCapability (com.google.gerrit.common.data.GlobalCapability)1 RequiresCapability (com.google.gerrit.extensions.annotations.RequiresCapability)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 HexFormat (com.google.gerrit.server.ioutil.HexFormat)1 TimeUtil (com.google.gerrit.server.util.time.TimeUtil)1 CommandMetaData (com.google.gerrit.sshd.CommandMetaData)1 MASTER_OR_SLAVE (com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE)1 SshCommand (com.google.gerrit.sshd.SshCommand)1 SshDaemon (com.google.gerrit.sshd.SshDaemon)1 SshSession (com.google.gerrit.sshd.SshSession)1 Inject (com.google.inject.Inject)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1