You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2008/09/03 20:44:19 UTC
svn commit: r691723 - in /directory/studio/trunk:
connection-core/src/main/java/org/apache/directory/studio/connection/core/
connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/
ldapbrowser-common/src/main/java/org/apache/...
Author: seelmann
Date: Wed Sep 3 11:44:19 2008
New Revision: 691723
URL: http://svn.apache.org/viewvc?rev=691723&view=rev
Log:
Fix for DIRSTUDIO-182:
o Added preference for the used JNDI LDAP context factory
o Added auto-detection for Sun and ApacheHarmony context factory
Modified:
directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCoreConstants.java
directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePreferencesInitializer.java
directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/io/jndi/JNDIConnectionWrapper.java
directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/MainPreferencePage.java
Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCoreConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCoreConstants.java?rev=691723&r1=691722&r2=691723&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCoreConstants.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCoreConstants.java Wed Sep 3 11:44:19 2008
@@ -20,8 +20,6 @@
package org.apache.directory.studio.connection.core;
-
-
/**
* Constants for the connection core plugin.
*
@@ -40,6 +38,9 @@
/** The date format of the modification logger */
public static final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS"; //$NON-NLS-1$
+ /** The constant used to preferred LDAP context factory */
+ public static final String PREFERENCE_LDAP_CONTEXT_FACTORY = "ldapContextFactory";
+
/** The constant used to identify the "enable modification logs" preference */
public static final String PREFERENCE_MODIFICATIONLOGS_ENABLE = "modificationLogsEnable";
Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java?rev=691723&r1=691722&r2=691723&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePlugin.java Wed Sep 3 11:44:19 2008
@@ -296,8 +296,8 @@
catch ( Exception e )
{
getLog().log(
- new Status( IStatus.ERROR, ConnectionCoreConstants.PLUGIN_ID, 1, "Unable to create JNDI logger "
- + member.getAttribute( "class" ), e ) );
+ new Status( IStatus.ERROR, ConnectionCoreConstants.PLUGIN_ID, 1,
+ "Unable to create JNDI logger " + member.getAttribute( "class" ), e ) );
}
}
}
@@ -371,4 +371,43 @@
return properties;
}
+
+
+ /**
+ * Gets the default LDAP context factory.
+ *
+ * Right now the following context factories are supported:
+ * <ul>
+ * <li>com.sun.jndi.ldap.LdapCtxFactory</li>
+ * <li>org.apache.harmony.jndi.provider.ldap.LdapContextFactory</li>
+ * </ul>
+ *
+ * @return the default LDAP context factory
+ */
+ public String getDefaultLdapContextFactory()
+ {
+ String defaultLdapContextFactory = "";
+
+ try
+ {
+ String sun = "com.sun.jndi.ldap.LdapCtxFactory";
+ Class.forName( sun );
+ defaultLdapContextFactory = sun;
+ }
+ catch ( ClassNotFoundException e )
+ {
+ }
+ try
+ {
+ String apache = "org.apache.harmony.jndi.provider.ldap.LdapContextFactory";
+ Class.forName( apache );
+ defaultLdapContextFactory = apache;
+ }
+ catch ( ClassNotFoundException e )
+ {
+ }
+
+ return defaultLdapContextFactory;
+ }
+
}
Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePreferencesInitializer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePreferencesInitializer.java?rev=691723&r1=691722&r2=691723&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePreferencesInitializer.java (original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/ConnectionCorePreferencesInitializer.java Wed Sep 3 11:44:19 2008
@@ -40,6 +40,10 @@
{
Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences();
+ // LDAP context factory
+ String defaultLdapContextFactory = ConnectionCorePlugin.getDefault().getDefaultLdapContextFactory();
+ preferences.setDefault( ConnectionCoreConstants.PREFERENCE_LDAP_CONTEXT_FACTORY, defaultLdapContextFactory );
+
// Modification Logs
preferences.setDefault( ConnectionCoreConstants.PREFERENCE_MODIFICATIONLOGS_ENABLE, true );
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=691723&r1=691722&r2=691723&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 11:44:19 2008
@@ -25,6 +25,7 @@
import java.util.List;
import javax.naming.CommunicationException;
+import javax.naming.CompositeName;
import javax.naming.Context;
import javax.naming.InsufficientResourcesException;
import javax.naming.InvalidNameException;
@@ -53,6 +54,7 @@
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.util.LdapURL;
import org.apache.directory.studio.connection.core.Connection;
+import org.apache.directory.studio.connection.core.ConnectionCoreConstants;
import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
import org.apache.directory.studio.connection.core.ConnectionParameter;
import org.apache.directory.studio.connection.core.IAuthHandler;
@@ -67,6 +69,7 @@
import org.apache.directory.studio.connection.core.io.ConnectionWrapper;
import org.apache.directory.studio.connection.core.io.jndi.ReferralsInfo.UrlAndDn;
import org.apache.directory.studio.connection.core.jobs.StudioProgressMonitor;
+import org.eclipse.core.runtime.Preferences;
/**
@@ -304,7 +307,7 @@
searchCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
// perform the search
- NamingEnumeration<SearchResult> ne = searchCtx.search( getJndiSaveLdapName( searchBase ), filter,
+ NamingEnumeration<SearchResult> ne = searchCtx.search( getSaveJndiName( searchBase ), filter,
searchControls );
namingEnumeration = new StudioNamingEnumeration( connection, searchCtx, ne, searchBase, filter,
searchControls, aliasesDereferencingMethod, referralsHandlingMethod, controls, requestNum,
@@ -457,7 +460,7 @@
modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
// perform modification
- modCtx.modifyAttributes( getJndiSaveLdapName( dn ), modificationItems );
+ modCtx.modifyAttributes( getSaveJndiName( dn ), modificationItems );
}
catch ( ReferralException re )
{
@@ -558,7 +561,7 @@
}
// rename entry
- modCtx.rename( getJndiSaveLdapName( oldDn ), getJndiSaveLdapName( newDn ) );
+ modCtx.rename( getSaveJndiName( oldDn ), getSaveJndiName( newDn ) );
}
catch ( ReferralException re )
{
@@ -648,7 +651,7 @@
modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
// create entry
- modCtx.createSubcontext( getJndiSaveLdapName( dn ), attributes );
+ modCtx.createSubcontext( getSaveJndiName( dn ), attributes );
}
catch ( ReferralException re )
{
@@ -736,7 +739,7 @@
modCtx.addToEnvironment( Context.REFERRAL, REFERRAL_THROW );
// delete entry
- modCtx.destroySubcontext( getJndiSaveLdapName( dn ) );
+ modCtx.destroySubcontext( getSaveJndiName( dn ) );
}
catch ( ReferralException re )
{
@@ -803,7 +806,9 @@
useStartTLS = connection.getConnectionParameter().getEncryptionMethod() == ConnectionParameter.EncryptionMethod.START_TLS;
environment = new Hashtable<String, String>();
- environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); //$NON-NLS-1$
+ Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences();
+ String ldapCtxFactory = preferences.getString( ConnectionCoreConstants.PREFERENCE_LDAP_CONTEXT_FACTORY );
+ environment.put( Context.INITIAL_CONTEXT_FACTORY, ldapCtxFactory ); //$NON-NLS-1$
environment.put( "java.naming.ldap.version", "3" ); //$NON-NLS-1$ //$NON-NLS-2$
// timeouts
@@ -1213,21 +1218,43 @@
/**
* Gets a Name object that is save for JNDI operations.
+ * <p>
+ * In JNDI we have could use the following classes for names:
+ * <ul>
+ * <li>DN as String</li>
+ * <li>javax.naming.CompositeName</li>
+ * <li>javax.naming.ldap.LdapName (since Java5)</li>
+ * <li>org.apache.directory.shared.ldap.name.LdapDN</li>
+ * </ul>
+ * <p>
+ * There are some drawbacks when using this classes:
+ * <ul>
* <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.
+ * So we must use a Name object here.</li>
+ * <li>With CompositeName we have the same problem with slashes '/'.</li>
+ * <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.</li>
+ * <li>When using LdapName 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)).</li>
+ * <li>Using LdapDN for the RootDSE doesn't work with Apache Harmony because
+ * its JNDI provider only accepts intstances of CompositeName or LdapName.</li>
+ * </ul>
+ * <p>
+ * So we use LdapName as default and the CompositeName for the empty DN.
+ *
+ * @param name the DN
+ *
+ * @return the save JNDI name
+ *
+ * @throws InvalidNameException the invalid name exception
*/
- private static Name getJndiSaveLdapName( String name ) throws InvalidNameException
+ private Name getSaveJndiName( String name ) throws InvalidNameException
{
if ( name == null || "".equals( name ) )
{
- return LdapDN.EMPTY_LDAPDN;
+ return new CompositeName();
}
else
{
Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/MainPreferencePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/MainPreferencePage.java?rev=691723&r1=691722&r2=691723&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/MainPreferencePage.java (original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/preferences/MainPreferencePage.java Wed Sep 3 11:44:19 2008
@@ -21,11 +21,16 @@
package org.apache.directory.studio.ldapbrowser.common.dialogs.preferences;
-import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.apache.directory.studio.connection.core.ConnectionCoreConstants;
+import org.apache.directory.studio.connection.core.ConnectionCorePlugin;
import org.apache.directory.studio.connection.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
+import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -39,6 +44,9 @@
public class MainPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
{
+ private Text jndiLdapContextProvider;
+
+
/**
*
* Creates a new instance of MainPreferencePage.
@@ -54,7 +62,6 @@
/**
* {@inheritDoc}
*/
-
public void init( IWorkbench workbench )
{
}
@@ -67,18 +74,43 @@
{
Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
+ BaseWidgetUtils.createSpacer( composite, 1 );
+ BaseWidgetUtils.createSpacer( composite, 1 );
+
+ Group group = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
+ "JNDI LDAP context provider", 1 );
+
+ Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences();
+ String ldapCtxFactory = preferences.getString( ConnectionCoreConstants.PREFERENCE_LDAP_CONTEXT_FACTORY );
+ String defaultLdapCtxFactory = preferences
+ .getDefaultString( ConnectionCoreConstants.PREFERENCE_LDAP_CONTEXT_FACTORY );
+ String note = "Note: The system detected '" + defaultLdapCtxFactory + "'.";
+
+ jndiLdapContextProvider = BaseWidgetUtils.createText( group, ldapCtxFactory, 1 );
+ BaseWidgetUtils.createWrappedLabel( group, note, 1 );
+
return composite;
}
+ /**
+ * {@inheritDoc}
+ */
protected void performDefaults()
{
+ jndiLdapContextProvider.setText( ConnectionCorePlugin.getDefault().getPluginPreferences().getDefaultString(
+ ConnectionCoreConstants.PREFERENCE_LDAP_CONTEXT_FACTORY ) );
super.performDefaults();
}
+ /**
+ * {@inheritDoc}
+ */
public boolean performOk()
{
+ ConnectionCorePlugin.getDefault().getPluginPreferences().setValue(
+ ConnectionCoreConstants.PREFERENCE_LDAP_CONTEXT_FACTORY, jndiLdapContextProvider.getText() );
return true;
}