You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/07/07 02:51:08 UTC
svn commit: r209553 - in /directory/sandbox/trunk/osgi-core/trunk/profile:
project.properties project.xml
src/main/java/org/apache/ldap/server/profile/Activator.java
Author: erodriguez
Date: Wed Jul 6 17:51:07 2005
New Revision: 209553
URL: http://svn.apache.org/viewcvs?rev=209553&view=rev
Log:
OSGi wrapper and Maven build files for Profile service.
Added:
directory/sandbox/trunk/osgi-core/trunk/profile/project.properties
directory/sandbox/trunk/osgi-core/trunk/profile/project.xml
directory/sandbox/trunk/osgi-core/trunk/profile/src/main/java/org/apache/ldap/server/profile/Activator.java
Added: directory/sandbox/trunk/osgi-core/trunk/profile/project.properties
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-core/trunk/profile/project.properties?rev=209553&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-core/trunk/profile/project.properties (added)
+++ directory/sandbox/trunk/osgi-core/trunk/profile/project.properties Wed Jul 6 17:51:07 2005
@@ -0,0 +1 @@
+module.path=apache-osgi-directory-profile
Added: directory/sandbox/trunk/osgi-core/trunk/profile/project.xml
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-core/trunk/profile/project.xml?rev=209553&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-core/trunk/profile/project.xml (added)
+++ directory/sandbox/trunk/osgi-core/trunk/profile/project.xml Wed Jul 6 17:51:07 2005
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <extend>${basedir}/../project.xml</extend>
+ <pomVersion>3</pomVersion>
+ <groupId>apache</groupId>
+ <artifactId>apache-profile</artifactId>
+ <name>Apache Profile Service</name>
+ <currentVersion>0.1.1</currentVersion>
+ <properties>
+ <osgi.import.package>org.apache.kerberos.store,org.osgi.framework,org.osgi.service.cm</osgi.import.package>
+ </properties>
+ <inceptionYear>2005</inceptionYear>
+ <package>org.apache.profile</package>
+ <shortDescription>Apache Profile Service</shortDescription>
+ <description>Apache Profile Service</description>
+ <dependencies>
+ <dependency>
+ <groupId>directory-shared</groupId>
+ <artifactId>kerberos-common</artifactId>
+ <version>0.4-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>directory-shared</groupId>
+ <artifactId>ldap-common</artifactId>
+ <version>0.9-SNAPSHOT</version>
+ <properties>
+ <osgi.jar.bundle>true</osgi.jar.bundle>
+ </properties>
+ </dependency>
+ <dependency>
+ <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>
+ </dependencies>
+</project>
+
Added: directory/sandbox/trunk/osgi-core/trunk/profile/src/main/java/org/apache/ldap/server/profile/Activator.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-core/trunk/profile/src/main/java/org/apache/ldap/server/profile/Activator.java?rev=209553&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-core/trunk/profile/src/main/java/org/apache/ldap/server/profile/Activator.java (added)
+++ directory/sandbox/trunk/osgi-core/trunk/profile/src/main/java/org/apache/ldap/server/profile/Activator.java Wed Jul 6 17:51:07 2005
@@ -0,0 +1,155 @@
+/*
+ * 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.ldap.server.profile;
+
+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.PrincipalStore;
+import org.apache.kerberos.store.PrincipalStoreImpl;
+import org.apache.ldap.common.name.LdapName;
+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;
+
+
+public class Activator implements BundleActivator
+{
+ public static final String FACTORY_PID = "org.apache.profile";
+
+ private PrincipalStore principalStore;
+ private ServiceRegistration principalRegistration;
+
+ /**
+ * 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
+ {
+ System.out.println( "Starting Apache Profile Service." );
+
+ ServiceReference storeReference = context.getServiceReference( InitialContextFactory.class.getName() );
+
+ InitialContextFactory factory = (InitialContextFactory) context.getService( storeReference );
+
+ Hashtable env = new Hashtable();
+ 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( KDC_ENTRY_BASEDN_KEY ) )
+ {
+ String baseDn = ( String ) env.get( KDC_ENTRY_BASEDN_KEY );
+ searchBaseDn = getRelativeName( ctx, baseDn );
+ }
+
+ principalStore = new PrincipalStoreImpl( ctx, searchBaseDn );
+
+ Dictionary parameters = new Hashtable();
+ principalRegistration = context.registerService( PrincipalStore.class.getName(), principalStore, parameters );
+ }
+
+ /**
+ * 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 Profile Service." );
+
+ if ( principalRegistration != null )
+ {
+ principalRegistration.unregister();
+ }
+
+ principalRegistration = null;
+ principalStore = 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" );
+ }
+}
+