You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/02/08 00:59:44 UTC

svn commit: r1241708 - in /directory: apacheds/trunk/ldap-client-test/src/main/java/org/apache/directory/shared/client/api/ apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/ apacheds/trunk/protocol-ldap/src/main/java...

Author: elecharny
Date: Tue Feb  7 23:59:43 2012
New Revision: 1241708

URL: http://svn.apache.org/viewvc?rev=1241708&view=rev
Log:
o Defined a NoSchemaBinaryAttributeDetector to simulate a connection to a server which does not expose the schema
o Added some missing ASL header
o Injected the BinaryAttributeDetector in the LdapConnectionConfig
o Fixed some failing tests (due to the above change)
o Renamed some SchemaLoader test names

Added:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/AdsSchemaLoaderTest.java
      - copied, changed from r1240465, directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/NetworkSchemaLoaderTest.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/ServerSchemaLoaderTest.java
      - copied, changed from r1240772, directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/SsseSchemaLoaderTest.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDetector.java
      - copied, changed from r1241488, directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/NoSchemaBinaryAttributeDetector.java
Removed:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/NetworkSchemaLoaderTest.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/SsseSchemaLoaderTest.java
    directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java
Modified:
    directory/apacheds/trunk/ldap-client-test/src/main/java/org/apache/directory/shared/client/api/LdapApiIntegrationUtils.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapApiISuite.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
    directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java

Modified: directory/apacheds/trunk/ldap-client-test/src/main/java/org/apache/directory/shared/client/api/LdapApiIntegrationUtils.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/main/java/org/apache/directory/shared/client/api/LdapApiIntegrationUtils.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/main/java/org/apache/directory/shared/client/api/LdapApiIntegrationUtils.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/main/java/org/apache/directory/shared/client/api/LdapApiIntegrationUtils.java Tue Feb  7 23:59:43 2012
@@ -29,6 +29,7 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.PoolableLdapConnectionFactory;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.ldap.LdapServer;
+import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDetector;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -128,6 +129,7 @@ public class LdapApiIntegrationUtils
     private static LdapConnectionPool getAdminPool( LdapServer ldapServer )
     {
         int port = ldapServer.getPort();
+        
         if ( !pools.containsKey( port ) )
         {
             LdapConnectionConfig config = new LdapConnectionConfig();
@@ -135,6 +137,8 @@ public class LdapApiIntegrationUtils
             config.setLdapPort( port );
             config.setName( DEFAULT_ADMIN );
             config.setCredentials( DEFAULT_PASSWORD );
+            config.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector(
+                ldapServer.getDirectoryService().getSchemaManager() ) );
             PoolableLdapConnectionFactory factory = new PoolableLdapConnectionFactory( config );
             LdapConnectionPool pool = new LdapConnectionPool( factory );
             pool.setTestOnBorrow( true );

Copied: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/AdsSchemaLoaderTest.java (from r1240465, directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/NetworkSchemaLoaderTest.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/AdsSchemaLoaderTest.java?p2=directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/AdsSchemaLoaderTest.java&p1=directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/NetworkSchemaLoaderTest.java&r1=1240465&r2=1241708&rev=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/NetworkSchemaLoaderTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/AdsSchemaLoaderTest.java Tue Feb  7 23:59:43 2012
@@ -47,7 +47,7 @@ import org.junit.runner.RunWith;
 @RunWith(FrameworkRunner.class)
 @CreateLdapServer(transports =
     { @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
-public class NetworkSchemaLoaderTest extends AbstractLdapTestUnit
+public class AdsSchemaLoaderTest extends AbstractLdapTestUnit
 {
     private LdapNetworkConnection connection;
 

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapApiISuite.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapApiISuite.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapApiISuite.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapApiISuite.java Tue Feb  7 23:59:43 2012
@@ -48,7 +48,7 @@ import org.junit.runners.Suite;
     {
         LdapConnectionTest.class,
         LdapSSLConnectionTest.class,
-        NetworkSchemaLoaderTest.class,
+        AdsSchemaLoaderTest.class,
 
         ClientAbandonRequestTest.class,
         ClientAddRequestTest.class,

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java Tue Feb  7 23:59:43 2012
@@ -31,12 +31,16 @@ import java.util.HashMap;
 import java.util.List;
 
 import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapConnectionConfig;
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDetector;
+import org.apache.directory.shared.ldap.codec.api.NoSchemaBinaryAttributeDetector;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
 import org.apache.directory.shared.ldap.model.entry.Entry;
@@ -161,10 +165,26 @@ public void testLookup() throws Exceptio
     @Test
     public void testRetrieveBinaryAttibute() throws Exception
     {
-        Entry entry = connection.lookup( "uid=admin,ou=system" );
+        LdapConnectionConfig config = new LdapConnectionConfig();
+        config.setLdapHost( "localhost" );
+        config.setLdapPort( ldapServer.getPort() );
+        config.setName( ServerDNConstants.ADMIN_SYSTEM_DN );
+        config.setCredentials( "secret" );
+        config.setBinaryAttributeDetector( new NoSchemaBinaryAttributeDetector() );
+
+        LdapConnection myConnection = new LdapNetworkConnection( config );
+        myConnection.bind( "uid=admin,ou=system", "secret" );
+
+        Entry entry = myConnection.lookup( "uid=admin,ou=system" );
         assertTrue( entry.get( SchemaConstants.USER_PASSWORD_AT ).get().isHumanReadable() );
+        
+        // Now, load a new binary Attribute
+        config.getBinaryAttributeDetector().addBinaryAttribute( "userPassword" );
+        entry = myConnection.lookup( "uid=admin,ou=system" );
+        assertFalse( entry.get( SchemaConstants.USER_PASSWORD_AT ).get().isHumanReadable() );
 
         connection.loadDefaultSchema();
+        connection.getConfig().setBinaryAttributeDetector( new DefaultBinaryAttributeDetector( connection.getSchemaManager() ) );
 
         entry = connection.lookup( "uid=admin,ou=system" );
         assertFalse( entry.get( SchemaConstants.USER_PASSWORD_AT ).get().isHumanReadable() );

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapSSLConnectionTest.java Tue Feb  7 23:59:43 2012
@@ -43,6 +43,7 @@ import org.apache.directory.server.ldap.
 import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
 import org.apache.directory.server.ldap.handlers.bind.plain.PlainMechanismHandler;
 import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
+import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDetector;
 import org.apache.directory.shared.ldap.model.constants.SupportedSaslMechanisms;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.name.Dn;
@@ -93,11 +94,15 @@ public class LdapSSLConnectionTest exten
         sslConfig.setUseSsl( true );
         sslConfig.setLdapPort( getLdapServer().getPortSSL() );
         sslConfig.setTrustManagers( new NoVerificationTrustManager() );
+        sslConfig.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector(
+                ldapServer.getDirectoryService().getSchemaManager() ) );
 
         tlsConfig = new LdapConnectionConfig();
         tlsConfig.setLdapHost( "localhost" );
         tlsConfig.setLdapPort( getLdapServer().getPort() );
         tlsConfig.setTrustManagers( new NoVerificationTrustManager() );
+        tlsConfig.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector(
+            ldapServer.getDirectoryService().getSchemaManager() ) );
     }
 
 

Copied: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/ServerSchemaLoaderTest.java (from r1240772, directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/SsseSchemaLoaderTest.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/ServerSchemaLoaderTest.java?p2=directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/ServerSchemaLoaderTest.java&p1=directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/SsseSchemaLoaderTest.java&r1=1240772&r2=1241708&rev=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/SsseSchemaLoaderTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/ServerSchemaLoaderTest.java Tue Feb  7 23:59:43 2012
@@ -51,7 +51,7 @@ import org.junit.runner.RunWith;
 @RunWith(FrameworkRunner.class)
 @CreateLdapServer(transports =
     { @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
-public class SsseSchemaLoaderTest extends AbstractLdapTestUnit
+public class ServerSchemaLoaderTest extends AbstractLdapTestUnit
 {
     private LdapNetworkConnection connection;
 
@@ -73,6 +73,7 @@ public class SsseSchemaLoaderTest extend
     @Test
     public void testLoadSSSE() throws Exception
     {
+        connection.setTimeOut( 0L );
         SchemaLoader loader = new SsseSchemaLoader( connection );
         
         // Load the schemas

Modified: directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java (original)
+++ directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/LdapProtocolHandler.java Tue Feb  7 23:59:43 2012
@@ -20,7 +20,7 @@
 package org.apache.directory.server.ldap;
 
 
-import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDectector;
+import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDetector;
 import org.apache.directory.shared.ldap.codec.api.LdapApiServiceFactory;
 import org.apache.directory.shared.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.api.MessageDecorator;
@@ -89,7 +89,7 @@ class LdapProtocolHandler extends Demuxi
         LdapMessageContainer<? extends MessageDecorator<Message>> ldapMessageContainer =
             new LdapMessageContainer<MessageDecorator<Message>>(
                 ldapServer.getDirectoryService().getLdapCodecService(),
-                new DefaultBinaryAttributeDectector(
+                new DefaultBinaryAttributeDetector(
                     ldapServer.getDirectoryService().getSchemaManager() ) );
 
         session.setAttribute( "messageContainer", ldapMessageContainer );

Modified: directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java (original)
+++ directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java Tue Feb  7 23:59:43 2012
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ * 
  */
 package org.apache.directory.server;
 
@@ -29,8 +29,11 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDetector;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
 import org.junit.Test;
 
 
@@ -74,12 +77,14 @@ public class UberJarMainTest
             {
                 try
                 {
-                    // Creating a connection on the created server 
+                    SchemaManager schemaManager = new DefaultSchemaManager();
+                    // Creating a connection on the created server
                     LdapConnectionConfig configuration = new LdapConnectionConfig();
                     configuration.setLdapHost( "localhost" );
                     configuration.setLdapPort( 10389 );
                     configuration.setName( ServerDNConstants.ADMIN_SYSTEM_DN );
                     configuration.setCredentials( PartitionNexus.ADMIN_PASSWORD_STRING );
+                    configuration.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector( schemaManager ) );
                     LdapNetworkConnection connection = new LdapNetworkConnection( configuration );
 
                     // Binding on the connection
@@ -102,7 +107,7 @@ public class UberJarMainTest
         };
 
         // Starting the connection verification thread
-        // and waiting for the termination of it 
+        // and waiting for the termination of it
         connectionVerificationThread.start();
         connectionVerificationThread.join();
 

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnectionConfig.java Tue Feb  7 23:59:43 2012
@@ -31,6 +31,7 @@ import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
 import javax.net.ssl.X509TrustManager;
 
+import org.apache.directory.shared.ldap.codec.api.BinaryAttributeDetector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,6 +43,8 @@ import org.slf4j.LoggerFactory;
  */
 public class LdapConnectionConfig
 {
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( LdapConnectionConfig.class );
 
     /** Default ports for LDAP */
     public static final int DEFAULT_LDAP_PORT = 389;
@@ -62,7 +65,6 @@ public class LdapConnectionConfig
     public static final String DEFAULT_SSL_PROTOCOL = "TLS";
 
     // --- private members ----
-
     /** A flag indicating if we are using SSL or not, default value is false */
     private boolean useSsl = false;
 
@@ -93,9 +95,12 @@ public class LdapConnectionConfig
     /** name of the protocol used for creating SSL context, default value is "TLS" */
     private String sslProtocol = DEFAULT_SSL_PROTOCOL;
 
-    private static final Logger LOG = LoggerFactory.getLogger( LdapConnectionConfig.class );
-
+    /** The class used to detect if an attribute is HR or not */
+    private BinaryAttributeDetector binaryAttributeDetector;
 
+    /**
+     * Creates a default LdapConnectionConfig instance
+     */
     public LdapConnectionConfig()
     {
         setDefaultTrustManager();
@@ -411,4 +416,22 @@ public class LdapConnectionConfig
     {
         this.enabledCipherSuites = enabledCipherSuites;
     }
+    
+    
+    /**
+     * @return the binaryAttributeDetector
+     */
+    public BinaryAttributeDetector getBinaryAttributeDetector()
+    {
+        return binaryAttributeDetector;
+    }
+
+
+    /**
+     * @param binaryAttributeDetector the binaryAttributeDetector to set
+     */
+    public void setBinaryAttributeDetector( BinaryAttributeDetector binaryAttributeDetector )
+    {
+        this.binaryAttributeDetector = binaryAttributeDetector;
+    }
 }

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1241708&r1=1241707&r2=1241708&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Tue Feb  7 23:59:43 2012
@@ -63,7 +63,7 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.future.SearchFuture;
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.util.Oid;
-import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDectector;
+import org.apache.directory.shared.ldap.codec.api.DefaultBinaryAttributeDetector;
 import org.apache.directory.shared.ldap.codec.api.LdapApiService;
 import org.apache.directory.shared.ldap.codec.api.LdapApiServiceFactory;
 import org.apache.directory.shared.ldap.codec.api.LdapMessageContainer;
@@ -350,6 +350,7 @@ public class LdapNetworkConnection exten
         config.setUseSsl( false );
         config.setLdapPort( config.getDefaultLdapPort() );
         config.setLdapHost( config.getDefaultLdapHost() );
+        config.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector( schemaManager ) );
         messageId = new AtomicInteger( 0 );
     }
 
@@ -379,6 +380,7 @@ public class LdapNetworkConnection exten
         config.setUseSsl( useSsl );
         config.setLdapPort( useSsl ? config.getDefaultLdapsPort() : config.getDefaultLdapPort() );
         config.setLdapHost( config.getDefaultLdapHost() );
+        config.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector( schemaManager ) );
         messageId = new AtomicInteger( 0 );
     }
 
@@ -403,6 +405,7 @@ public class LdapNetworkConnection exten
         }
         else
         {
+            config.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector( schemaManager ) );
             config.setLdapHost( server );
         }
 
@@ -435,6 +438,8 @@ public class LdapNetworkConnection exten
             config.setLdapHost( server );
         }
 
+        config.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector( schemaManager ) );
+
         messageId = new AtomicInteger( 0 );
     }
 
@@ -478,6 +483,7 @@ public class LdapNetworkConnection exten
             config.setLdapHost( server );
         }
 
+        config.setBinaryAttributeDetector( new DefaultBinaryAttributeDetector( schemaManager ) );
         messageId = new AtomicInteger();
     }
 
@@ -3600,7 +3606,7 @@ public class LdapNetworkConnection exten
         // Last, store the message container
         LdapMessageContainer<? extends MessageDecorator<Message>> ldapMessageContainer =
             new LdapMessageContainer<MessageDecorator<Message>>(
-                codec, new DefaultBinaryAttributeDectector( schemaManager ) );
+                codec, config.getBinaryAttributeDetector() );
 
         session.setAttribute( "messageContainer", ldapMessageContainer );
     }

Copied: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDetector.java (from r1241488, directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java)
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDetector.java?p2=directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDetector.java&p1=directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java&r1=1241488&r2=1241708&rev=1241708&view=diff
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDectector.java (original)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/DefaultBinaryAttributeDetector.java Tue Feb  7 23:59:43 2012
@@ -1,3 +1,22 @@
+/*
+ *  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.directory.shared.ldap.codec.api;
 
 import java.util.Set;
@@ -8,7 +27,13 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.util.Strings;
 import org.apache.mina.util.ConcurrentHashSet;
 
-public class DefaultBinaryAttributeDectector implements BinaryAttributeDetector
+/**
+ * An implementation of the BinaryAttributeDetector interface. It's used
+ * on the client and server side to detect if an Attribute is HumanRedable.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DefaultBinaryAttributeDetector implements BinaryAttributeDetector
 {
     /** A set of binary Attribute ID */
     private Set<String> binaryAttributes = new ConcurrentHashSet<String>();
@@ -26,7 +51,7 @@ public class DefaultBinaryAttributeDecte
      * 
      * @param schemaManager The associated SchemaManager
      */
-    public DefaultBinaryAttributeDectector( SchemaManager schemaManager )
+    public DefaultBinaryAttributeDetector( SchemaManager schemaManager )
     {
         this.schemaManager = schemaManager;
     }

Added: directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/NoSchemaBinaryAttributeDetector.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/NoSchemaBinaryAttributeDetector.java?rev=1241708&view=auto
==============================================================================
--- directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/NoSchemaBinaryAttributeDetector.java (added)
+++ directory/shared/trunk/ldap/codec/core/src/main/java/org/apache/directory/shared/ldap/codec/api/NoSchemaBinaryAttributeDetector.java Tue Feb  7 23:59:43 2012
@@ -0,0 +1,164 @@
+/*
+ *  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.directory.shared.ldap.codec.api;
+
+import java.util.Set;
+
+import org.apache.directory.shared.util.Strings;
+import org.apache.mina.util.ConcurrentHashSet;
+
+/**
+ * An implementation of the BinaryAttributeDetector interface. It's not
+ * schema aware, so it only uses the list of binary Attributes.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class NoSchemaBinaryAttributeDetector implements BinaryAttributeDetector
+{
+    /** A set of binary Attribute ID */
+    private Set<String> binaryAttributes = new ConcurrentHashSet<String>();
+
+    /** A set of binary Syntax ID */
+    private Set<String> binarySyntaxes = new ConcurrentHashSet<String>();
+    
+    
+    /**
+     * Creates a new instance of BinaryAttributeDetector. It's not schema aware
+     */
+    public NoSchemaBinaryAttributeDetector()
+    {
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isBinary( String attributeId )
+    {
+        String attrId = Strings.toLowerCase( attributeId );
+
+        if ( attrId.endsWith( ";binary" ) )
+        {
+            return true;
+        }
+
+        return binaryAttributes.contains( attrId );
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addBinaryAttribute( String... binaryAttributes )
+    {
+        if ( binaryAttributes != null )
+        {
+            for ( String binaryAttribute : binaryAttributes )
+            {
+                String attrId = Strings.toLowerCase( binaryAttribute );
+                this.binaryAttributes.add( attrId );
+            }
+        }
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeBinaryAttribute( String... binaryAttributes )
+    {
+        if ( binaryAttributes != null )
+        {
+            for ( String binaryAttribute : binaryAttributes )
+            {
+                String attrId = Strings.toLowerCase( binaryAttribute );
+                this.binaryAttributes.remove( attrId );
+            }
+        }
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setBinaryAttributes( Set<String> binaryAttributes )
+    {
+        if ( binaryAttributes != null )
+        {
+            this.binaryAttributes.clear();
+            
+            for ( String binaryAttribute : binaryAttributes )
+            {
+                String attrId = Strings.toLowerCase( binaryAttribute );
+                this.binaryAttributes.add( attrId );
+            }
+        }
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addBinarySyntaxes( String... binarySyntaxes )
+    {
+        if ( binarySyntaxes != null )
+        {
+            for ( String binarySyntax : binarySyntaxes )
+            {
+                String syntaxId = Strings.toLowerCase( binarySyntax );
+                this.binarySyntaxes.add( syntaxId );
+            }
+        }
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setBinarySyntaxes( Set<String> binarySyntaxes )
+    {
+        if ( binarySyntaxes != null )
+        {
+            this.binarySyntaxes.clear();
+            
+            for ( String binarySyntax : binarySyntaxes )
+            {
+                String syntaxId = Strings.toLowerCase( binarySyntax );
+                this.binarySyntaxes.add( syntaxId );
+            }
+        }
+    }
+    
+
+    /**
+     * {@inheritDoc}
+     */
+    public void removeBinarySyntaxes( String... binarySyntaxes )
+    {
+        if ( binarySyntaxes != null )
+        {
+            for ( String binarySyntax : binarySyntaxes )
+            {
+                String syntaxId = Strings.toLowerCase( binarySyntax );
+                this.binarySyntaxes.remove( syntaxId );
+            }
+        }
+    }
+}