geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578506 - 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/rsh/ gshell-remote-common/s...
Date Sat, 22 Sep 2007 21:37:19 GMT
Author: jdillon
Date: Sat Sep 22 14:37:18 2007
New Revision: 578506

URL: http://svn.apache.org/viewvc?rev=578506&view=rev
Log:
Update the security filter to use the session binder

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-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/security/SecurityFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/SessionAttributeBinder.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=578506&r1=578505&r2=578506&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 14:37:18 2007
@@ -94,7 +94,7 @@
 
         response = transport.request(new HandShakeMessage(crypto.getPublicKey()));
 
-        PublicKey serverKey = ((HandShakeMessage.Result)response).getPublicKey();
+        PublicKey serverKey = ((HandShakeMessage.Result)response).getClientKey();
 
         log.debug("Logging in: {}", username);
 

Modified: 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=578506&r1=578505&r2=578506&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/HandShakeMessage.java
Sat Sep 22 14:37:18 2007
@@ -24,8 +24,6 @@
 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.common.tostring.ToStringBuilder;
-import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
 import org.apache.mina.common.ByteBuffer;
 
 //
@@ -41,32 +39,32 @@
 public class HandShakeMessage
     extends CryptoAwareMessageSupport
 {
-    private PublicKey publicKey;
+    private PublicKey clientKey;
 
-    protected HandShakeMessage(final MessageType type, final PublicKey publicKey) {
+    protected HandShakeMessage(final MessageType type, final PublicKey clientKey) {
         super(type);
 
-        this.publicKey = publicKey;
+        this.clientKey = clientKey;
     }
 
-    public HandShakeMessage(final PublicKey publicKey) {
-        this(MessageType.HANDSHAKE, publicKey);
+    public HandShakeMessage(final PublicKey clientKey) {
+        this(MessageType.HANDSHAKE, clientKey);
     }
 
     public HandShakeMessage() {
         this(null);
     }
 
-    public PublicKey getPublicKey() {
-        if (publicKey == null) {
-            throw new IllegalStateException("Missing public key");
+    public PublicKey getClientKey() {
+        if (clientKey == null) {
+            throw new IllegalStateException("Missing client key");
         }
 
-        return publicKey;
+        return clientKey;
     }
 
-    public void setPublicKey(final PublicKey publicKey) {
-        this.publicKey = publicKey;
+    public void setClientKey(final PublicKey clientKey) {
+        this.clientKey = clientKey;
     }
 
     public void readExternal(final ByteBuffer in) throws Exception {
@@ -80,7 +78,7 @@
             throw new IllegalStateException();
         }
 
-        publicKey = getCryptoContext().deserializePublicKey(bytes);
+        clientKey = getCryptoContext().deserializePublicKey(bytes);
     }
 
     public void writeExternal(final ByteBuffer out) throws Exception {
@@ -88,7 +86,7 @@
 
         super.writeExternal(out);
 
-        Marshaller.writeBytes(out, getPublicKey().getEncoded());
+        Marshaller.writeBytes(out, getClientKey().getEncoded());
     }
 
     /**

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=578506&r1=578505&r2=578506&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 14:37:18 2007
@@ -30,6 +30,7 @@
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.geronimo.gshell.remote.message.rsh.HandShakeMessage;
 import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
+import org.apache.geronimo.gshell.remote.session.SessionAttributeBinder;
 import org.apache.geronimo.gshell.remote.util.NamedThreadFactory;
 import org.apache.mina.common.IoFilterAdapter;
 import org.apache.mina.common.IoSession;
@@ -47,11 +48,11 @@
 public class SecurityFilter
     extends IoFilterAdapter
 {
-    private static final String AUTHENTICATED_KEY = SecurityFilter.class.getName() + ".authenticated";
+    private static final SessionAttributeBinder<PublicKey> CLIENT_KEY_BINDER = new
SessionAttributeBinder<PublicKey>(SecurityFilter.class, "clientPublicKey");
 
-    private static final String REMOTE_PUBLIC_KEY_KEY = SecurityFilter.class.getName() +
".remotePublicKey";
+    private static final SessionAttributeBinder<UUID> AUTH_BINDER = new SessionAttributeBinder<UUID>(SecurityFilter.class,
"authenticated");
 
-    private static final String TIMEOUT_TASK_KEY = TimeoutTask.class.getName();
+    private static final SessionAttributeBinder<ScheduledFuture> TIMEOUT_BINDER = new
SessionAttributeBinder<ScheduledFuture>(TimeoutTask.class);
     
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -94,7 +95,7 @@
         assert session != null;
         assert obj != null;
 
-        UUID token = (UUID) session.getAttribute(AUTHENTICATED_KEY);
+        UUID token = AUTH_BINDER.lookup(session, null);
 
         // If the session is already authenticated, then pass on the message
         if (securityToken.equals(token)) {
@@ -141,10 +142,10 @@
             log.warn("Aborting handshake processing; timeout has triggered");
         }
         else {
-            PublicKey key = msg.getPublicKey();
+            PublicKey key = msg.getClientKey();
             
             // Stuff the remote public key into the session
-            session.setAttribute(REMOTE_PUBLIC_KEY_KEY, key);
+            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?
@@ -185,7 +186,7 @@
             }
             else {
                 // Mark the session as authenticated
-                session.setAttribute(AUTHENTICATED_KEY, securityToken);
+                AUTH_BINDER.bind(session, securityToken);
 
                 log.info("Successfull authentication for user: {}, at location: {}", username,
session.getRemoteAddress());
 
@@ -204,7 +205,7 @@
         assert session != null;
 
         ScheduledFuture task = scheduler.schedule(new TimeoutTask(session), l, unit);
-        session.setAttribute(TIMEOUT_TASK_KEY, task);
+        TIMEOUT_BINDER.rebind(session, task);
 
         return task;
     }
@@ -216,7 +217,7 @@
     private boolean cancelTimeout(final IoSession session) {
         assert session != null;
 
-        ScheduledFuture timeoutTask = (ScheduledFuture) session.getAttribute(TIMEOUT_TASK_KEY);
+        ScheduledFuture timeoutTask = TIMEOUT_BINDER.lookup(session);
 
         return timeoutTask.cancel(false);
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/SessionAttributeBinder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/SessionAttributeBinder.java?rev=578506&r1=578505&r2=578506&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/SessionAttributeBinder.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/SessionAttributeBinder.java
Sat Sep 22 14:37:18 2007
@@ -43,7 +43,7 @@
     public SessionAttributeBinder(final Class type, final String suffix) {
         this(type.getName() + "." + suffix);
     }
-    
+
     @SuppressWarnings({"unchecked"})
     public T lookup(final IoSession session) {
         assert session != null;
@@ -57,6 +57,19 @@
         return obj;
     }
 
+    @SuppressWarnings({"unchecked"})
+    public T lookup(final IoSession session, final T defaultValue) {
+        assert session != null;
+
+        T obj = (T) session.getAttribute(key);
+
+        if (obj == null) {
+            return defaultValue;
+        }
+
+        return obj;
+    }
+
     public void bind(final IoSession session, final T obj) {
         assert session != null;
         assert obj != null;
@@ -68,6 +81,18 @@
         }
 
         session.setAttribute(key, obj);
+    }
+
+    @SuppressWarnings({"unchecked"})
+    public T rebind(final IoSession session, final T obj) {
+        assert session != null;
+        assert obj != null;
+
+        T prev = (T) session.getAttribute(key);
+
+        session.setAttribute(key, obj);
+
+        return prev;
     }
 
     @SuppressWarnings({"unchecked"})



Mime
View raw message