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