directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject [directory-server] 02/02: o Extending IoHandlerAdapter instead of implementing IoHandler o Added the event() message for LDAP o Calling closeNow() instead of close(true)
Date Tue, 05 Jun 2018 08:56:10 GMT
This is an automated email from the ASF dual-hosted git repository.

elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-server.git

commit af4c0723d671827c60749b4239a7cb40cf0de32b
Author: Emmanuel L├ęcharny <elecharny@symas.com>
AuthorDate: Tue Jun 5 10:55:54 2018 +0200

    o Extending IoHandlerAdapter instead of implementing IoHandler
    o Added the event() message for LDAP
    o Calling closeNow() instead of close(true)
---
 .../server/dhcp/protocol/DhcpProtocolHandler.java  |  4 +-
 .../server/dns/protocol/DnsProtocolHandler.java    |  4 +-
 .../kerberos/protocol/KerberosProtocolHandler.java |  6 +--
 .../directory/server/ldap/LdapProtocolHandler.java | 49 ++++++++++++----------
 4 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/protocol/DhcpProtocolHandler.java
b/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/protocol/DhcpProtocolHandler.java
index 3457783..da11887 100644
--- a/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/protocol/DhcpProtocolHandler.java
+++ b/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/protocol/DhcpProtocolHandler.java
@@ -27,7 +27,7 @@ import java.net.InetSocketAddress;
 import org.apache.directory.server.dhcp.messages.DhcpMessage;
 import org.apache.directory.server.dhcp.messages.MessageType;
 import org.apache.directory.server.dhcp.service.DhcpService;
-import org.apache.mina.core.service.IoHandler;
+import org.apache.mina.core.service.IoHandlerAdapter;
 import org.apache.mina.core.session.IdleStatus;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
@@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
  * @see org.apache.directory.server.dhcp.service.DhcpService
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class DhcpProtocolHandler implements IoHandler
+public class DhcpProtocolHandler extends IoHandlerAdapter
 {
     private static final Logger LOG = LoggerFactory.getLogger( DhcpProtocolHandler.class
);
 
diff --git a/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
b/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
index 3e764c8..f20a864 100644
--- a/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
+++ b/protocol-dns/src/main/java/org/apache/directory/server/dns/protocol/DnsProtocolHandler.java
@@ -34,7 +34,7 @@ import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.directory.server.dns.service.DnsContext;
 import org.apache.directory.server.dns.service.DomainNameService;
 import org.apache.directory.server.dns.store.RecordStore;
-import org.apache.mina.core.service.IoHandler;
+import org.apache.mina.core.service.IoHandlerAdapter;
 import org.apache.mina.core.session.IdleStatus;
 import org.apache.mina.core.session.IoSession;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
 /**
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class DnsProtocolHandler implements IoHandler
+public class DnsProtocolHandler extends IoHandlerAdapter
 {
     private static final Logger LOG = LoggerFactory.getLogger( DnsProtocolHandler.class );
 
diff --git a/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosProtocolHandler.java
b/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosProtocolHandler.java
index 4f6f904..ec71944 100644
--- a/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosProtocolHandler.java
+++ b/protocol-kerberos/src/main/java/org/apache/directory/server/kerberos/protocol/KerberosProtocolHandler.java
@@ -40,7 +40,7 @@ import org.apache.directory.shared.kerberos.components.PrincipalName;
 import org.apache.directory.shared.kerberos.exceptions.ErrorType;
 import org.apache.directory.shared.kerberos.exceptions.KerberosException;
 import org.apache.directory.shared.kerberos.messages.KrbError;
-import org.apache.mina.core.service.IoHandler;
+import org.apache.mina.core.service.IoHandlerAdapter;
 import org.apache.mina.core.session.IdleStatus;
 import org.apache.mina.core.session.IoSession;
 import org.slf4j.Logger;
@@ -53,7 +53,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class KerberosProtocolHandler implements IoHandler
+public class KerberosProtocolHandler extends IoHandlerAdapter
 {
     /** The loggers for this class */
     private static final Logger LOG = LoggerFactory.getLogger( KerberosProtocolHandler.class
);
@@ -156,7 +156,7 @@ public class KerberosProtocolHandler implements IoHandler
     {
         LOG.error( "{} EXCEPTION", session.getRemoteAddress(), cause );
         LOG_KRB.error( "{} EXCEPTION", session.getRemoteAddress(), cause );
-        session.close( true );
+        session.closeNow();
     }
 
 
diff --git a/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
b/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
index 6b815bd..d53f673 100644
--- a/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
+++ b/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
@@ -20,14 +20,12 @@
 package org.apache.directory.server.ldap;
 
 
-import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
 import org.apache.directory.api.ldap.codec.api.LdapDecoder;
 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.api.ldap.codec.api.MessageDecorator;
 import org.apache.directory.api.ldap.codec.api.SchemaBinaryAttributeDetector;
 import org.apache.directory.api.ldap.model.exception.ResponseCarryingMessageException;
 import org.apache.directory.api.ldap.model.message.Control;
-import org.apache.directory.api.ldap.model.message.ExtendedRequest;
 import org.apache.directory.api.ldap.model.message.Message;
 import org.apache.directory.api.ldap.model.message.Request;
 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
@@ -36,7 +34,8 @@ import org.apache.directory.api.ldap.model.message.ResultResponseRequest;
 import org.apache.directory.api.ldap.model.message.extended.NoticeOfDisconnect;
 import org.apache.mina.core.buffer.IoBuffer;
 import org.apache.mina.core.session.IoSession;
-import org.apache.mina.filter.ssl.SslFilter;
+import org.apache.mina.filter.FilterEvent;
+import org.apache.mina.filter.ssl.SslEvent;
 import org.apache.mina.handler.demux.DemuxingIoHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -136,7 +135,7 @@ class LdapProtocolHandler extends DemuxingIoHandler
         {
             try
             {
-                ldapSession.getIoSession().close( true );
+                ldapSession.getIoSession().closeNow();
             }
             catch ( Throwable t )
             {
@@ -162,6 +161,30 @@ class LdapProtocolHandler extends DemuxingIoHandler
         super.messageSent( session, message );
     }
 
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void event( IoSession session, FilterEvent event ) throws Exception 
+    {
+        Object message;
+        
+        if ( event instanceof SslEvent )
+        {
+            if ( ( ( SslEvent ) event ) == SslEvent.SECURED ) 
+            {
+                LdapSession ldapSession = ldapServer.getLdapSessionManager().getLdapSession(
session );
+                LOG.debug( "Session {} secured", ldapSession ); 
+            }
+            else
+            {
+                LdapSession ldapSession = ldapServer.getLdapSessionManager().getLdapSession(
session );
+                LOG.debug( "Session {} not secured", ldapSession ); 
+            }
+        }
+    }
+
 
     /**
      * {@inheritDoc}
@@ -178,22 +201,6 @@ class LdapProtocolHandler extends DemuxingIoHandler
         // handler should react to only SESSION_UNSECURED message
         // and degrade authentication level to 'anonymous' as specified
         // in the RFC, and this is no threat.
-
-        if ( message == SslFilter.SESSION_SECURED )
-        {
-            ExtendedRequest req =
-                LdapApiServiceFactory.getSingleton().newExtendedRequest( "1.3.6.1.4.1.1466.20037",
-                    "SECURED".getBytes( "ISO-8859-1" ) );
-            message = req;
-        }
-        else if ( message == SslFilter.SESSION_UNSECURED )
-        {
-            ExtendedRequest req =
-                LdapApiServiceFactory.getSingleton().newExtendedRequest( "1.3.6.1.4.1.1466.20037",
-                    "SECURED".getBytes( "ISO-8859-1" ) );
-            message = req;
-        }
-
         if ( ( ( Request ) message ).getControls().size() > 0
             && message instanceof ResultResponseRequest )
         {
@@ -238,6 +245,6 @@ class LdapProtocolHandler extends DemuxingIoHandler
         session.write( NoticeOfDisconnect.PROTOCOLERROR );
         LdapSession ldapSession = this.ldapServer.getLdapSessionManager().removeLdapSession(
session );
         cleanUpSession( ldapSession );
-        session.close( true );
+        session.closeNow();
     }
 }

-- 
To stop receiving notification emails like this one, please contact
elecharny@apache.org.

Mime
View raw message