directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r188719 - in /directory/network: branches/0.7/src/java/org/apache/mina/io/filter/SSLFilter.java branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java trunk/src/java/org/apache/mina/filter/SSLFilter.java
Date Tue, 07 Jun 2005 06:46:51 GMT
Author: trustin
Date: Mon Jun  6 23:46:50 2005
New Revision: 188719

URL: http://svn.apache.org/viewcvs?rev=188719&view=rev
Log:
* Made SSLFilter to store SSLHandler as a session attribute
* Added SSLFilter.getSSLSession( IoSession ) so that users can get SSLSessions not using IoSession.getAttribute()



Modified:
    directory/network/branches/0.7/src/java/org/apache/mina/io/filter/SSLFilter.java
    directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java
    directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java

Modified: directory/network/branches/0.7/src/java/org/apache/mina/io/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.7/src/java/org/apache/mina/io/filter/SSLFilter.java?rev=188719&r1=188718&r2=188719&view=diff
==============================================================================
--- directory/network/branches/0.7/src/java/org/apache/mina/io/filter/SSLFilter.java (original)
+++ directory/network/branches/0.7/src/java/org/apache/mina/io/filter/SSLFilter.java Mon Jun
 6 23:46:50 2005
@@ -18,8 +18,6 @@
  */
 package org.apache.mina.io.filter;
 
-import java.util.IdentityHashMap;
-import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -27,6 +25,7 @@
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.SSLSession;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.io.IoFilterAdapter;
@@ -47,10 +46,12 @@
 public class SSLFilter extends IoFilterAdapter
 {
     /**
-     * Session attribute key that stores underlying {@link javax.net.ssl.SSLSession}
+     * Session attribute key that stores underlying {@link SSLSession}
      * for each session.
      */
     public static final String SSL_SESSION = SSLFilter.class.getName() + ".SSLSession";
+    
+    private static final String SSL_HANDLER = SSLFilter.class.getName() + ".SSLHandler";
 
     private static final Logger log = Logger.getLogger( SSLFilter.class.getName() );
 
@@ -69,9 +70,6 @@
     // SSL Context
     private SSLContext sslContext;
 
-    // Map used to map SSLHandler objects per session (key is IoSession)
-    private Map sslSessionHandlerMap = new IdentityHashMap();
-
     private boolean client;
     private boolean needClientAuth;
     private boolean wantClientAuth;
@@ -90,6 +88,16 @@
 
         this.sslContext = sslContext;
     }
+    
+    /**
+     * Returns the underlying {@link SSLSession} for the specified session.
+     * 
+     * @return <tt>null</tt> if no {@link SSLSession} is initialized yet.
+     */
+    public SSLSession getSSLSession( IoSession session )
+    {
+        return ( SSLSession ) session.getAttribute( SSL_SESSION );
+    }
 
     /**
      * Returns <tt>true</tt> if the engine is set to use client mode
@@ -478,12 +486,12 @@
 
     private SSLHandler createSSLSessionHandler( NextFilter nextFilter, IoSession session
) throws SSLException
     {
-        SSLHandler handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+        SSLHandler handler = getSSLSessionHandler( session );
         if( handler == null )
         {
-            synchronized( sslSessionHandlerMap )
+            synchronized( session )
             {
-                handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+                handler = getSSLSessionHandler( session );
                 if( handler == null )
                 {
                     boolean done = false;
@@ -491,7 +499,7 @@
                     {
                         handler =
                             new SSLHandler( this, sslContext, session );
-                        sslSessionHandlerMap.put( session, handler );
+                        session.setAttribute( SSL_HANDLER, handler );
                         handler.doHandshake( nextFilter );
                         done = true;
                     }
@@ -499,7 +507,7 @@
                     {
                         if( !done )
                         {
-                            sslSessionHandlerMap.remove( session );
+                            session.removeAttribute( SSL_HANDLER );
                         }
                     }
                 }
@@ -511,14 +519,11 @@
 
     private SSLHandler getSSLSessionHandler( IoSession session )
     {
-        return ( SSLHandler ) sslSessionHandlerMap.get( session );
+        return ( SSLHandler ) session.getAttribute( SSL_HANDLER );
     }
 
     private void removeSSLSessionHandler( IoSession session )
     {
-        synchronized( sslSessionHandlerMap )
-        {
-            sslSessionHandlerMap.remove( session );
-        }
+        session.removeAttribute( SSL_HANDLER );
     }
 }

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java?rev=188719&r1=188718&r2=188719&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java (original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/filter/SSLFilter.java Mon
Jun  6 23:46:50 2005
@@ -18,8 +18,6 @@
  */
 package org.apache.mina.filter;
 
-import java.util.IdentityHashMap;
-import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -27,6 +25,7 @@
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.SSLSession;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.ByteBufferProxy;
@@ -49,19 +48,18 @@
 public class SSLFilter extends IoFilterAdapter
 {
     /**
-     * Session attribute key that stores underlying {@link javax.net.ssl.SSLSession}
+     * Session attribute key that stores underlying {@link SSLSession}
      * for each session.
      */
     public static final String SSL_SESSION = SSLFilter.class.getName() + ".SSLSession";
+    
+    private static final String SSL_HANDLER = SSLFilter.class.getName() + ".SSLHandler";
 
     private static final Logger log = Logger.getLogger( SSLFilter.class.getName() );
 
     // SSL Context
     private SSLContext sslContext;
 
-    // Map used to map SSLHandler objects per session (key is IoSession)
-    private Map sslSessionHandlerMap = new IdentityHashMap();
-
     private boolean client;
     private boolean needClientAuth;
     private boolean wantClientAuth;
@@ -80,6 +78,16 @@
 
         this.sslContext = sslContext;
     }
+    
+    /**
+     * Returns the underlying {@link SSLSession} for the specified session.
+     * 
+     * @return <tt>null</tt> if no {@link SSLSession} is initialized yet.
+     */
+    public SSLSession getSSLSession( IoSession session )
+    {
+        return ( SSLSession ) session.getAttribute( SSL_SESSION );
+    }
 
     /**
      * Returns <tt>true</tt> if the engine is set to use client mode
@@ -480,12 +488,12 @@
 
     private SSLHandler createSSLSessionHandler( NextFilter nextFilter, IoSession session
) throws SSLException
     {
-        SSLHandler handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+        SSLHandler handler = getSSLSessionHandler( session );
         if( handler == null )
         {
-            synchronized( sslSessionHandlerMap )
+            synchronized( session )
             {
-                handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+                handler = getSSLSessionHandler( session );
                 if( handler == null )
                 {
                     boolean done = false;
@@ -493,7 +501,7 @@
                     {
                         handler =
                             new SSLHandler( this, sslContext, session );
-                        sslSessionHandlerMap.put( session, handler );
+                        session.setAttribute( SSL_HANDLER, handler );
                         handler.doHandshake( nextFilter );
                         done = true;
                     }
@@ -501,7 +509,7 @@
                     {
                         if( !done )
                         {
-                            sslSessionHandlerMap.remove( session );
+                            session.removeAttribute( SSL_HANDLER );
                         }
                     }
                 }
@@ -513,15 +521,12 @@
 
     private SSLHandler getSSLSessionHandler( IoSession session )
     {
-        return ( SSLHandler ) sslSessionHandlerMap.get( session );
+        return ( SSLHandler ) session.getAttribute( SSL_HANDLER );
     }
 
     private void removeSSLSessionHandler( IoSession session )
     {
-        synchronized( sslSessionHandlerMap )
-        {
-            sslSessionHandlerMap.remove( session );
-        }
+        session.removeAttribute( SSL_HANDLER );
     }
 
     private static class EncryptedBuffer extends ByteBufferProxy

Modified: directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java?rev=188719&r1=188718&r2=188719&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/SSLFilter.java Mon Jun  6 23:46:50
2005
@@ -18,8 +18,6 @@
  */
 package org.apache.mina.filter;
 
-import java.util.IdentityHashMap;
-import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -27,6 +25,7 @@
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.SSLSession;
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.ByteBufferProxy;
@@ -47,19 +46,18 @@
 public class SSLFilter extends IoFilterAdapter
 {
     /**
-     * Session attribute key that stores underlying {@link javax.net.ssl.SSLSession}
+     * Session attribute key that stores underlying {@link SSLSession}
      * for each session.
      */
     public static final String SSL_SESSION = SSLFilter.class.getName() + ".SSLSession";
+    
+    private static final String SSL_HANDLER = SSLFilter.class.getName() + ".SSLHandler";
 
     private static final Logger log = Logger.getLogger( SSLFilter.class.getName() );
 
     // SSL Context
     private SSLContext sslContext;
 
-    // Map used to map SSLHandler objects per session (key is IoSession)
-    private Map sslSessionHandlerMap = new IdentityHashMap();
-
     private boolean client;
     private boolean needClientAuth;
     private boolean wantClientAuth;
@@ -78,6 +76,16 @@
 
         this.sslContext = sslContext;
     }
+    
+    /**
+     * Returns the underlying {@link SSLSession} for the specified session.
+     * 
+     * @return <tt>null</tt> if no {@link SSLSession} is initialized yet.
+     */
+    public SSLSession getSSLSession( IoSession session )
+    {
+        return ( SSLSession ) session.getAttribute( SSL_SESSION );
+    }
 
     /**
      * Returns <tt>true</tt> if the engine is set to use client mode
@@ -476,12 +484,12 @@
 
     private SSLHandler createSSLSessionHandler( NextFilter nextFilter, IoSession session
) throws SSLException
     {
-        SSLHandler handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+        SSLHandler handler = getSSLSessionHandler( session );
         if( handler == null )
         {
-            synchronized( sslSessionHandlerMap )
+            synchronized( session )
             {
-                handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+                handler = getSSLSessionHandler( session );
                 if( handler == null )
                 {
                     boolean done = false;
@@ -489,7 +497,7 @@
                     {
                         handler =
                             new SSLHandler( this, sslContext, session );
-                        sslSessionHandlerMap.put( session, handler );
+                        session.setAttribute( SSL_HANDLER, handler );
                         handler.doHandshake( nextFilter );
                         done = true;
                     }
@@ -497,7 +505,7 @@
                     {
                         if( !done )
                         {
-                            sslSessionHandlerMap.remove( session );
+                            session.removeAttribute( SSL_HANDLER );
                         }
                     }
                 }
@@ -509,15 +517,12 @@
 
     private SSLHandler getSSLSessionHandler( IoSession session )
     {
-        return ( SSLHandler ) sslSessionHandlerMap.get( session );
+        return ( SSLHandler ) session.getAttribute( SSL_HANDLER );
     }
 
     private void removeSSLSessionHandler( IoSession session )
     {
-        synchronized( sslSessionHandlerMap )
-        {
-            sslSessionHandlerMap.remove( session );
-        }
+        session.removeAttribute( SSL_HANDLER );
     }
 
     private static class EncryptedBuffer extends ByteBufferProxy



Mime
View raw message