directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r265799 - in /directory/sandbox/trunk/osgi-protocol-providers/trunk/dns: ./ src/main/java/org/apache/dns/
Date Thu, 01 Sep 2005 23:01:16 GMT
Author: erodriguez
Date: Thu Sep  1 16:01:10 2005
New Revision: 265799

URL: http://svn.apache.org/viewcvs?rev=265799&view=rev
Log:
Updates to dns protocol OSGi wrapper:
o  initial use of apacheds-core configuration mechanism
o  dns now interacts with core via InitialContextFactory
o  initial use of SLF4J logging, library dependency to POM
o  addition of dynamic config dependency on Config Admin
o  addition of MINA ServiceRegistry tracking using ServiceTracker

Added:
    directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsConfiguration.java
  (with props)
Modified:
    directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/project.xml
    directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/Activator.java
    directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServer.java
    directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServerFactory.java

Modified: directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/project.xml
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/project.xml?rev=265799&r1=265798&r2=265799&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/project.xml (original)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/project.xml Thu Sep  1 16:01:10
2005
@@ -8,7 +8,7 @@
   <currentVersion>0.1.1</currentVersion>
   <properties>
     <osgi.bundle.category>Network Service</osgi.bundle.category>
-    <osgi.import.package>org.osgi.framework,org.apache.mina.registry,org.apache.mina.protocol,org.apache.mina.common</osgi.import.package>
+    <osgi.import.package>org.apache.ldap.server.jndi,org.apache.ldap.server.configuration,org.osgi.framework,org.apache.mina.registry,org.apache.mina.protocol,org.apache.mina.common,org.osgi.service.cm,org.osgi.util.tracker</osgi.import.package>
   </properties>
   <inceptionYear>2005</inceptionYear>
   <package>org.apache.dns</package>
@@ -18,10 +18,44 @@
     <dependency>
       <groupId>directory-protocols</groupId>
       <artifactId>dns-protocol</artifactId>
-      <version>0.1-SNAPSHOT</version>
+      <version>0.3-SNAPSHOT</version>
       <properties>
         <osgi.jar.bundle>true</osgi.jar.bundle>
       </properties>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>nlog4j</artifactId>
+      <version>1.2.14</version>
+      <url>http://slf4j.org/nlog4j</url>
+      <properties>
+        <osgi.jar.bundle>true</osgi.jar.bundle>
+      </properties>
+    </dependency>
+    <dependency>
+      <!-- bad containment of filter nodes -->
+      <groupId>directory-shared</groupId>
+      <artifactId>ldap-common</artifactId>
+      <version>0.9.3-SNAPSHOT</version>
+      <properties>
+        <osgi.jar.bundle>true</osgi.jar.bundle>
+      </properties>
+    </dependency>
+    <dependency>
+      <!-- bad containment of antlr exceptions -->
+      <groupId>antlr</groupId>
+      <artifactId>antlr</artifactId>
+      <version>2.7.2</version>
+      <url>http://antlr.org/</url>
+      <properties>
+        <osgi.jar.bundle>true</osgi.jar.bundle>
+      </properties>
+    </dependency>
+    <dependency>
+      <!-- required to load Configuration base class -->
+      <groupId>directory</groupId>
+      <artifactId>apacheds-core</artifactId>
+      <version>0.9.2-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>

Modified: directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/Activator.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/Activator.java?rev=265799&r1=265798&r2=265799&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/Activator.java
(original)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/Activator.java
Thu Sep  1 16:01:10 2005
@@ -20,9 +20,21 @@
 import java.util.Dictionary;
 import java.util.Hashtable;
 
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+import javax.naming.spi.InitialContextFactory;
+
+import org.apache.dns.store.JndiRecordStoreImpl;
+import org.apache.dns.store.RecordStore;
+import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.server.jndi.CoreContextFactory;
 import org.apache.mina.registry.ServiceRegistry;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.Configuration;
@@ -39,16 +51,27 @@
     public static final String FACTORY_PID = "org.apache.dns";
 
     private ServiceRegistry registry;
+    private ServiceTracker tracker;
+
     private DnsServerFactory serverFactory;
     private ServiceRegistration registration;
-    private ServiceTracker tracker;
+
+    private RecordStore store;
 
     /**
-     * Implements BundleActivator.start(). Logs that this service is starting and
-     * starts this service.
+     * The key of the property specifying where Kerberos users are stored.  If this
+     * property is not set the store defaults to performing a subtree search
+     * from the DN in the {@link Context#PROVIDER_URL}. If it is present a more
+     * efficient search is conducted on the more specific DN.
+     */
+    public static final String DNS_ENTRY_BASEDN_KEY = "dns.entry.basedn";
+
+    /**
+     * Implements BundleActivator.start().
+     * Logs that this service is starting and starts this service.
      * @param context the framework context for the bundle.
      */
-    public void start( BundleContext context )
+    public void start( BundleContext context ) throws BundleException
     {
         System.out.println( "Starting Apache DNS." );
 
@@ -57,7 +80,36 @@
 
         registry = (ServiceRegistry) tracker.getService();
 
-        serverFactory = new DnsServerFactory( registry );
+        ServiceReference storeReference = context.getServiceReference( InitialContextFactory.class.getName()
);
+
+        InitialContextFactory factory = (InitialContextFactory) context.getService( storeReference
);
+
+        Hashtable env = new Hashtable( new DnsConfiguration().toJndiEnvironment() );
+        loadEnvironment( env );
+
+        LdapContext ctx = null;
+
+        try
+        {
+            ctx = (LdapContext) factory.getInitialContext( env );
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            throw new BundleException( "Initial context load failed." );
+        }
+
+        Name searchBaseDn = null;
+
+        if ( env.containsKey( DNS_ENTRY_BASEDN_KEY ) )
+        {
+            String baseDn = (String) env.get( DNS_ENTRY_BASEDN_KEY );
+            searchBaseDn = getRelativeName( ctx, baseDn );
+        }
+
+        store = new JndiRecordStoreImpl( ctx, searchBaseDn );
+
+        serverFactory = new DnsServerFactory( registry, store );
 
         Dictionary parameters = new Hashtable();
         parameters.put( ConfigurationAdmin.SERVICE_FACTORYPID, FACTORY_PID );
@@ -106,13 +158,16 @@
     }
 
     /**
-     * Implements BundleActivator.stop(). Logs that this service has stopped.
+     * Implements BundleActivator.stop().
+     * Logs that this service has stopped.
      * @param context the framework context for the bundle.
      */
     public void stop( BundleContext context )
     {
         System.out.println( "Stopping Apache DNS." );
 
+        store = null;
+
         registration.unregister();
         registration = null;
 
@@ -120,5 +175,45 @@
         serverFactory = null;
 
         registry = null;
+    }
+
+    private Name getRelativeName( DirContext ctx, String baseDn ) throws BundleException
+    {
+        Name searchBaseDn = null;
+
+        try
+        {
+            LdapName ctxRoot = new LdapName( ctx.getNameInNamespace() );
+            searchBaseDn = new LdapName( baseDn );
+
+            if ( searchBaseDn.startsWith( ctxRoot ) )
+            {
+                for ( int ii = 0; ii < ctxRoot.size(); ii++ )
+                {
+                    searchBaseDn.remove( 0 );
+                }
+            }
+            else
+            {
+                throw new BundleException( "Invalid search base for Apache DNS records."
);
+            }
+        }
+        catch ( NamingException e )
+        {
+            throw new BundleException( "Failed to initialize search base for Apache DNS records."
);
+        }
+
+        return searchBaseDn;
+    }
+
+    private void loadEnvironment( Hashtable env )
+    {
+        env.put( Context.PROVIDER_URL, "ou=forward lookup zones,ou=dns,ou=system" );
+        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        env.put( Context.SECURITY_CREDENTIALS, "secret" );
+        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );
+
+        env.put( DNS_ENTRY_BASEDN_KEY, "ou=example.com,ou=forward lookup zones,ou=dns,ou=system"
);
     }
 }

Added: directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsConfiguration.java?rev=265799&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsConfiguration.java
(added)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsConfiguration.java
Thu Sep  1 16:01:10 2005
@@ -0,0 +1,40 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.dns;
+
+import org.apache.ldap.server.configuration.Configuration;
+import org.apache.ldap.server.jndi.ContextFactoryService;
+
+public class DnsConfiguration extends Configuration
+{
+    /**
+     * Creates a new instance with default settings.
+     */
+    public DnsConfiguration()
+    {
+    }
+
+    /**
+     * Creates a new instance with default settings that operates on the
+     * {@link ContextFactoryService} with the specified ID.
+     */
+    public DnsConfiguration( String instanceId )
+    {
+        setInstanceId( instanceId );
+    }
+}

Propchange: directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServer.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServer.java?rev=265799&r1=265798&r2=265799&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServer.java
(original)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServer.java
Thu Sep  1 16:01:10 2005
@@ -21,6 +21,8 @@
 import java.util.Dictionary;
 
 import org.apache.dns.protocol.DnsProtocolProvider;
+import org.apache.dns.service.DnsConfiguration;
+import org.apache.dns.store.RecordStore;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.protocol.ProtocolProvider;
 import org.apache.mina.registry.Service;
@@ -34,14 +36,16 @@
     private Service udpService;
 
     private DnsConfig config;
+    private RecordStore store;
 
     private String name;
     private int port = -1;
 
-    public DnsServer( DnsConfig config, ServiceRegistry registry )
+    public DnsServer( DnsConfig config, ServiceRegistry registry, RecordStore store )
     {
         this.config = config;
         this.registry = registry;
+        this.store = store;
 
         init();
     }
@@ -55,7 +59,7 @@
         {
             System.out.println( name + " starting on " + port );
 
-            provider = new DnsProtocolProvider();
+            provider = new DnsProtocolProvider( new DnsConfiguration(), store );
 
             udpService = new Service( name, TransportType.DATAGRAM, port );
             tcpService = new Service( name, TransportType.SOCKET, port );

Modified: directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServerFactory.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServerFactory.java?rev=265799&r1=265798&r2=265799&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServerFactory.java
(original)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/dns/src/main/java/org/apache/dns/DnsServerFactory.java
Thu Sep  1 16:01:10 2005
@@ -22,6 +22,7 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.dns.store.RecordStore;
 import org.apache.mina.registry.ServiceRegistry;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedServiceFactory;
@@ -30,14 +31,16 @@
 {
     final static String DEFAULT_PID = Activator.FACTORY_PID + ".default";
 
+    private final RecordStore store;
     private final ServiceRegistry registry;
     private final Map servers = new HashMap();
 
     Object updateLock = new Object();
 
-    DnsServerFactory( ServiceRegistry registry )
+    DnsServerFactory( ServiceRegistry registry, RecordStore store )
     {
         this.registry = registry;
+        this.store = store;
     }
 
     public void destroy()
@@ -76,7 +79,7 @@
             DnsServer dnsServer = (DnsServer) servers.get( pid );
             if ( dnsServer == null )
             {
-                dnsServer = new DnsServer( new DnsConfig( config ), registry );
+                dnsServer = new DnsServer( new DnsConfig( config ), registry, store );
                 servers.put( pid, dnsServer );
             }
             else
@@ -88,7 +91,7 @@
                     // the config for this service is different, so ...
                     // destroy the listener and recreate it with the new config.
                     deleted( pid );
-                    dnsServer = new DnsServer( new DnsConfig( config ), registry );
+                    dnsServer = new DnsServer( new DnsConfig( config ), registry, store );
                     servers.put( pid, dnsServer );
                 }
             }



Mime
View raw message