You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/09/23 02:07:26 UTC
svn commit: r578530 - in /geronimo/sandbox/gshell/trunk/gshell-remote:
gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/
gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/
gshell-remote-common/src/m...
Author: jdillon
Date: Sat Sep 22 17:07:25 2007
New Revision: 578530
URL: http://svn.apache.org/viewvc?rev=578530&view=rev
Log:
Renamed HandShakeMessage to ConnectMessage
Added HandshakeMessage intf, which ConnectMessage and LoginMessage impl to simplify the handshake processing a wee bit
Using the message visitor to handle the connect and login messages again
Added:
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java (contents, props changed)
- copied, changed from r578527, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandshakeMessage.java
Removed:
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java
Modified:
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientHandler.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/LoginMessage.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerHandler.java
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java?rev=578530&r1=578529&r2=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java Sat Sep 22 17:07:25 2007
@@ -29,7 +29,7 @@
import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
-import org.apache.geronimo.gshell.remote.message.rsh.HandShakeMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ConnectMessage;
import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
import org.apache.geronimo.gshell.remote.transport.Transport;
@@ -92,9 +92,9 @@
Message response;
- response = transport.request(new HandShakeMessage(crypto.getPublicKey()));
+ response = transport.request(new ConnectMessage(crypto.getPublicKey()));
- PublicKey serverKey = ((HandShakeMessage.Result)response).getClientKey();
+ PublicKey serverKey = ((ConnectMessage.Result)response).getClientKey();
log.debug("Logging in: {}", username);
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientHandler.java?rev=578530&r1=578529&r2=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientHandler.java Sat Sep 22 17:07:25 2007
@@ -27,7 +27,7 @@
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
/**
- * ???
+ * rovides the client-side message handling for the GShell rsh protocol.
*
* @version $Rev$ $Date$
*/
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java?rev=578530&r1=578529&r2=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java Sat Sep 22 17:07:25 2007
@@ -26,7 +26,7 @@
import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
-import org.apache.geronimo.gshell.remote.message.rsh.HandShakeMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ConnectMessage;
import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
import org.apache.geronimo.gshell.remote.stream.WriteStreamMessage;
@@ -43,8 +43,8 @@
//
ECHO (EchoMessage.class),
- HANDSHAKE (HandShakeMessage.class),
- HANDSHAKE_RESULT (HandShakeMessage.Result.class),
+ CONNECT (ConnectMessage.class),
+ CONNECT_RESULT (ConnectMessage.Result.class),
LOGIN (LoginMessage.class),
LOGIN_SUCCESS (LoginMessage.Success.class),
LOGIN_FAILURE (LoginMessage.Failure.class),
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java?rev=578530&r1=578529&r2=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java Sat Sep 22 17:07:25 2007
@@ -22,6 +22,8 @@
import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ConnectMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
import org.apache.geronimo.gshell.remote.session.SessionAttributeBinder;
@@ -37,6 +39,10 @@
//
SessionAttributeBinder<MessageVisitor> BINDER = new SessionAttributeBinder<MessageVisitor>(MessageVisitor.class);
+
+ void visitConnect(ConnectMessage msg) throws Exception;
+
+ void visitLogin(LoginMessage msg) throws Exception;
void visitEcho(EchoMessage msg) throws Exception;
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java?rev=578530&r1=578529&r2=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java Sat Sep 22 17:07:25 2007
@@ -23,6 +23,8 @@
import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ConnectMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +43,11 @@
protected final Logger log = LoggerFactory.getLogger(getClass());
protected MessageVisitorSupport() {}
-
+
+ public void visitConnect(ConnectMessage msg) throws Exception {}
+
+ public void visitLogin(LoginMessage msg) throws Exception {}
+
public void visitEcho(EchoMessage msg) throws Exception {}
public void visitOpenShell(OpenShellMessage msg) throws Exception {}
Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java (from r578527, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java&r1=578527&r2=578530&rev=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java Sat Sep 22 17:07:25 2007
@@ -24,34 +24,31 @@
import org.apache.geronimo.gshell.remote.marshall.Marshaller;
import org.apache.geronimo.gshell.remote.message.CryptoAwareMessageSupport;
import org.apache.geronimo.gshell.remote.message.MessageType;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
import org.apache.mina.common.ByteBuffer;
-//
-// NOTE: This message does not support MessageListener, actually should never make it to a message listener anyways
-// since this is consumed by the security filter.
-//
-
/**
- * Initial client handshake which contains the clients public key.
+ * Initial client to server message to initiate the connection.
*
* @version $Rev$ $Date$
*/
-public class HandShakeMessage
+public class ConnectMessage
extends CryptoAwareMessageSupport
+ implements HandshakeMessage
{
private PublicKey clientKey;
- protected HandShakeMessage(final MessageType type, final PublicKey clientKey) {
+ protected ConnectMessage(final MessageType type, final PublicKey clientKey) {
super(type);
this.clientKey = clientKey;
}
- public HandShakeMessage(final PublicKey clientKey) {
- this(MessageType.HANDSHAKE, clientKey);
+ public ConnectMessage(final PublicKey clientKey) {
+ this(MessageType.CONNECT, clientKey);
}
- public HandShakeMessage() {
+ public ConnectMessage() {
this(null);
}
@@ -67,6 +64,10 @@
this.clientKey = clientKey;
}
+ public void process(final MessageVisitor visitor) throws Exception {
+ visitor.visitConnect(this);
+ }
+
public void readExternal(final ByteBuffer in) throws Exception {
assert in != null;
@@ -93,10 +94,10 @@
* Reply from server to client which contains the server's public key.
*/
public static class Result
- extends HandShakeMessage
+ extends ConnectMessage
{
public Result(final PublicKey publicKey) {
- super(MessageType.HANDSHAKE_RESULT, publicKey);
+ super(MessageType.CONNECT_RESULT, publicKey);
}
public Result() {
Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ConnectMessage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandshakeMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandshakeMessage.java?rev=578530&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandshakeMessage.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandshakeMessage.java Sat Sep 22 17:07:25 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.geronimo.gshell.remote.message.rsh;
+
+/**
+ * Marker interface for messages which are part of the initial client-server handshake.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface HandshakeMessage
+{
+ // Empty
+}
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/LoginMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/LoginMessage.java?rev=578530&r1=578529&r2=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/LoginMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/LoginMessage.java Sat Sep 22 17:07:25 2007
@@ -25,21 +25,19 @@
import org.apache.geronimo.gshell.remote.message.CryptoAwareMessageSupport;
import org.apache.geronimo.gshell.remote.message.MessageSupport;
import org.apache.geronimo.gshell.remote.message.MessageType;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
import org.apache.mina.common.ByteBuffer;
import org.codehaus.plexus.util.StringUtils;
-//
-// NOTE: This message does not support MessageListener, actually should never make it to a message listener anyways
-// since this is consumed by the security filter.
-//
-
/**
- * Clients request to login to the server.
+ * Contains the user authentication details which the client will pass to the server after the
+ * authetication of the connection has been established.
*
* @version $Rev$ $Date$
*/
public class LoginMessage
extends CryptoAwareMessageSupport
+ implements HandshakeMessage
{
private PublicKey serverKey;
@@ -74,6 +72,10 @@
public String getPassword() {
return password;
+ }
+
+ public void process(final MessageVisitor visitor) throws Exception {
+ visitor.visitLogin(this);
}
public void readExternal(final ByteBuffer in) throws Exception {
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerHandler.java?rev=578530&r1=578529&r2=578530&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerHandler.java Sat Sep 22 17:07:25 2007
@@ -30,25 +30,26 @@
import org.apache.geronimo.gshell.DefaultEnvironment;
import org.apache.geronimo.gshell.command.IO;
+import org.apache.geronimo.gshell.common.Duration;
+import org.apache.geronimo.gshell.common.NamedThreadFactory;
import org.apache.geronimo.gshell.common.Notification;
import org.apache.geronimo.gshell.lookup.EnvironmentLookup;
import org.apache.geronimo.gshell.lookup.IOLookup;
import org.apache.geronimo.gshell.remote.RemoteShell;
import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
-import org.apache.geronimo.gshell.remote.message.Message;
import org.apache.geronimo.gshell.remote.message.MessageHandler;
import org.apache.geronimo.gshell.remote.message.MessageVisitorSupport;
import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ConnectMessage;
import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
-import org.apache.geronimo.gshell.remote.message.rsh.HandShakeMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.HandshakeMessage;
import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
import org.apache.geronimo.gshell.remote.server.auth.UserAuthenticator;
import org.apache.geronimo.gshell.remote.session.SessionAttributeBinder;
import org.apache.geronimo.gshell.remote.stream.SessionInputStream;
import org.apache.geronimo.gshell.remote.stream.SessionOutputStream;
-import org.apache.geronimo.gshell.common.NamedThreadFactory;
import org.apache.geronimo.gshell.shell.Environment;
import org.apache.mina.common.IoSession;
import org.codehaus.plexus.ContainerConfiguration;
@@ -61,7 +62,7 @@
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
/**
- * ???
+ * Provides the server-side message handling for the GShell rsh protocol.
*
* @version $Rev$ $Date$
*/
@@ -70,11 +71,15 @@
extends MessageHandler
implements Initializable
{
- private static final SessionAttributeBinder<PublicKey> CLIENT_KEY_BINDER = new SessionAttributeBinder<PublicKey>(RshServerHandler.class, "clientPublicKey");
+ //
+ // TODO: Introduce a context object which we can stuff any kinda of data we want into for the session... and have one binder, etc...
+ //
+
+ private static final SessionAttributeBinder<PublicKey> CLIENT_KEY_BINDER = new SessionAttributeBinder<PublicKey>(RshServerHandler.class, "clientpk");
- private static final SessionAttributeBinder<UUID> AUTH_BINDER = new SessionAttributeBinder<UUID>(RshServerHandler.class, "authenticated");
+ private static final SessionAttributeBinder<UUID> SECTOKEN = new SessionAttributeBinder<UUID>(RshServerHandler.class, "sectoken");
- private static final SessionAttributeBinder<ScheduledFuture> TIMEOUT_BINDER = new SessionAttributeBinder<ScheduledFuture>(RshServerHandler.class);
+ private static final SessionAttributeBinder<ScheduledFuture> TIMEOUT_BINDER = new SessionAttributeBinder<ScheduledFuture>(RshServerHandler.class, "timeout");
@Requirement
private PlexusContainer parentContainer;
@@ -93,6 +98,7 @@
setVisitor(new Visitor());
ThreadFactory tf = new NamedThreadFactory(getClass());
+
scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), tf);
securityToken = UUID.randomUUID();
@@ -111,7 +117,7 @@
assert session != null;
assert obj != null;
- UUID token = AUTH_BINDER.lookup(session, null);
+ UUID token = SECTOKEN.lookup(session, null);
if (securityToken.equals(token)) {
super.messageReceived(session, obj);
@@ -121,11 +127,8 @@
session.close();
}
- else if (obj instanceof HandShakeMessage) {
- doHandShake(session, (HandShakeMessage)obj);
- }
- else if (obj instanceof LoginMessage) {
- doLogin(session, (LoginMessage)obj);
+ else if (obj instanceof HandshakeMessage) {
+ super.messageReceived(session, obj);
}
else {
// If we get to here, then the message is not valid, so complain, then kill the session
@@ -135,127 +138,45 @@
}
}
- private void setSession(final IoSession session, final Message msg) {
- assert session != null;
- assert msg != null;
-
- // Prep the message for reply, this is normally done by the protocol handler, but that hasn't a chance to fire at this point
- msg.setSession(session);
- msg.freeze();
- }
-
- private void doHandShake(final IoSession session, final HandShakeMessage msg) throws Exception {
- assert session != null;
- assert msg != null;
-
- log.debug("Processing handshake");
-
- setSession(session, msg);
-
- // Try to cancel the timeout task
- if (!cancelTimeout(session)) {
- log.warn("Aborting handshake processing; timeout has triggered");
- }
- else {
- PublicKey key = msg.getClientKey();
-
- // Stuff the remote public key into the session
- CLIENT_KEY_BINDER.bind(session, key);
-
- //
- // TODO: Do we want to pass the client back some token which it needs to put onto messages that are sent for more security?
- //
-
- // And then send back our public key to the remote client
- msg.reply(new HandShakeMessage.Result(crypto.getPublicKey()));
-
- // Don't wait on the write future
+ //
+ // Timeout Support
+ //
- // Schedule a task to timeout the login process
- scheduleTimeout(session);
- }
- }
+ //
+ // TODO: Move this timeout stuff to a component, a few things need this functionality, probably more than I can think of too..
+ //
+
+ private static final Duration AUTH_TIMEOUT = new Duration(15, TimeUnit.SECONDS);
- private void doLogin(final IoSession session, final LoginMessage msg) throws Exception {
+ private ScheduledFuture scheduleTimeout(final IoSession session, final Duration timeout) {
assert session != null;
- assert msg != null;
-
- log.debug("Processing login");
-
- setSession(session, msg);
-
- // Try to cancel the timeout task
- if (!cancelTimeout(session)) {
- log.warn("Aborting login processing; timeout has triggered");
- }
- else {
- String username = msg.getUsername();
- String password = msg.getPassword();
-
- if (!userAuthenticator.authenticate(username, password)) {
- log.error("Authentication failed for user: {}, at location: {}", username, session.getRemoteAddress());
-
- String reason = "Failed to authenticate";
+ assert timeout != null;
- msg.reply(new LoginMessage.Failure(reason));
+ Runnable task = new Runnable() {
+ public void run() {
+ log.error("Timeout waiting for handshake or authentication from: {}", session.getRemoteAddress());
+
+ session.close();
}
- else {
- // Mark the session as authenticated
- AUTH_BINDER.bind(session, securityToken);
+ };
- log.info("Successfull authentication for user: {}, at location: {}", username, session.getRemoteAddress());
+ ScheduledFuture tf = scheduler.schedule(task, timeout.value, timeout.unit);
- msg.reply(new LoginMessage.Success());
+ TIMEOUT_BINDER.rebind(session, tf);
- // Don't wait on the write future
- }
- }
- }
-
- //
- // Timeout Support
- //
-
- private ScheduledFuture scheduleTimeout(final IoSession session, final long l, final TimeUnit unit) {
- assert session != null;
-
- ScheduledFuture task = scheduler.schedule(new TimeoutTask(session), l, unit);
- TIMEOUT_BINDER.rebind(session, task);
-
- return task;
+ return tf;
}
private ScheduledFuture scheduleTimeout(final IoSession session) {
- return scheduleTimeout(session, 30, TimeUnit.SECONDS);
+ return scheduleTimeout(session, AUTH_TIMEOUT);
}
private boolean cancelTimeout(final IoSession session) {
assert session != null;
- ScheduledFuture timeoutTask = TIMEOUT_BINDER.lookup(session);
+ ScheduledFuture tf = TIMEOUT_BINDER.lookup(session);
- return timeoutTask.cancel(false);
- }
-
- /**
- * Task to timeout sessions which fail to handshake or authenticate in a timely manner.
- */
- private class TimeoutTask
- implements Runnable
- {
- private final IoSession session;
-
- public TimeoutTask(final IoSession session) {
- assert session != null;
-
- this.session = session;
- }
-
- public void run() {
- log.error("Timeout waiting for handshake or authentication from: " + session.getRemoteAddress());
-
- session.close();
- }
+ return tf.cancel(false);
}
//
@@ -271,47 +192,78 @@
private class Visitor
extends MessageVisitorSupport
{
- public void visitEcho(final EchoMessage msg) throws Exception {
- assert msg != null;
+ //
+ // Client-Server Handshake and Authentication
+ //
- log.info("ECHO: {}", msg);
+ @Override
+ public void visitConnect(final ConnectMessage msg) throws Exception {
+ assert msg != null;
- String text = msg.getText();
+ log.debug("Processing handshake");
- //
- // HACK:
- //
+ IoSession session = msg.getSession();
+
+ // Try to cancel the timeout task
+ if (!cancelTimeout(session)) {
+ log.warn("Aborting handshake processing; timeout has triggered");
+ }
+ else {
+ PublicKey key = msg.getClientKey();
- if ("NOISE MAKER".equals(text)) {
- log.info("Making noise...");
+ // Stuff the remote public key into the session
+ CLIENT_KEY_BINDER.bind(session, key);
- final IoSession session = msg.getSession();
- final PrintWriter out = new PrintWriter(SessionOutputStream.BINDER.lookup(session), false);
+ //
+ // TODO: Do we want to pass the client back some token which it needs to put onto messages that are sent for more security?
+ //
- new Thread("NOISE MAKER") {
- public void run() {
- while (true) {
- out.println("FROM SERVER: " + new Date());
- out.flush();
+ // And then send back our public key to the remote client
+ msg.reply(new ConnectMessage.Result(crypto.getPublicKey()));
- try {
- Thread.sleep(5000);
- }
- catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }.start();
+ // Schedule a task to timeout the login process
+ scheduleTimeout(session);
}
- else if ("NO REPLY".equals(text)) {
- // ignore
+ }
+
+ @Override
+ public void visitLogin(final LoginMessage msg) throws Exception {
+ assert msg != null;
+
+ log.debug("Processing login");
+
+ IoSession session = msg.getSession();
+
+ // Try to cancel the timeout task
+ if (!cancelTimeout(session)) {
+ log.warn("Aborting login processing; timeout has triggered");
}
else {
- msg.reply(new EchoMessage(text));
+ String username = msg.getUsername();
+ String password = msg.getPassword();
+
+ if (!userAuthenticator.authenticate(username, password)) {
+ log.error("Authentication failed for user: {}, at location: {}", username, session.getRemoteAddress());
+
+ String reason = "Failed to authenticate";
+
+ msg.reply(new LoginMessage.Failure(reason));
+ }
+ else {
+ // Mark the session as authenticated
+ SECTOKEN.bind(session, securityToken);
+
+ log.info("Successfull authentication for user: {}, at location: {}", username, session.getRemoteAddress());
+
+ msg.reply(new LoginMessage.Success());
+ }
}
}
+ //
+ // Remote Shell Session
+ //
+
private RemoteShellContainer createContainer() throws PlexusContainerException {
// Create a new container which will be the parent for our remote shells
ContainerConfiguration config = new DefaultContainerConfiguration();
@@ -325,6 +277,7 @@
return new RemoteShellContainer(config);
}
+ @Override
public void visitOpenShell(final OpenShellMessage msg) throws Exception {
assert msg != null;
@@ -361,6 +314,7 @@
msg.reply(new EchoMessage("OPEN SHELL SUCCESS"));
}
+ @Override
public void visitCloseShell(final CloseShellMessage msg) throws Exception {
assert msg != null;
@@ -392,6 +346,11 @@
msg.reply(new EchoMessage("CLOSE SHELL SUCCESS"));
}
+ //
+ // Command Execution
+ //
+
+ @Override
public void visitExecute(final ExecuteMessage msg) throws Exception {
assert msg != null;
@@ -429,6 +388,52 @@
log.debug("Fault: " + t);
msg.reply(new ExecuteMessage.Fault(t));
+ }
+ }
+
+ //
+ // Testing & Debug
+ //
+
+ @Override
+ public void visitEcho(final EchoMessage msg) throws Exception {
+ assert msg != null;
+
+ log.info("ECHO: {}", msg);
+
+ String text = msg.getText();
+
+ //
+ // HACK:
+ //
+
+ if ("NOISE MAKER".equals(text)) {
+ log.info("Making noise...");
+
+ final IoSession session = msg.getSession();
+ final PrintWriter out = new PrintWriter(SessionOutputStream.BINDER.lookup(session), false);
+
+ new Thread("NOISE MAKER") {
+ public void run() {
+ while (true) {
+ out.println("FROM SERVER: " + new Date());
+ out.flush();
+
+ try {
+ Thread.sleep(5000);
+ }
+ catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }.start();
+ }
+ else if ("NO REPLY".equals(text)) {
+ // ignore
+ }
+ else {
+ msg.reply(new EchoMessage(text));
}
}
}