From: Mathieu Baudier Date: Mon, 23 Nov 2009 13:54:20 +0000 (+0000) Subject: Improve Apache directory server X-Git-Tag: argeo-commons-2.1.30~1700 X-Git-Url: http://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=c6c3aa132f6559ac1e2fa015cf2efba92802eba0 Improve Apache directory server git-svn-id: https://svn.argeo.org/commons/trunk@3148 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/security/demo/init.ldif b/security/demo/init.ldif deleted file mode 100644 index 9fb8d4b6f..000000000 --- a/security/demo/init.ldif +++ /dev/null @@ -1,74 +0,0 @@ -dn: dc=demo,dc=argeo,dc=org -objectClass: domain -objectClass: extensibleObject -objectClass: top -dc: springsecurity - -dn: ou=groups,dc=demo,dc=argeo,dc=org -objectClass: organizationalUnit -objectClass: top -ou: groups - -dn: ou=users,dc=demo,dc=argeo,dc=org -objectClass: organizationalUnit -objectClass: top -ou: users - -dn: uid=demo,ou=users,dc=demo,dc=argeo,dc=org -objectClass: organizationalPerson -objectClass: person -objectClass: inetOrgPerson -objectClass: top -cn: demo User -description: Demo user -givenname: Demo -mail: demo@localhost -sn: User -uid: demo -userpassword:: e1NIQX1pZVNWNTVRYytlUU9hWURSU2hhL0Fqek5USkU9 - -dn: uid=root,ou=users,dc=demo,dc=argeo,dc=org -objectClass: person -objectClass: inetOrgPerson -objectClass: organizationalPerson -objectClass: top -cn: demo User -description: Superuser -givenname: Root -mail: root@localhost -sn: Root -uid: root -userpassword:: e1NIQX1pZVNWNTVRYytlUU9hWURSU2hhL0Fqek5USkU9 - -dn: uid=frodo,ou=users,dc=demo,dc=argeo,dc=org -objectClass: person -objectClass: inetOrgPerson -objectClass: organizationalPerson -objectClass: top -cn: demo User -description: Heroe -givenname: Frodo -mail: frodo@localhost -sn: User -uid: frodo -userpassword:: e1NIQX1pZVNWNTVRYytlUU9hWURSU2hhL0Fqek5USkU9 - -dn: uid=gandalf,ou=users,dc=demo,dc=argeo,dc=org -objectClass: organizationalPerson -objectClass: person -objectClass: inetOrgPerson -objectClass: top -cn: root User -description: Superuser -givenname: Gandalf -mail: admin@localhost -sn: User -uid: gandalf -userpassword:: e1NIQX1pZVNWNTVRYytlUU9hWURSU2hhL0Fqek5USkU9 - -dn: cn=admin,ou=groups,dc=demo,dc=argeo,dc=org -objectClass: groupOfUniqueNames -objectClass: top -cn: admin -uniquemember: uid=gandalf,ou=users,dc=demo,dc=argeo,dc=org -uniquemember: uid=root,ou=users,dc=demo,dc=argeo,dc=org diff --git a/security/demo/org.argeo.security.demo.ldap/META-INF/MANIFEST.MF b/security/demo/org.argeo.security.demo.ldap/META-INF/MANIFEST.MF new file mode 100644 index 000000000..00885883a --- /dev/null +++ b/security/demo/org.argeo.security.demo.ldap/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Bundle-SymbolicName: org.argeo.security.demo.ldap +Bundle-Version: 0.1.2.SNAPSHOT +Fragment-Host: org.argeo.security.manager.ldap diff --git a/security/demo/org.argeo.security.demo.ldap/ldap.properties b/security/demo/org.argeo.security.demo.ldap/ldap.properties new file mode 100644 index 000000000..970468a8a --- /dev/null +++ b/security/demo/org.argeo.security.demo.ldap/ldap.properties @@ -0,0 +1,5 @@ +argeo.ldap.rootdn=dc=demo,dc=argeo,dc=org +argeo.ldap.host=localhost +argeo.ldap.port=10389 +argeo.ldap.manager.userdn=uid=admin,ou=system +argeo.ldap.manager.password=secret diff --git a/security/demo/pom.xml b/security/demo/pom.xml index 9da7b0927..67cb9c7dc 100644 --- a/security/demo/pom.xml +++ b/security/demo/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.argeo.commons @@ -26,7 +27,7 @@ false - + org.springframework.osgi.extender, org.springframework.osgi.web.extender, org.argeo.dep.osgi.catalina.start, @@ -35,12 +36,12 @@ org.argeo.security.ria, org.argeo.security.core, org.argeo.server.ads.server - - + + ${basedir};in=*;ex=pom.xml;ex=target;ex=.*;ex=*.ldif, ${basedir}/../modules;in=*;ex=pom.xml;ex=target;ex=.*, ${basedir}/../../server/modules;in=*;ex=pom.xml;ex=target;ex=.*, - + @@ -94,5 +95,13 @@ org.springframework.osgi org.springframework.osgi.web.extender + + + + org.argeo.commons.server + org.argeo.server.ads + 0.1.2-SNAPSHOT + + \ No newline at end of file diff --git a/security/modules/org.argeo.security.manager.ldap/META-INF/MANIFEST.MF b/security/modules/org.argeo.security.manager.ldap/META-INF/MANIFEST.MF index bb61a8fee..7ef09fd7e 100644 --- a/security/modules/org.argeo.security.manager.ldap/META-INF/MANIFEST.MF +++ b/security/modules/org.argeo.security.manager.ldap/META-INF/MANIFEST.MF @@ -2,6 +2,7 @@ Bundle-SymbolicName: org.argeo.security.manager.ldap Bundle-Version: 0.1.2.SNAPSHOT Import-Package: org.argeo.security, org.argeo.security.ldap, + org.springframework.beans.factory.config, org.springframework.ldap.core.support, org.springframework.security, org.springframework.security.ldap, diff --git a/security/modules/org.argeo.security.manager.ldap/META-INF/spring/ldap-osgi.xml b/security/modules/org.argeo.security.manager.ldap/META-INF/spring/ldap-osgi.xml new file mode 100644 index 000000000..49ad482ce --- /dev/null +++ b/security/modules/org.argeo.security.manager.ldap/META-INF/spring/ldap-osgi.xml @@ -0,0 +1,17 @@ + + + + + + + + + \ No newline at end of file diff --git a/security/modules/org.argeo.security.manager.ldap/META-INF/spring/ldap.xml b/security/modules/org.argeo.security.manager.ldap/META-INF/spring/ldap.xml index 534bfe5df..c3cea65d4 100644 --- a/security/modules/org.argeo.security.manager.ldap/META-INF/spring/ldap.xml +++ b/security/modules/org.argeo.security.manager.ldap/META-INF/spring/ldap.xml @@ -5,6 +5,16 @@ http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"> + + + + + osgibundle:ldap.properties + + + + @@ -15,9 +25,10 @@ - - - + + + - - - - + + --> diff --git a/security/modules/org.argeo.security.manager.ldap/META-INF/spring/osgi.xml b/security/modules/org.argeo.security.manager.ldap/META-INF/spring/osgi.xml deleted file mode 100644 index 49ad482ce..000000000 --- a/security/modules/org.argeo.security.manager.ldap/META-INF/spring/osgi.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/server/modules/org.argeo.server.ads.server/META-INF/MANIFEST.MF b/server/modules/org.argeo.server.ads.server/META-INF/MANIFEST.MF index c58d8be49..d5060c345 100644 --- a/server/modules/org.argeo.server.ads.server/META-INF/MANIFEST.MF +++ b/server/modules/org.argeo.server.ads.server/META-INF/MANIFEST.MF @@ -17,7 +17,5 @@ Import-Package: org.apache.directory.server.configuration, org.apache.directory.server.jndi, org.apache.directory.server.ldap.support.extended, org.apache.directory.shared.asn1.codec, - org.springframework.beans.factory.config, - org.springframework.ldap.core.support, - org.springframework.security.config, - org.springframework.security.ldap + org.argeo.server.ads, + org.springframework.beans.factory.config diff --git a/server/modules/org.argeo.server.ads.server/META-INF/spring/ads.xml b/server/modules/org.argeo.server.ads.server/META-INF/spring/ads.xml index 593234f1b..6f7f6a615 100644 --- a/server/modules/org.argeo.server.ads.server/META-INF/spring/ads.xml +++ b/server/modules/org.argeo.server.ads.server/META-INF/spring/ads.xml @@ -1,9 +1,59 @@ - + - + + + + + osgibundle:ads.properties + + + - + + + + + + + + osgibundle:init.ldif + + + + + + + + simple + ${argeo.ldap.manager.userdn} + ${argeo.ldap.manager.password} + + + + + + + + + + + + diff --git a/server/modules/org.argeo.server.ads.server/META-INF/spring/server.xml b/server/modules/org.argeo.server.ads.server/META-INF/spring/server.xml index ca83c1f6f..2bf80b941 100644 --- a/server/modules/org.argeo.server.ads.server/META-INF/spring/server.xml +++ b/server/modules/org.argeo.server.ads.server/META-INF/spring/server.xml @@ -4,37 +4,6 @@ "http://www.springframework.org/dtd/spring-beans.dtd"> - - - - simple - uid=admin,ou=system - secret - - - - - - - - - - @@ -66,12 +35,17 @@ --> + + + @@ -123,7 +97,7 @@ --> - + @@ -305,12 +279,12 @@ - + + ]]> @@ -319,7 +293,7 @@ class="org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration"> - + + workDir="${argeo.osgi.data.dir}/tomcat/work"> + + org.argeo.commons.server + org.argeo.server.ads + 0.1.2-SNAPSHOT + + \ No newline at end of file diff --git a/server/runtime/org.argeo.server.ads/.classpath b/server/runtime/org.argeo.server.ads/.classpath new file mode 100644 index 000000000..16f01e2ee --- /dev/null +++ b/server/runtime/org.argeo.server.ads/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/server/runtime/org.argeo.server.ads/.project b/server/runtime/org.argeo.server.ads/.project new file mode 100644 index 000000000..831bb1b8d --- /dev/null +++ b/server/runtime/org.argeo.server.ads/.project @@ -0,0 +1,23 @@ + + + org.argeo.server.ads + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/server/runtime/org.argeo.server.ads/.settings/org.eclipse.jdt.core.prefs b/server/runtime/org.argeo.server.ads/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..96aed002c --- /dev/null +++ b/server/runtime/org.argeo.server.ads/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Nov 23 13:34:23 CET 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/server/runtime/org.argeo.server.ads/.settings/org.maven.ide.eclipse.prefs b/server/runtime/org.argeo.server.ads/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..8a80a771a --- /dev/null +++ b/server/runtime/org.argeo.server.ads/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Mon Nov 23 13:34:22 CET 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/server/runtime/org.argeo.server.ads/pom.xml b/server/runtime/org.argeo.server.ads/pom.xml new file mode 100644 index 000000000..f5894520c --- /dev/null +++ b/server/runtime/org.argeo.server.ads/pom.xml @@ -0,0 +1,65 @@ + + 4.0.0 + + org.argeo.commons.server + runtime + 0.1.2-SNAPSHOT + .. + + org.argeo.server.ads + Commons Server Apache Directory Server + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.felix + maven-bundle-plugin + ${version.maven-bundle-plugin} + + + + org.argeo.server.ads.* + + + + + + + + + + org.apache.directory + com.springsource.org.apache.directory.server.jndi + + + + + org.apache.commons + com.springsource.org.apache.commons.io + + + + + org.springframework + org.springframework.beans + + + + + org.slf4j + com.springsource.slf4j.org.apache.commons.logging + + + diff --git a/server/runtime/org.argeo.server.ads/src/main/java/org/argeo/server/ads/AdsContainer.java b/server/runtime/org.argeo.server.ads/src/main/java/org/argeo/server/ads/AdsContainer.java new file mode 100644 index 000000000..4a36f721d --- /dev/null +++ b/server/runtime/org.argeo.server.ads/src/main/java/org/argeo/server/ads/AdsContainer.java @@ -0,0 +1,138 @@ +package org.argeo.server.ads; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.naming.directory.InitialDirContext; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.directory.server.configuration.MutableServerStartupConfiguration; +import org.apache.directory.server.core.configuration.ShutdownConfiguration; +import org.apache.directory.server.jndi.ServerContextFactory; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.core.io.Resource; +import org.springframework.util.Assert; + +public class AdsContainer implements InitializingBean, DisposableBean { + private final static Log log = LogFactory.getLog(AdsContainer.class); + + private MutableServerStartupConfiguration configuration; + private Properties environment = null; + private File workingDirectory = new File(System + .getProperty("java.io.tmpdir") + + File.separator + "argeo-apacheDirectoryServer"); + private List ldifs = new ArrayList(); + private File ldifDirectory; + private Boolean deleteWorkingDirOnExit = false; + + @SuppressWarnings("unchecked") + public void afterPropertiesSet() throws Exception { + + log.info("Starting directory server with id '" + + configuration.getInstanceId() + "' in directory " + + workingDirectory.getAbsolutePath()); + + if (deleteWorkingDirOnExit && workingDirectory.exists()) { + log.warn("Found existing directory " + workingDirectory + + " deleting it..."); + FileUtils.deleteDirectory(workingDirectory); + } + configuration.setWorkingDirectory(workingDirectory); + workingDirectory.mkdirs(); + + if (ldifDirectory != null) + configuration.setLdifDirectory(ldifDirectory); + else + configuration.setLdifDirectory(new File(workingDirectory + .getAbsolutePath() + + File.separator + "ldif")); + + if (ldifs.size() > 0) + configuration.getLdifDirectory().mkdirs(); + for (Resource ldif : ldifs) { + FileUtils.copyURLToFile(ldif.getURL(), new File(configuration + .getLdifDirectory().getAbsolutePath() + + File.separator + ldif.getFilename().replace(':', '_'))); + if (log.isDebugEnabled()) + log.debug("Copied " + ldif + " to LDIF directory " + + configuration.getLdifDirectory()); + } + + Properties env = new Properties(); + env.setProperty(Context.INITIAL_CONTEXT_FACTORY, + ServerContextFactory.class.getName()); + Assert.notNull(environment); + env.putAll(environment); + env.putAll(configuration.toJndiEnvironment()); + + try { + new InitialDirContext(env); + } catch (NamingException e) { + throw new RuntimeException( + "Failed to start Apache Directory server", e); + } + } + + @SuppressWarnings("unchecked") + public void destroy() throws Exception { + ShutdownConfiguration shutdown = new ShutdownConfiguration( + configuration.getInstanceId()); + + Properties env = new Properties(); + env.setProperty(Context.INITIAL_CONTEXT_FACTORY, + ServerContextFactory.class.getName()); + Assert.notNull(environment); + env.putAll(environment); + env.putAll(shutdown.toJndiEnvironment()); + + log.info("Shutting down directory server with id '" + + configuration.getInstanceId() + "'"); + + try { + new InitialContext(env); + } catch (NamingException e) { + throw new RuntimeException( + "Failed to stop Apache Directory server", e); + } + + if (workingDirectory.exists() && deleteWorkingDirOnExit) { + if (log.isDebugEnabled()) + log.debug("Delete Apache DS working dir " + workingDirectory); + FileUtils.deleteDirectory(workingDirectory); + } + + } + + public void setConfiguration(MutableServerStartupConfiguration configuration) { + this.configuration = configuration; + } + + public void setWorkingDirectory(File workingDirectory) { + this.workingDirectory = workingDirectory; + } + + public void setEnvironment(Properties environment) { + this.environment = environment; + } + + public void setLdifs(List ldifs) { + this.ldifs = ldifs; + } + + public void setLdifDirectory(File ldifDirectory) { + this.ldifDirectory = ldifDirectory; + } + + public void setDeleteWorkingDirOnExit(Boolean deleteWorkingDirOnExit) { + this.deleteWorkingDirOnExit = deleteWorkingDirOnExit; + } + +} diff --git a/server/runtime/pom.xml b/server/runtime/pom.xml index 1d8f5e6ac..a643674aa 100644 --- a/server/runtime/pom.xml +++ b/server/runtime/pom.xml @@ -17,5 +17,6 @@ org.argeo.server.osgi org.argeo.server.jxl org.argeo.server.hibernate + org.argeo.server.ads \ No newline at end of file