use of org.apache.sshd.common.future.CloseFuture 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;
}
use of org.apache.sshd.common.future.CloseFuture in project gerrit by GerritCodeReview.
the class CloseConnection method run.
@Override
protected void run() throws Failure {
IoAcceptor acceptor = sshDaemon.getIoAcceptor();
if (acceptor == null) {
throw new Failure(1, "fatal: sshd no longer running");
}
for (String sessionId : sessionIds) {
boolean connectionFound = false;
int id = (int) Long.parseLong(sessionId, 16);
for (IoSession io : acceptor.getManagedSessions().values()) {
AbstractSession serverSession = AbstractSession.getSession(io, true);
SshSession sshSession = serverSession != null ? serverSession.getAttribute(SshSession.KEY) : null;
if (sshSession != null && sshSession.getSessionId() == id) {
connectionFound = true;
stdout.println("closing connection " + sessionId + "...");
CloseFuture future = io.close(true);
if (wait) {
try {
future.await();
stdout.println("closed connection " + sessionId);
} catch (IOException e) {
log.warn("Wait for connection to close interrupted: " + e.getMessage());
}
}
break;
}
}
if (!connectionFound) {
stderr.print("close connection " + sessionId + ": no such connection\n");
}
}
}
use of org.apache.sshd.common.future.CloseFuture in project gerrit by GerritCodeReview.
the class SshUtil method success.
public static boolean success(final String username, final ServerSession session, final SshScope sshScope, final SshLog sshLog, final SshSession sd, final CurrentUser user) {
if (sd.getUser() == null) {
sd.authenticationSuccess(username, user);
// If this is the first time we've authenticated this
// session, record a login event in the log and add
// a close listener to record a logout event.
//
Context ctx = sshScope.newContext(null, sd, null);
Context old = sshScope.set(ctx);
try {
sshLog.onLogin();
} finally {
sshScope.set(old);
}
session.addCloseFutureListener(new SshFutureListener<CloseFuture>() {
@Override
public void operationComplete(CloseFuture future) {
final Context ctx = sshScope.newContext(null, sd, null);
final Context old = sshScope.set(ctx);
try {
sshLog.onLogout();
} finally {
sshScope.set(old);
}
}
});
}
return true;
}
Aggregations