You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dj...@apache.org on 2007/10/10 21:49:38 UTC

svn commit: r583592 - in /directory/apacheds/branches/bigbang: kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/ protocol-dns/src/main/java/org/apache/directory/server/dns/ protocol-dns/src/main/java/org/apache/directory/...

Author: djencks
Date: Wed Oct 10 12:49:37 2007
New Revision: 583592

URL: http://svn.apache.org/viewvc?rev=583592&view=rev
Log:
simplify the dns record store to use DirectoryService more directly instead of jndi fluff

Modified:
    directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java
    directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java

Modified: directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java?rev=583592&r1=583591&r2=583592&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java (original)
+++ directory/apacheds/branches/bigbang/kerberos-shared/src/main/java/org/apache/directory/server/kerberos/shared/store/SingleBaseSearch.java Wed Oct 10 12:49:37 2007
@@ -23,6 +23,7 @@
 
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.kerberos.shared.store.operations.*;
+import org.apache.directory.server.protocol.shared.ServiceConfigurationException;
 
 import javax.naming.directory.DirContext;
 import javax.naming.NamingException;
@@ -48,14 +49,8 @@
             ctx = directoryService.getJndiContext(searchBaseDn);
         } catch ( NamingException e )
         {
-            throw new IllegalStateException("Can't get context at" + searchBaseDn);
+            throw new ServiceConfigurationException("Can't get context at" + searchBaseDn, e);
         }
-//        env.put( Context.INITIAL_CONTEXT_FACTORY, config.getInitialContextFactory() );
-//        env.put( Context.PROVIDER_URL, config.getSearchBaseDn() );
-//        env.put( Context.SECURITY_AUTHENTICATION, config.getSecurityAuthentication() );
-//        env.put( Context.SECURITY_CREDENTIALS, config.getSecurityCredentials() );
-//        env.put( Context.SECURITY_PRINCIPAL, config.getSecurityPrincipal() );
-//        env.put( DirectoryService.JNDI_KEY, directoryService );
 
     }
 

Modified: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java?rev=583592&r1=583591&r2=583592&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java (original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java Wed Oct 10 12:49:37 2007
@@ -77,7 +77,7 @@
      */
     public void start() throws IOException
     {
-        RecordStore store = new JndiRecordStoreImpl( this, directoryService );
+        RecordStore store = new JndiRecordStoreImpl( getCatalogBaseDn(), getSearchBaseDn(), directoryService );
 
         DatagramAcceptorConfig udpConfig = new DatagramAcceptorConfig();
         udpConfig.setThreadModel( ThreadModel.MANUAL );

Modified: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java?rev=583592&r1=583591&r2=583592&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java (original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/JndiRecordStoreImpl.java Wed Oct 10 12:49:37 2007
@@ -20,46 +20,42 @@
 package org.apache.directory.server.dns.store.jndi;
 
 
+import java.util.Set;
+
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.dns.DnsConfiguration;
 import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.store.RecordStore;
 
-import java.util.Set;
-
 
 /**
- * A JNDI-backed implementation of the RecordStore interface.  This RecordStore uses
+ * A DirectoryService-backed implementation of the RecordStore interface.  This RecordStore uses
  * the Strategy pattern to either serve records based on a single base DN or to lookup
  * catalog mappings from directory configuration.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class JndiRecordStoreImpl implements RecordStore
 {
-    /** a handle on the configuration */
-    private DnsConfiguration config;
-    /** a handle on the provider factory */
-    private DirectoryService directoryService;
-    /** a handle on the searchh strategy */
-    private SearchStrategy strategy;
+    /**
+     * a handle on the searchh strategy
+     */
+    private final SearchStrategy strategy;
 
 
     /**
      * Creates a new instance of JndiRecordStoreImpl.
      *
-     * @param config
-     * @param directoryService
+     * @param catalogBaseDn base of catalog of searchDns
+     * @param searchBaseDn single search base for when there is no catalog
+     * @param directoryService DirectoryService backend for the searches.
      */
-    public JndiRecordStoreImpl( DnsConfiguration config, DirectoryService directoryService )
+    public JndiRecordStoreImpl( String catalogBaseDn, String searchBaseDn, DirectoryService directoryService )
     {
-        this.config = config;
-        this.directoryService = directoryService;
 
-        strategy = getSearchStrategy();
+        strategy = getSearchStrategy( catalogBaseDn, searchBaseDn, directoryService );
     }
 
 
@@ -69,15 +65,15 @@
     }
 
 
-    private SearchStrategy getSearchStrategy()
+    private SearchStrategy getSearchStrategy( String catalogBaseDn, String searchBaseDn, DirectoryService directoryService )
     {
-        if ( config.getCatalogBaseDn() != null )
+        if ( catalogBaseDn != null )
         {
             // build catalog from factory
-            return new MultiBaseSearch( config, directoryService );
+            return new MultiBaseSearch( catalogBaseDn, directoryService );
         }
 
         // use config for catalog baseDN
-        return new SingleBaseSearch( config, directoryService );
+        return new SingleBaseSearch( searchBaseDn, directoryService );
     }
 }

Modified: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java?rev=583592&r1=583591&r2=583592&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java (original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/MultiBaseSearch.java Wed Oct 10 12:49:37 2007
@@ -22,7 +22,6 @@
 
 
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.dns.DnsConfiguration;
 import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
@@ -31,16 +30,13 @@
 import org.apache.directory.server.protocol.shared.ServiceConfigurationException;
 import org.apache.directory.server.protocol.shared.catalog.Catalog;
 import org.apache.directory.server.protocol.shared.catalog.GetCatalog;
-import org.apache.directory.server.protocol.shared.store.ContextOperation;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import java.util.Hashtable;
+
 import java.util.Map;
 import java.util.Set;
 
@@ -58,26 +54,23 @@
     /** the LOG for this class */
     private static final Logger LOG = LoggerFactory.getLogger( MultiBaseSearch.class );
 
-    private Hashtable<String, Object> env = new Hashtable<String, Object>();
-    private Catalog catalog;
+    private final Catalog catalog;
+    private final DirectoryService directoryService;
 
 
-    MultiBaseSearch( DnsConfiguration config, DirectoryService directoryService )
+    MultiBaseSearch( String catalogBaseDn, DirectoryService directoryService )
     {
-        env.put( Context.INITIAL_CONTEXT_FACTORY, config.getInitialContextFactory() );
-        env.put( Context.PROVIDER_URL, config.getCatalogBaseDn() );
-        env.put( DirectoryService.JNDI_KEY, directoryService );
-
+        this.directoryService = directoryService;
         try
         {
-            DirContext ctx = new InitialDirContext( env );
+            DirContext ctx = directoryService.getJndiContext(catalogBaseDn);
             //noinspection unchecked
-            catalog = new DnsCatalog( ( Map<String, Object> ) execute( ctx, new GetCatalog() ) );
+            catalog = new DnsCatalog( ( Map<String, Object> ) new GetCatalog().execute( ctx, null ) );
         }
         catch ( Exception e )
         {
             LOG.error( e.getMessage(), e );
-            String message = "Failed to get catalog context " + env.get( Context.PROVIDER_URL );
+            String message = "Failed to get catalog context " + catalogBaseDn;
             throw new ServiceConfigurationException( message, e );
         }
     }
@@ -85,14 +78,12 @@
 
     public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
     {
-        Hashtable<String, Object> cloned = new Hashtable<String, Object>();
-        cloned.putAll( env );
-        cloned.put( Context.PROVIDER_URL, catalog.getBaseDn( question.getDomainName() ) );
-
         try
         {
-            DirContext ctx = new InitialDirContext( cloned );
-            return execute( ctx, new GetRecords( question ) );
+            GetRecords getRecords = new GetRecords( question );
+            String baseDn = catalog.getBaseDn( question.getDomainName() );
+            DirContext dirContext = directoryService.getJndiContext( baseDn );
+            return getRecords.execute( dirContext, null );
         }
         catch ( LdapNameNotFoundException lnnfe )
         {
@@ -103,7 +94,7 @@
         catch ( NamingException ne )
         {
             LOG.error( ne.getMessage(), ne );
-            String message = "Failed to get initial context " + env.get( Context.PROVIDER_URL );
+            String message = "Failed to get initial context " + question.getDomainName();
             throw new ServiceConfigurationException( message, ne );
         }
         catch ( Exception e )
@@ -115,14 +106,4 @@
     }
 
 
-    private Object execute( DirContext ctx, ContextOperation operation ) throws Exception
-    {
-        return operation.execute( ctx, null );
-    }
-
-
-    private Set<ResourceRecord> execute( DirContext ctx, DnsOperation operation ) throws Exception
-    {
-        return operation.execute( ctx, null );
-    }
 }

Modified: directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java?rev=583592&r1=583591&r2=583592&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java (original)
+++ directory/apacheds/branches/bigbang/protocol-dns/src/main/java/org/apache/directory/server/dns/store/jndi/SingleBaseSearch.java Wed Oct 10 12:49:37 2007
@@ -21,89 +21,65 @@
 package org.apache.directory.server.dns.store.jndi;
 
 
+import java.util.Set;
+
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.dns.DnsConfiguration;
 import org.apache.directory.server.dns.DnsException;
 import org.apache.directory.server.dns.messages.QuestionRecord;
 import org.apache.directory.server.dns.messages.ResourceRecord;
 import org.apache.directory.server.dns.messages.ResponseCode;
 import org.apache.directory.server.dns.store.jndi.operations.GetRecords;
 import org.apache.directory.server.protocol.shared.ServiceConfigurationException;
-import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import java.util.Hashtable;
-import java.util.Set;
-
 
 /**
  * A JNDI-backed search strategy implementation.  This search strategy searches a
  * single base DN for resource records.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class SingleBaseSearch implements SearchStrategy
 {
-    /** the LOG for this class */
+    /**
+     * the LOG for this class
+     */
     private static final Logger LOG = LoggerFactory.getLogger( SingleBaseSearch.class );
 
-    private DirContext ctx;
-    private Hashtable<String, Object> env = new Hashtable<String, Object>();
+    private final DirContext ctx;
 
 
-    SingleBaseSearch( DnsConfiguration config, DirectoryService directoryService )
+    SingleBaseSearch( String searchBaseDn, DirectoryService directoryService )
     {
-        env.put( Context.INITIAL_CONTEXT_FACTORY, config.getInitialContextFactory() );
-        env.put( Context.PROVIDER_URL, config.getSearchBaseDn() );
-        env.put( Context.SECURITY_AUTHENTICATION, config.getSecurityAuthentication() );
-        env.put( Context.SECURITY_CREDENTIALS, config.getSecurityCredentials() );
-        env.put( Context.SECURITY_PRINCIPAL, config.getSecurityPrincipal() );
-        env.put( DirectoryService.JNDI_KEY, directoryService );
+        try
+        {
+            ctx = directoryService.getJndiContext( searchBaseDn );
+        } catch ( NamingException e )
+        {
+            throw new ServiceConfigurationException( "Can't get context at" + searchBaseDn, e );
+        }
+
     }
 
 
     public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
     {
-        return execute( new GetRecords( question ) );
-    }
-
+        try
+        {
 
-    private Set<ResourceRecord> execute( DnsOperation operation ) throws DnsException
-    {
-    	try {
-    		
-	        if ( ctx == null )
-	        {
-	            try
-	            {
-	                ctx = new InitialDirContext( env );
-	            }
-		        catch ( LdapNameNotFoundException lnnfe )
-			    {
-			        LOG.debug( "Name for DNS record search does not exist.", lnnfe );
-			
-			        throw new DnsException( ResponseCode.NAME_ERROR );
-			    }
-	            catch ( NamingException ne )
-	            {
-	                LOG.error( ne.getMessage(), ne );
-	                String message = "Failed to get initial context " + env.get( Context.PROVIDER_URL );
-	                throw new ServiceConfigurationException( message, ne );
-	            }
-	        }
-	        
-	        return operation.execute( ctx, null );
+            return new GetRecords( question ).execute( ctx, null );
+        }
+        catch ( Exception e )
+        {
+            LOG.debug( "Unexpected error retrieving DNS records.", e );
+            throw new DnsException( ResponseCode.SERVER_FAILURE );
         }
-	    catch ( Exception e )
-	    {
-	        LOG.debug( "Unexpected error retrieving DNS records.", e );
-	        throw new DnsException( ResponseCode.SERVER_FAILURE );
-	    }
     }
+
+
 }