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/22 22:35:17 UTC
svn commit: r578489 - 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 13:35:16 2007
New Revision: 578489
URL: http://svn.apache.org/viewvc?rev=578489&view=rev
Log:
Expose --username and --password for the rsh command
Added success and failure login responses
Still trying to figure out a nice simple and elegant way to handle message response processing
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/RshCommand.java
geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.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/rsh/ExecuteMessage.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-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.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=578489&r1=578488&r2=578489&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 13:35:16 2007
@@ -90,18 +90,32 @@
log.debug("Starting handshake", username);
- HandShakeMessage.Result handShakeResult = (HandShakeMessage.Result) transport.request(new HandShakeMessage(crypto.getPublicKey()));
-
- PublicKey serverKey = handShakeResult.getPublicKey();
+ Message response;
+
+ response = transport.request(new HandShakeMessage(crypto.getPublicKey()));
+
+ PublicKey serverKey = ((HandShakeMessage.Result)response).getPublicKey();
log.debug("Logging in: {}", username);
- LoginMessage.Result loginResult = (LoginMessage.Result) transport.request(new LoginMessage(serverKey, username, password));
+ response = transport.request(new LoginMessage(serverKey, username, password));
- log.debug("Login Result: {}", loginResult);
+ if (response instanceof LoginMessage.Success) {
+ log.debug("Login successful");
+ }
+ else if (response instanceof LoginMessage.Failure) {
+ LoginMessage.Failure failure = (LoginMessage.Failure)response;
+
+ throw new Exception("Login failed: " + failure.getReason());
+ }
+ else {
+ throw new InternalError();
+ }
}
public void echo(final String text) throws Exception {
+ assert text != null;
+
log.debug("Echoing: {}", text);
transport.send(new EchoMessage(text));
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.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/RshCommand.java?rev=578489&r1=578488&r2=578489&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java Sat Sep 22 13:35:16 2007
@@ -45,6 +45,12 @@
@Option(name="-b", aliases={"--bind"}, metaVar="URI")
private URI local;
+ @Option(name="-u", aliases={"--username"}, metaVar="USERNAME", required=true)
+ private String username;
+
+ @Option(name="-p", aliases={"--password"}, metaVar="PASSWORD", required=true)
+ private String password;
+
@Argument(metaVar="URI", required=true, index=0)
private URI remote;
@@ -66,8 +72,12 @@
io.info("Connected");
- client.login("jason", "password");
-
+ //
+ // TODO: Allow username and/or password to be read from input, need access to the console instance to get password reading working
+ //
+
+ client.login(username, password);
+
// client.echo("NOISE MAKER");
// client.getTransport().request(new EchoMessage("NO REPLY"));
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.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/MessageSupport.java?rev=578489&r1=578488&r2=578489&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java Sat Sep 22 13:35:16 2007
@@ -24,10 +24,12 @@
import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
import org.apache.geronimo.gshell.remote.marshall.Marshaller;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.WriteFuture;
+import org.codehaus.plexus.util.StringUtils;
/**
* Support for {@link Message} implementations.
@@ -75,6 +77,13 @@
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+ }
+
+ protected ToStringBuilder createToStringBuilder() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("id", getId())
+ .append("sequence", getSequence())
+ .append("timestamp", getTimestamp());
}
public MessageType getType() throws IOException {
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=578489&r1=578488&r2=578489&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 13:35:16 2007
@@ -46,7 +46,8 @@
HANDSHAKE (HandShakeMessage.class),
HANDSHAKE_RESULT (HandShakeMessage.Result.class),
LOGIN (LoginMessage.class),
- LOGIN_RESULT (LoginMessage.Result.class),
+ LOGIN_SUCCESS (LoginMessage.Success.class),
+ LOGIN_FAILURE (LoginMessage.Failure.class),
OPEN_SHELL (OpenShellMessage.class),
CLOSE_SHELL (CloseShellMessage.class),
EXECUTE (ExecuteMessage.class),
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ExecuteMessage.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/ExecuteMessage.java?rev=578489&r1=578488&r2=578489&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ExecuteMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ExecuteMessage.java Sat Sep 22 13:35:16 2007
@@ -132,7 +132,7 @@
}
/**
- * Container for the normal result of an execute command.
+ * Response for execute messages which contain the result of the command execution.
*/
public static class Result
extends MessageSupport
@@ -177,7 +177,7 @@
}
/**
- * Container for any exceptions thrown durring execution.
+ * Response for execute messages which resulted in a server-side exception.
*/
public static class Fault
extends Result
@@ -196,7 +196,7 @@
}
/**
- * Container for any notifications thrown durring execution.
+ * Response for execute messages which resulted in a server-side notification.
*/
public static class Notification
extends Result
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=578489&r1=578488&r2=578489&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 13:35:16 2007
@@ -21,10 +21,14 @@
import java.security.PublicKey;
+import org.apache.geronimo.gshell.remote.marshall.Marshaller;
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.common.tostring.ToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
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
@@ -39,15 +43,11 @@
public class LoginMessage
extends CryptoAwareMessageSupport
{
- private transient PublicKey serverKey;
+ private PublicKey serverKey;
private String username;
- //
- // NOTE: Marked as transiet to prevent the ToStringBuilder from displaying its value.
- //
-
- private transient String password;
+ private String password;
public LoginMessage(final PublicKey serverKey, final String username, final String password) {
super(MessageType.LOGIN);
@@ -63,6 +63,13 @@
this(null, null, null);
}
+ public String toString() {
+ return createToStringBuilder()
+ .append("username", username)
+ .append("password", StringUtils.repeat("*", password.length()))
+ .toString();
+ }
+
public String getUsername() {
return username;
}
@@ -92,13 +99,52 @@
}
/**
- * Server to client message to indicate successfull login.
+ * Response for login messages which were sucessful.
*/
- public static class Result
+ public static class Success
extends MessageSupport
{
- public Result() {
- super(MessageType.LOGIN_RESULT);
+ public Success() {
+ super(MessageType.LOGIN_SUCCESS);
+ }
+ }
+
+ /**
+ * Response for login messages which have failed.
+ */
+ public static class Failure
+ extends MessageSupport
+ {
+ private String reason;
+
+ public Failure(final String reason) {
+ super(MessageType.LOGIN_FAILURE);
+
+ this.reason = reason;
+ }
+
+ public Failure() {
+ this(null);
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public void readExternal(final ByteBuffer in) throws Exception {
+ assert in != null;
+
+ super.readExternal(in);
+
+ reason = Marshaller.readString(in);
+ }
+
+ public void writeExternal(final ByteBuffer out) throws Exception {
+ assert out != null;
+
+ super.writeExternal(out);
+
+ Marshaller.writeString(out, reason);
}
}
}
Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java?rev=578489&r1=578488&r2=578489&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java Sat Sep 22 13:35:16 2007
@@ -178,8 +178,10 @@
if (!userAuthenticator.authenticate(username, password)) {
log.error("Authentication failed for user: {}, at location: {}", username, session.getRemoteAddress());
-
- session.close();
+
+ String reason = "Failed to authenticate";
+
+ msg.reply(new LoginMessage.Failure(reason));
}
else {
// Mark the session as authenticated
@@ -187,7 +189,7 @@
log.info("Successfull authentication for user: {}, at location: {}", username, session.getRemoteAddress());
- msg.reply(new LoginMessage.Result());
+ msg.reply(new LoginMessage.Success());
// Don't wait on the write future
}