directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r691543 - /directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
Date Wed, 03 Sep 2008 08:37:57 GMT
Author: seelmann
Date: Wed Sep  3 01:37:55 2008
New Revision: 691543

URL: http://svn.apache.org/viewvc?rev=691543&view=rev
Log:
Fixed another JNDI issue

Modified:
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java?rev=691543&r1=691542&r2=691543&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
Wed Sep  3 01:37:55 2008
@@ -27,6 +27,8 @@
 import javax.naming.CommunicationException;
 import javax.naming.Context;
 import javax.naming.InsufficientResourcesException;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.PartialResultException;
@@ -280,7 +282,7 @@
         final StudioProgressMonitor monitor, final ReferralsInfo referralsInfo )
     {
         final long requestNum = SEARCH_RESQUEST_NUM++;
-        
+
         // start
         InnerRunnable runnable = new InnerRunnable()
         {
@@ -302,12 +304,7 @@
                     searchCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // perform the search
-                    // we use LdapName here for the following reason:
-                    // - when passing dn as String, JNDI doesn't handle slashes '/' correctly
-                    // - when using LdapDN from shared-ldap, JNDI uses the toString() method

-                    //   and LdapDN.toString() returns the normalized ATAV, but we need the

-                    //   user provided ATAV.
-                    NamingEnumeration<SearchResult> ne = searchCtx.search( new LdapName(
searchBase ), filter,
+                    NamingEnumeration<SearchResult> ne = searchCtx.search( getJndiSaveLdapName(
searchBase ), filter,
                         searchControls );
                     namingEnumeration = new StudioNamingEnumeration( connection, searchCtx,
ne, searchBase, filter,
                         searchControls, aliasesDereferencingMethod, referralsHandlingMethod,
controls, requestNum,
@@ -418,9 +415,8 @@
         }
         else
         {
-            return new StudioNamingEnumeration( connection, null, null, searchBase, filter,
-                searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls,
requestNum,
-                monitor, referralsInfo );
+            return new StudioNamingEnumeration( connection, null, null, searchBase, filter,
searchControls,
+                aliasesDereferencingMethod, referralsHandlingMethod, controls, requestNum,
monitor, referralsInfo );
         }
     }
 
@@ -461,12 +457,7 @@
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // perform modification
-                    // we use LdapName here for the following reason:
-                    // - when passing dn as String, JNDI doesn't handle slashes '/' correctly
-                    // - when using LdapDN from shared-ldap, JNDI uses the toString() method

-                    //   and LdapDN.toString() returns the normalized ATAV, but we need the

-                    //   user provided ATAV.
-                    modCtx.modifyAttributes( new LdapName( dn ), modificationItems );
+                    modCtx.modifyAttributes( getJndiSaveLdapName( dn ), modificationItems
);
                 }
                 catch ( ReferralException re )
                 {
@@ -567,12 +558,7 @@
                     }
 
                     // rename entry
-                    // we use LdapName here for the following reason:
-                    // - when passing dn as String, JNDI doesn't handle slashes '/' correctly
-                    // - when using LdapDN from shared-ldap, JNDI uses the toString() method

-                    //   and LdapDN.toString() returns the normalized ATAV, but we need the

-                    //   user provided ATAV.
-                    modCtx.rename( new LdapName( oldDn ), new LdapName( newDn ) );
+                    modCtx.rename( getJndiSaveLdapName( oldDn ), getJndiSaveLdapName( newDn
) );
                 }
                 catch ( ReferralException re )
                 {
@@ -662,12 +648,7 @@
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // create entry
-                    // we use LdapName here for the following reason:
-                    // - when passing dn as String, JNDI doesn't handle slashes '/' correctly
-                    // - when using LdapDN from shared-ldap, JNDI uses the toString() method

-                    //   and LdapDN.toString() returns the normalized ATAV, but we need the

-                    //   user provided ATAV.
-                    modCtx.createSubcontext( new LdapName( dn ), attributes );
+                    modCtx.createSubcontext( getJndiSaveLdapName( dn ), attributes );
                 }
                 catch ( ReferralException re )
                 {
@@ -755,12 +736,7 @@
                     modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
 
                     // delete entry
-                    // we use LdapName here for the following reason:
-                    // - when passing dn as String, JNDI doesn't handle slashes '/' correctly
-                    // - when using LdapDN from shared-ldap, JNDI uses the toString() method

-                    //   and LdapDN.toString() returns the normalized ATAV, but we need the

-                    //   user provided ATAV.
-                    modCtx.destroySubcontext( new LdapName( dn ) );
+                    modCtx.destroySubcontext( getJndiSaveLdapName( dn ) );
                 }
                 catch ( ReferralException re )
                 {
@@ -942,7 +918,7 @@
             IAuthHandler authHandler = ConnectionCorePlugin.getDefault().getAuthHandler();
             if ( authHandler == null )
             {
-                NamingException namingException = new NamingException(  Messages.model__no_auth_handler
);
+                NamingException namingException = new NamingException( Messages.model__no_auth_handler
);
                 monitor.reportError( Messages.model__no_auth_handler, namingException );
                 throw namingException;
             }
@@ -956,7 +932,7 @@
             }
             if ( credentials.getBindPrincipal() == null || credentials.getBindPassword()
== null )
             {
-                NamingException namingException = new NamingException(  Messages.model__no_credentials
);
+                NamingException namingException = new NamingException( Messages.model__no_credentials
);
                 monitor.reportError( Messages.model__no_credentials, namingException );
                 throw namingException;
             }
@@ -1236,6 +1212,31 @@
 
 
     /**
+     * Gets a Name object that is save for JNDI operations.
+     * <li>When passing DN as String, JNDI doesn't handle slashes '/' correctly.
+     *     So we must use a Name object here.
+     * <li>When using LdapDN from shared-ldap, JNDI uses the toString() method 
+     *     and LdapDN.toString() returns the normalized ATAV, but we need the 
+     *     user provided ATAV. Thats the cause we use LdapName by default.
+     * <li>When using for the empty DN (Root DSE) JNDI _sometimes_ throws an 
+     *     Exception (java.lang.IndexOutOfBoundsException: Posn: -1, Size: 0
+     *     at javax.naming.ldap.LdapName.getPrefix(LdapName.java:240)). 
+     *     Thats the cause we use LdapDN for the empty DN.
+     */
+    private static Name getJndiSaveLdapName( String name ) throws InvalidNameException
+    {
+        if ( name == null || "".equals( name ) )
+        {
+            return LdapDN.EMPTY_LDAPDN;
+        }
+        else
+        {
+            return new LdapName( name );
+        }
+    }
+
+
+    /**
      * Gets the referral connection from the given URL.
      * 
      * @param url the URL



Mime
View raw message