From 61b32fe07e3eb76a7dfbceb66a7758eac5f308ee Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 14 Mar 2014 15:36:55 -0400 Subject: Rename server session classes --- .../transport/ssh/GitblitServerSession.java | 35 ---------- .../java/com/gitblit/transport/ssh/SshDaemon.java | 2 +- .../gitblit/transport/ssh/SshServerSession.java | 34 ++++++++++ .../transport/ssh/SshServerSessionFactory.java | 72 ++++++++++++++++++++ .../gitblit/transport/ssh/SshSessionFactory.java | 77 ---------------------- 5 files changed, 107 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java create mode 100644 src/main/java/com/gitblit/transport/ssh/SshServerSession.java create mode 100644 src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java delete mode 100644 src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java diff --git a/src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java b/src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java deleted file mode 100644 index e5336025..00000000 --- a/src/main/java/com/gitblit/transport/ssh/GitblitServerSession.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2014 gitblit.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gitblit.transport.ssh; - -import org.apache.sshd.common.future.CloseFuture; -import org.apache.sshd.common.future.SshFutureListener; -import org.apache.sshd.common.io.IoSession; -import org.apache.sshd.server.ServerFactoryManager; -import org.apache.sshd.server.session.ServerSession; - -// Expose addition of close session listeners -class GitblitServerSession extends ServerSession { - - GitblitServerSession(ServerFactoryManager server, IoSession ioSession) - throws Exception { - super(server, ioSession); - } - - void addCloseSessionListener(SshFutureListener l) { - closeFuture.addListener(l); - } -} diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java index 5415779e..c11cb1f6 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java +++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java @@ -126,7 +126,7 @@ public class SshDaemon { gitblit.getBaseFolder(), HOST_KEY_STORE).getPath())); sshd.setPublickeyAuthenticator(publickeyAuthenticator); sshd.setPasswordAuthenticator(new UsernamePasswordAuthenticator(gitblit)); - sshd.setSessionFactory(new SshSessionFactory()); + sshd.setSessionFactory(new SshServerSessionFactory()); sshd.setFileSystemFactory(new DisabledFilesystemFactory()); sshd.setTcpipForwardingFilter(new NonForwardingFilter()); diff --git a/src/main/java/com/gitblit/transport/ssh/SshServerSession.java b/src/main/java/com/gitblit/transport/ssh/SshServerSession.java new file mode 100644 index 00000000..d12a6be2 --- /dev/null +++ b/src/main/java/com/gitblit/transport/ssh/SshServerSession.java @@ -0,0 +1,34 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.transport.ssh; + +import org.apache.sshd.common.future.CloseFuture; +import org.apache.sshd.common.future.SshFutureListener; +import org.apache.sshd.common.io.IoSession; +import org.apache.sshd.server.ServerFactoryManager; +import org.apache.sshd.server.session.ServerSession; + +// Expose addition of close session listeners +class SshServerSession extends ServerSession { + + SshServerSession(ServerFactoryManager server, IoSession ioSession) throws Exception { + super(server, ioSession); + } + + void addCloseSessionListener(SshFutureListener l) { + closeFuture.addListener(l); + } +} diff --git a/src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java b/src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java new file mode 100644 index 00000000..dd3c139d --- /dev/null +++ b/src/main/java/com/gitblit/transport/ssh/SshServerSessionFactory.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.transport.ssh; + +import java.net.SocketAddress; + +import org.apache.mina.transport.socket.SocketSessionConfig; +import org.apache.sshd.common.future.CloseFuture; +import org.apache.sshd.common.future.SshFutureListener; +import org.apache.sshd.common.io.IoSession; +import org.apache.sshd.common.io.mina.MinaSession; +import org.apache.sshd.common.session.AbstractSession; +import org.apache.sshd.server.session.SessionFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author James Moger + * + */ +public class SshServerSessionFactory extends SessionFactory { + + private final Logger log = LoggerFactory.getLogger(getClass()); + + public SshServerSessionFactory() { + } + + @Override + protected AbstractSession createSession(final IoSession io) throws Exception { + log.info("connection accepted on " + io); + + 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() { + @Override + public void operationComplete(CloseFuture future) { + log.info("connection closed on " + io); + } + }); + return session; + } + + @Override + protected AbstractSession doCreateSession(IoSession ioSession) throws Exception { + return new SshServerSession(server, ioSession); + } +} diff --git a/src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java b/src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java deleted file mode 100644 index 66fe057d..00000000 --- a/src/main/java/com/gitblit/transport/ssh/SshSessionFactory.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2014 gitblit.com. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gitblit.transport.ssh; - -import java.net.SocketAddress; - -import org.apache.mina.transport.socket.SocketSessionConfig; -import org.apache.sshd.common.future.CloseFuture; -import org.apache.sshd.common.future.SshFutureListener; -import org.apache.sshd.common.io.IoSession; -import org.apache.sshd.common.io.mina.MinaSession; -import org.apache.sshd.common.session.AbstractSession; -import org.apache.sshd.server.session.SessionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * - * @author James Moger - * - */ -public class SshSessionFactory extends SessionFactory { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - public SshSessionFactory() { - } - - @Override - protected AbstractSession createSession(final IoSession io) - throws Exception { - log.info("connection accepted on " + io); - - if (io instanceof MinaSession) { - if (((MinaSession) io).getSession().getConfig() instanceof SocketSessionConfig) { - ((SocketSessionConfig) ((MinaSession) io).getSession() - .getConfig()).setKeepAlive(true); - } - } - - final GitblitServerSession session = (GitblitServerSession) 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() { - @Override - public void operationComplete(CloseFuture future) { - log.info("connection closed on " + io); - } - }); - return session; - } - - @Override - protected AbstractSession doCreateSession(IoSession ioSession) - throws Exception { - return new GitblitServerSession(server, ioSession); - } -} -- cgit v1.2.3