]> source.dussan.org Git - archiva.git/commitdiff
ease users life for ldap setup make com.sun.jndi.ldap.LdapCtxFactory default if avail...
authorOlivier Lamy <olamy@apache.org>
Fri, 22 Feb 2013 16:04:29 +0000 (16:04 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 22 Feb 2013 16:04:29 +0000 (16:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1449089 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/runtime/DefaultRedbackRuntimeConfigurationAdmin.java

index 7801ded471d5de61adfa88087c58dceaef06d858..e582f628e946c1d9a19daaf2859eaab13e9bc1f9 100644 (file)
@@ -53,7 +53,7 @@ import java.util.Set;
  * @author Olivier Lamy
  * @since 1.4-M4
  */
-@Service( "userConfiguration#archiva" )
+@Service("userConfiguration#archiva")
 public class DefaultRedbackRuntimeConfigurationAdmin
     implements RedbackRuntimeConfigurationAdmin, UserConfiguration
 {
@@ -64,11 +64,11 @@ public class DefaultRedbackRuntimeConfigurationAdmin
     private ArchivaConfiguration archivaConfiguration;
 
     @Inject
-    @Named( value = "userConfiguration#redback" )
+    @Named(value = "userConfiguration#redback")
     UserConfiguration userConfiguration;
 
     @Inject
-    @Named( value = "cache#users" )
+    @Named(value = "cache#users")
     private Cache usersCache;
 
     @PostConstruct
@@ -128,7 +128,10 @@ public class DefaultRedbackRuntimeConfigurationAdmin
                                                            ldapConfiguration.getBaseDn() ) );
 
                 ldapConfiguration.setContextFactory(
-                    userConfiguration.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY, null ) );
+                    userConfiguration.getString( UserConfigurationKeys.LDAP_CONTEX_FACTORY,
+                                                 isSunContextFactoryAvailable()
+                                                     ? "com.sun.jndi.ldap.LdapCtxFactory"
+                                                     : "" ) );
                 ldapConfiguration.setBindDn(
                     userConfiguration.getConcatenatedList( UserConfigurationKeys.LDAP_BINDDN, null ) );
                 ldapConfiguration.setPassword(
@@ -226,6 +229,19 @@ public class DefaultRedbackRuntimeConfigurationAdmin
         }
     }
 
+    private boolean isSunContextFactoryAvailable()
+    {
+        try
+        {
+            return Thread.currentThread().getContextClassLoader().loadClass( "com.sun.jndi.ldap.LdapCtxFactory" )
+                != null;
+        }
+        catch ( ClassNotFoundException e )
+        {
+            return false;
+        }
+    }
+
     public RedbackRuntimeConfiguration getRedbackRuntimeConfiguration()
     {
         return build( archivaConfiguration.getConfiguration().getRedbackRuntimeConfiguration() );