directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r265030 - in /directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos: ./ src/main/java/org/apache/kerberos/
Date Wed, 31 Aug 2005 12:31:17 GMT
Author: erodriguez
Date: Wed Aug 31 05:30:53 2005
New Revision: 265030

URL: http://svn.apache.org/viewcvs?rev=265030&view=rev
Log:
Updates to kerberos protocol OSGi wrapper:
o  removed erroneous osgi imports
o  initial use of apacheds-core configuration mechanism
o  KdcConfiguration moved from kerberos-common to kerberos-protocol
o  removed dependency on Profile Service so kerberos now interacts directly with core via
InitialContextFactory
o  initial use of SLF4J logging, library dependency to POM
o  addition of MINA ServiceRegistry tracking using ServiceTracker

Added:
    directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosConfiguration.java
  (with props)
Modified:
    directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/project.xml
    directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/Activator.java
    directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosServer.java

Modified: directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/project.xml
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/project.xml?rev=265030&r1=265029&r2=265030&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/project.xml (original)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/project.xml Wed Aug 31
05:30:53 2005
@@ -8,8 +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,org.osgi.service.cm</osgi.import.package>
-    <osgi.export.package>org.apache.kerberos.jaas,org.apache.kerberos.exceptions,org.apache.kerberos.service,org.apache.kerberos.store,org.apache.kerberos.store.operations,org.apache.kerberos.messages,org.apache.kerberos.messages.value,org.apache.kerberos.messages.application,org.apache.kerberos.messages.components,org.apache.kerberos.crypto.encryption,org.apache.kerberos.io.decoder,org.apache.kerberos.io.encoder</osgi.export.package>
+    <osgi.import.package>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.kerberos</package>
@@ -19,7 +18,7 @@
     <dependency>
       <groupId>directory-protocols</groupId>
       <artifactId>kerberos-protocol</artifactId>
-      <version>0.4-SNAPSHOT</version>
+      <version>0.5.1-SNAPSHOT</version>
       <properties>
         <osgi.jar.bundle>true</osgi.jar.bundle>
       </properties>
@@ -27,15 +26,15 @@
     <dependency>
       <groupId>directory-shared</groupId>
       <artifactId>kerberos-common</artifactId>
-      <version>0.4-SNAPSHOT</version>
+      <version>0.5.1-SNAPSHOT</version>
       <properties>
         <osgi.jar.bundle>true</osgi.jar.bundle>
       </properties>
     </dependency>
     <dependency>
-      <groupId>directory-shared</groupId>
-      <artifactId>ldap-common</artifactId>
-      <version>0.9-SNAPSHOT</version>
+      <groupId>directory-asn1</groupId>
+      <artifactId>asn1-der</artifactId>
+      <version>0.3-SNAPSHOT</version>
       <properties>
         <osgi.jar.bundle>true</osgi.jar.bundle>
       </properties>
@@ -49,14 +48,25 @@
       </properties>
     </dependency>
     <dependency>
-      <groupId>directory-asn1</groupId>
-      <artifactId>asn1-der</artifactId>
-      <version>0.3-SNAPSHOT</version>
+      <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.2-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>
@@ -65,6 +75,11 @@
         <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/kerberos/src/main/java/org/apache/kerberos/Activator.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/Activator.java?rev=265030&r1=265029&r2=265030&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/Activator.java
(original)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/Activator.java
Wed Aug 31 05:30:53 2005
@@ -20,7 +20,16 @@
 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.kerberos.store.JndiPrincipalStoreImpl;
 import org.apache.kerberos.store.PrincipalStore;
+import org.apache.ldap.common.name.LdapName;
 import org.apache.mina.registry.ServiceRegistry;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -46,35 +55,66 @@
     private KerberosServerFactory serverFactory = null;
     private ServiceRegistration registration = null;
 
+    private PrincipalStore principalStore;
+
+    /**
+     * 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 KDC_ENTRY_BASEDN_KEY = "kdc.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) throws BundleException
+    public void start( BundleContext context ) throws BundleException
     {
-        System.out.println("Starting Apache Kerberos.");
+        System.out.println( "Starting Apache Kerberos." );
 
-        tracker = new ServiceTracker(context, ServiceRegistry.class.getName(), null);
+        tracker = new ServiceTracker( context, ServiceRegistry.class.getName(), null );
         tracker.open();
 
         registry = (ServiceRegistry) tracker.getService();
 
-        ServiceReference storeReference = context.getServiceReference(PrincipalStore.class
-                .getName());
+        ServiceReference storeReference = context.getServiceReference( InitialContextFactory.class
+                .getName() );
 
-        Object ref = context.getService(storeReference);
+        InitialContextFactory factory = (InitialContextFactory) context.getService( storeReference
);
 
-        System.out.println("PrincipalStore retrieval got " + ref);
+        Hashtable env = new Hashtable( new KerberosConfiguration().toJndiEnvironment() );
+        loadEnvironment( env );
 
-        PrincipalStore store = (PrincipalStore) ref;
+        LdapContext ctx = null;
 
-        serverFactory = new KerberosServerFactory(registry, store);
+        try
+        {
+            ctx = (LdapContext) factory.getInitialContext( env );
+        }
+        catch ( NamingException ne )
+        {
+            ne.printStackTrace();
+            throw new BundleException( "Initial context load failed." );
+        }
+
+        Name searchBaseDn = null;
+
+        if ( env.containsKey( KDC_ENTRY_BASEDN_KEY ) )
+        {
+            String baseDn = (String) env.get( KDC_ENTRY_BASEDN_KEY );
+            searchBaseDn = getRelativeName( ctx, baseDn );
+        }
+
+        principalStore = new JndiPrincipalStoreImpl( ctx, searchBaseDn );
+
+        serverFactory = new KerberosServerFactory( registry, principalStore );
 
         Dictionary parameters = new Hashtable();
-        parameters.put(ConfigurationAdmin.SERVICE_FACTORYPID, FACTORY_PID);
-        registration = context.registerService(ManagedServiceFactory.class.getName(),
-                serverFactory, parameters);
+        parameters.put( ConfigurationAdmin.SERVICE_FACTORYPID, FACTORY_PID );
+        registration = context.registerService( ManagedServiceFactory.class.getName(),
+                serverFactory, parameters );
 
         ServiceReference adminRef = null;
         try
@@ -83,39 +123,39 @@
             Configuration[] configs = null;
             try
             {
-                adminRef = context.getServiceReference(ConfigurationAdmin.class.getName());
+                adminRef = context.getServiceReference( ConfigurationAdmin.class.getName()
);
 
                 // Potential start order problem!
-                if (adminRef != null)
+                if ( adminRef != null )
                 {
-                    admin = (ConfigurationAdmin) context.getService(adminRef);
+                    admin = (ConfigurationAdmin) context.getService( adminRef );
                     String filter = "(&(service.factoryPid=" + FACTORY_PID + ")"
                             + "(|(service.bundleLocation=" + context.getBundle().getLocation()
                             + ")" + "(service.bundleLocation=NULL)"
                             + "(!(service.bundleLocation=*))))";
-                    configs = admin.listConfigurations(filter);
+                    configs = admin.listConfigurations( filter );
                 }
             }
-            catch (Exception e)
+            catch ( Exception e )
             {
                 e.printStackTrace();
             }
 
-            if (admin == null || configs == null || configs.length == 0)
+            if ( admin == null || configs == null || configs.length == 0 )
             {
-                serverFactory.updated(KerberosServerFactory.DEFAULT_PID, KerberosConfig
-                        .getDefaultConfig());
+                serverFactory.updated( KerberosServerFactory.DEFAULT_PID, KerberosConfig
+                        .getDefaultConfig() );
             }
         }
-        catch (ConfigurationException ce)
+        catch ( ConfigurationException ce )
         {
             ce.printStackTrace();
         }
         finally
         {
-            if (adminRef != null)
+            if ( adminRef != null )
             {
-                context.ungetService(adminRef);
+                context.ungetService( adminRef );
             }
         }
     }
@@ -125,9 +165,11 @@
      * Logs that this service has stopped.
      * @param context the framework context for the bundle.
      */
-    public void stop(BundleContext context)
+    public void stop( BundleContext context )
     {
-        System.out.println("Stopping Apache Kerberos.");
+        System.out.println( "Stopping Apache Kerberos." );
+
+        principalStore = null;
 
         registration.unregister();
         registration = null;
@@ -136,5 +178,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 profiles." );
+            }
+        }
+        catch ( NamingException e )
+        {
+            throw new BundleException( "Failed to initialize search base for Apache profiles."
);
+        }
+
+        return searchBaseDn;
+    }
+
+    private void loadEnvironment( Hashtable env )
+    {
+        env.put( "java.naming.provider.url", "dc=example,dc=com" );
+        env.put( "java.naming.security.principal", "uid=admin,ou=system" );
+        env.put( "java.naming.security.authentication", "simple" );
+        env.put( "java.naming.security.credentials", "secret" );
+        env.put( "java.naming.factory.initial", "org.apache.ldap.server.jndi.CoreContextFactory"
);
+
+        env.put( "kdc.entry.basedn", "ou=Users,dc=example,dc=com" );
     }
 }

Added: directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosConfiguration.java?rev=265030&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosConfiguration.java
(added)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosConfiguration.java
Wed Aug 31 05:30:53 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.kerberos;
+
+import org.apache.ldap.server.configuration.Configuration;
+import org.apache.ldap.server.jndi.ContextFactoryService;
+
+public class KerberosConfiguration extends Configuration
+{
+    /**
+     * Creates a new instance with default settings.
+     */
+    public KerberosConfiguration()
+    {
+    }
+
+    /**
+     * Creates a new instance with default settings that operates on the
+     * {@link ContextFactoryService} with the specified ID.
+     */
+    public KerberosConfiguration( String instanceId )
+    {
+        setInstanceId( instanceId );
+    }
+}

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

Modified: directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosServer.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosServer.java?rev=265030&r1=265029&r2=265030&view=diff
==============================================================================
--- directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosServer.java
(original)
+++ directory/sandbox/trunk/osgi-protocol-providers/trunk/kerberos/src/main/java/org/apache/kerberos/KerberosServer.java
Wed Aug 31 05:30:53 2005
@@ -20,8 +20,8 @@
 import java.io.IOException;
 import java.util.Dictionary;
 
+import org.apache.kerberos.kdc.KdcConfiguration;
 import org.apache.kerberos.protocol.KerberosProtocolProvider;
-import org.apache.kerberos.service.KdcConfiguration;
 import org.apache.kerberos.store.PrincipalStore;
 import org.apache.mina.common.TransportType;
 import org.apache.mina.protocol.ProtocolProvider;



Mime
View raw message