You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2009/03/17 10:08:43 UTC

svn commit: r755158 - in /mina/sshd/trunk/src/main/java/org/apache/sshd: SshServer.java server/SessionFactory.java

Author: gnodet
Date: Tue Mar 17 09:08:41 2009
New Revision: 755158

URL: http://svn.apache.org/viewvc?rev=755158&view=rev
Log:
SSHD-17: Custom session handler factory

Added:
    mina/sshd/trunk/src/main/java/org/apache/sshd/server/SessionFactory.java
Modified:
    mina/sshd/trunk/src/main/java/org/apache/sshd/SshServer.java

Modified: mina/sshd/trunk/src/main/java/org/apache/sshd/SshServer.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/SshServer.java?rev=755158&r1=755157&r2=755158&view=diff
==============================================================================
--- mina/sshd/trunk/src/main/java/org/apache/sshd/SshServer.java (original)
+++ mina/sshd/trunk/src/main/java/org/apache/sshd/SshServer.java Tue Mar 17 09:08:41 2009
@@ -56,6 +56,7 @@
 import org.apache.sshd.server.session.ServerSession;
 import org.apache.sshd.server.ShellFactory;
 import org.apache.sshd.server.UserAuth;
+import org.apache.sshd.server.SessionFactory;
 import org.apache.sshd.server.CommandFactory;
 import org.apache.sshd.server.auth.UserAuthPassword;
 import org.apache.sshd.server.auth.UserAuthPublicKey;
@@ -98,6 +99,7 @@
     private List<NamedFactory<UserAuth>> userAuthFactories;
     private List<NamedFactory<ServerChannel>> channelFactories;
     private ShellFactory shellFactory;
+    private SessionFactory sessionFactory;
     private CommandFactory commandFactory;
     private PasswordAuthenticator passwordAuthenticator;
     private PublickeyAuthenticator publickeyAuthenticator;
@@ -142,6 +144,14 @@
         this.shellFactory = shellFactory;
     }
 
+    public SessionFactory getSessionFactory() {
+        return sessionFactory;
+    }
+
+    public void setSessionFactory(SessionFactory sessionFactory) {
+        this.sessionFactory = sessionFactory;
+    }
+
     public CommandFactory getCommandFactory() {
         return commandFactory;
     }
@@ -204,11 +214,14 @@
     public void start() throws IOException {
         checkConfig();
         acceptor = new NioSocketAcceptor();
-        acceptor.setHandler(new AbstractSessionIoHandler() {
-            protected AbstractSession createSession(IoSession ioSession) throws Exception {
-                return new ServerSession(SshServer.this, ioSession);
-            }
-        });
+
+        SessionFactory handler = sessionFactory;
+        if (handler == null) {
+            handler = new SessionFactory();
+        }
+        handler.setServer(this);
+        acceptor.setHandler((AbstractSessionIoHandler)handler);
+
         acceptor.bind(new InetSocketAddress(port));
     }
 

Added: mina/sshd/trunk/src/main/java/org/apache/sshd/server/SessionFactory.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/main/java/org/apache/sshd/server/SessionFactory.java?rev=755158&view=auto
==============================================================================
--- mina/sshd/trunk/src/main/java/org/apache/sshd/server/SessionFactory.java (added)
+++ mina/sshd/trunk/src/main/java/org/apache/sshd/server/SessionFactory.java Tue Mar 17 09:08:41 2009
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.sshd.server;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
+import org.apache.mina.core.session.IoSession;
+
+import org.apache.sshd.common.session.AbstractSession;
+import org.apache.sshd.common.AbstractSessionIoHandler;
+
+import org.apache.sshd.SshServer;
+import org.apache.sshd.server.session.ServerSession;
+
+/**
+ * A factory of sessions.
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ */
+public class SessionFactory extends AbstractSessionIoHandler {
+
+    protected SshServer server;
+
+    public void setServer(SshServer server) {
+        this.server = server;
+    }
+
+    protected AbstractSession createSession(IoSession ioSession) throws Exception {
+        return new ServerSession(server, ioSession);
+    }
+
+}