From 2c168b0663c851e3cd9150601200286be99d423b Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Mon, 22 Jul 2019 15:09:51 +0200 Subject: [PATCH] change subdomain, create contextlistener --- ldif/ldap-example-data.ldif | 20 +++++++++---------- pom.xml | 1 - .../ldap/DirectoryServiceRunner.java | 17 ++++++++-------- .../server/WebappDirectoryServer.java | 20 +++++++++++++++++++ .../jalin/ldapadmin/ldap/TestCreateGroup.java | 6 +++--- .../jalin/ldapadmin/ldap/TestCreateUser.java | 6 +++--- .../jalin/ldapadmin/ldap/TestDeleteUser.java | 6 +++--- .../de/jalin/ldapadmin/ldap/TestReadUser.java | 6 +++--- .../ldapadmin/ldap/TestUpdateAsBindUser.java | 6 +++--- .../ldap/TestUpdateAsSimpleUser.java | 8 ++++---- .../jalin/ldapadmin/ldap/TestUpdateUser.java | 6 +++--- 11 files changed, 60 insertions(+), 42 deletions(-) rename src/{test => main}/java/de/jalin/ldapadmin/ldap/DirectoryServiceRunner.java (89%) create mode 100644 src/main/java/de/jalin/ldapadmin/server/WebappDirectoryServer.java diff --git a/ldif/ldap-example-data.ldif b/ldif/ldap-example-data.ldif index 0c1e115..4e4e2b9 100644 --- a/ldif/ldap-example-data.ldif +++ b/ldif/ldap-example-data.ldif @@ -1,36 +1,36 @@ version: 1 -dn: dc=saastest,dc=example,dc=com +dn: dc=domain,dc=example,dc=com objectclass: top objectclass: domain administrativeRole: accessControlSpecificArea -dc: saastest +dc: domain -dn: cn=saastestAuthenticationRequirementsACISubentry,dc=saastest,dc=example,dc=com +dn: cn=domainAuthenticationRequirementsACISubentry,dc=domain,dc=example,dc=com objectClass: accessControlSubentry objectClass: subentry objectClass: top subtreeSpecification: { } -prescriptiveACI: { identificationTag "subtreeFullAccessACI", precedence 11, authenticationLevel simple, itemOrUserFirst userFirst: { userClasses { name { "uid=application,ou=bind,dc=saastest,dc=example,dc=com" } }, userPermissions { { protectedItems { entry, allUserAttributeTypesAndValues }, grantsAndDenials { grantCompare, grantBrowse, grantRename, grantRemove, grantAdd, grantRead, grantFilterMatch, grantReturnDN, grantModify } } } } } +prescriptiveACI: { identificationTag "subtreeFullAccessACI", precedence 11, authenticationLevel simple, itemOrUserFirst userFirst: { userClasses { name { "uid=application,ou=bind,dc=domain,dc=example,dc=com" } }, userPermissions { { protectedItems { entry, allUserAttributeTypesAndValues }, grantsAndDenials { grantCompare, grantBrowse, grantRename, grantRemove, grantAdd, grantRead, grantFilterMatch, grantReturnDN, grantModify } } } } } prescriptiveACI: { identificationTag "allUsersACI", precedence 9, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems { attributeType { userPassword } }, grantsAndDenials { denyRead, denyFilterMatch, denyCompare } }, { protectedItems { entry, allUserAttributeTypesAndValues }, grantsAndDenials { grantCompare, grantBrowse,grantDiscloseOnError, grantRead, grantFilterMatch, grantReturnDN } } } } } -cn: saastestAuthenticationRequirementsACISubentry +cn: domainAuthenticationRequirementsACISubentry -dn: ou=groups,dc=saastest,dc=example,dc=com +dn: ou=groups,dc=domain,dc=example,dc=com objectClass: top objectClass: organizationalUnit ou: groups -dn: ou=users,dc=saastest,dc=example,dc=com +dn: ou=users,dc=domain,dc=example,dc=com objectClass: top objectClass: organizationalUnit ou: users -dn: ou=bind,dc=saastest,dc=example,dc=com +dn: ou=bind,dc=domain,dc=example,dc=com objectClass: top objectClass: organizationalUnit ou: bind -dn: uid=admin,ou=users,dc=saastest,dc=example,dc=com +dn: uid=admin,ou=users,dc=domain,dc=example,dc=com objectClass: top objectClass: inetOrgPerson objectClass: person @@ -41,7 +41,7 @@ displayName: Directory Superuser uid: admin userPassword: admin-secret -dn: uid=application,ou=bind,dc=saastest,dc=example,dc=com +dn: uid=application,ou=bind,dc=domain,dc=example,dc=com objectClass: top objectClass: inetOrgPerson objectClass: person diff --git a/pom.xml b/pom.xml index 6092ad6..8a68322 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,6 @@ org.apache.directory.server apacheds-service 2.0.0.AM25 - test junit diff --git a/src/test/java/de/jalin/ldapadmin/ldap/DirectoryServiceRunner.java b/src/main/java/de/jalin/ldapadmin/ldap/DirectoryServiceRunner.java similarity index 89% rename from src/test/java/de/jalin/ldapadmin/ldap/DirectoryServiceRunner.java rename to src/main/java/de/jalin/ldapadmin/ldap/DirectoryServiceRunner.java index b141a79..7924dea 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/DirectoryServiceRunner.java +++ b/src/main/java/de/jalin/ldapadmin/ldap/DirectoryServiceRunner.java @@ -1,7 +1,6 @@ package de.jalin.ldapadmin.ldap; import java.io.File; -import java.io.FilenameFilter; import java.util.ArrayList; import java.util.List; @@ -28,18 +27,18 @@ public class DirectoryServiceRunner { private final DirectoryService service; - public DirectoryServiceRunner(final String dnString, final String ip, final String port) throws Exception { - service = initService(); + public DirectoryServiceRunner(final String partition, final String dnString, final String ip, final String port) throws Exception { + this.service = initService(partition); addPartition("ou=config", "config"); - addPartition(dnString, "example"); - service.startup(); + addPartition(dnString, partition); + this.service.startup(); loadData(); startServer(ip, port); } - private DirectoryService initService() throws Exception { + private DirectoryService initService(final String partition) throws Exception { final DefaultDirectoryServiceFactory factory = new DefaultDirectoryServiceFactory(); - factory.init("example"); + factory.init(partition); final DirectoryService directoryService = factory.getDirectoryService(); directoryService.setShutdownHookEnabled(true); directoryService.getChangeLog().setEnabled(false); @@ -85,7 +84,7 @@ public class DirectoryServiceRunner { if (serviceRunner == null) { final String dnName = "dc=" + name + ",dc=example,dc=com"; try { - serviceRunner = new DirectoryServiceRunner(dnName, "127.0.0.1", "10389"); + serviceRunner = new DirectoryServiceRunner("example", dnName, "127.0.0.1", "10389"); } catch (Exception e) { throw new DirectoryServiceException(e); } @@ -97,7 +96,7 @@ public class DirectoryServiceRunner { final String ip = args[1]; final String port = args[2]; try { - final DirectoryServiceRunner ads = new DirectoryServiceRunner(dnString, ip, port); + final DirectoryServiceRunner ads = new DirectoryServiceRunner("example", dnString, ip, port); final Entry result = ads.service.getAdminSession().lookup(new Dn(dnString)); System.out.println("Found entry : " + result); } catch (Exception e) { diff --git a/src/main/java/de/jalin/ldapadmin/server/WebappDirectoryServer.java b/src/main/java/de/jalin/ldapadmin/server/WebappDirectoryServer.java new file mode 100644 index 0000000..10d5c3a --- /dev/null +++ b/src/main/java/de/jalin/ldapadmin/server/WebappDirectoryServer.java @@ -0,0 +1,20 @@ +package de.jalin.ldapadmin.server; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +public class WebappDirectoryServer implements ServletContextListener { + + @Override + public void contextInitialized(final ServletContextEvent evt) { + final ServletContext ctx = evt.getServletContext(); + final String uri = ctx.getInitParameter("uri"); + } + + @Override + public void contextDestroyed(final ServletContextEvent evt) { + } + + +} diff --git a/src/test/java/de/jalin/ldapadmin/ldap/TestCreateGroup.java b/src/test/java/de/jalin/ldapadmin/ldap/TestCreateGroup.java index a8235af..e9803f4 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/TestCreateGroup.java +++ b/src/test/java/de/jalin/ldapadmin/ldap/TestCreateGroup.java @@ -14,18 +14,18 @@ import de.jalin.ldapadmin.beans.User; public class TestCreateGroup { - private static final String USERS_DN = "uid=${uid},ou=users,dc=saastest,dc=example,dc=com"; + private static final String USERS_DN = "uid=${uid},ou=users,dc=domain,dc=example,dc=com"; private LDAPSession session; @BeforeClass public static void setupClass() throws Exception { - DirectoryServiceRunner.assureServiceRunning("saastest"); + DirectoryServiceRunner.assureServiceRunning("domain"); } @Before public void setUp() throws Exception { - session = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); + session = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); } @After diff --git a/src/test/java/de/jalin/ldapadmin/ldap/TestCreateUser.java b/src/test/java/de/jalin/ldapadmin/ldap/TestCreateUser.java index 0520e9a..6b4ffc7 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/TestCreateUser.java +++ b/src/test/java/de/jalin/ldapadmin/ldap/TestCreateUser.java @@ -11,18 +11,18 @@ import de.jalin.ldapadmin.beans.User; public class TestCreateUser { - private static final String USERS_DN = "uid=pet,ou=users,dc=saastest,dc=example,dc=com"; + private static final String USERS_DN = "uid=pet,ou=users,dc=domain,dc=example,dc=com"; private LDAPSession session; @BeforeClass public static void setupClass() throws Exception { - DirectoryServiceRunner.assureServiceRunning("saastest"); + DirectoryServiceRunner.assureServiceRunning("domain"); } @Before public void setUp() throws Exception { - session = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); + session = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); } @After diff --git a/src/test/java/de/jalin/ldapadmin/ldap/TestDeleteUser.java b/src/test/java/de/jalin/ldapadmin/ldap/TestDeleteUser.java index a25e619..e692118 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/TestDeleteUser.java +++ b/src/test/java/de/jalin/ldapadmin/ldap/TestDeleteUser.java @@ -11,18 +11,18 @@ import de.jalin.ldapadmin.beans.User; public class TestDeleteUser { - private static final String USERS_DN = "uid=hei,ou=users,dc=saastest,dc=example,dc=com"; + private static final String USERS_DN = "uid=hei,ou=users,dc=domain,dc=example,dc=com"; private LDAPSession session; @BeforeClass public static void setupClass() throws Exception { - DirectoryServiceRunner.assureServiceRunning("saastest"); + DirectoryServiceRunner.assureServiceRunning("domain"); } @Before public void setUp() throws Exception { - session = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); + session = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); } @After diff --git a/src/test/java/de/jalin/ldapadmin/ldap/TestReadUser.java b/src/test/java/de/jalin/ldapadmin/ldap/TestReadUser.java index 984c919..19f177f 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/TestReadUser.java +++ b/src/test/java/de/jalin/ldapadmin/ldap/TestReadUser.java @@ -11,18 +11,18 @@ import de.jalin.ldapadmin.beans.User; public class TestReadUser { - private static final String USERS_DN = "uid=chr,ou=users,dc=saastest,dc=example,dc=com"; + private static final String USERS_DN = "uid=chr,ou=users,dc=domain,dc=example,dc=com"; private LDAPSession session; @BeforeClass public static void setupClass() throws Exception { - DirectoryServiceRunner.assureServiceRunning("saastest"); + DirectoryServiceRunner.assureServiceRunning("domain"); } @Before public void setUp() throws Exception { - session = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); + session = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); } @After diff --git a/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsBindUser.java b/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsBindUser.java index 91ced74..beb6de5 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsBindUser.java +++ b/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsBindUser.java @@ -15,18 +15,18 @@ import de.jalin.ldapadmin.beans.User; public class TestUpdateAsBindUser { - private static final String USERS_DN = "uid=pau,ou=users,dc=saastest,dc=example,dc=com"; + private static final String USERS_DN = "uid=pau,ou=users,dc=domain,dc=example,dc=com"; private LDAPSession session; @BeforeClass public static void setupClass() throws Exception { - DirectoryServiceRunner.assureServiceRunning("saastest"); + DirectoryServiceRunner.assureServiceRunning("domain"); } @Before public void setUp() throws Exception { - session = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=application,ou=bind,dc=saastest,dc=example,dc=com", "app-secret"); + session = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=application,ou=bind,dc=domain,dc=example,dc=com", "app-secret"); } @After diff --git a/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsSimpleUser.java b/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsSimpleUser.java index 064abe3..0e5451e 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsSimpleUser.java +++ b/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateAsSimpleUser.java @@ -17,16 +17,16 @@ import de.jalin.ldapadmin.beans.User; public class TestUpdateAsSimpleUser { - private static final String USERS_DN = "uid=mic,ou=users,dc=saastest,dc=example,dc=com"; + private static final String USERS_DN = "uid=mic,ou=users,dc=domain,dc=example,dc=com"; @BeforeClass public static void setupClass() throws Exception { - DirectoryServiceRunner.assureServiceRunning("saastest"); + DirectoryServiceRunner.assureServiceRunning("domain"); } @Before public void setUp() throws Exception { - final LDAPSession bindUserSession = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=application,ou=bind,dc=saastest,dc=example,dc=com", "app-secret"); + final LDAPSession bindUserSession = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=application,ou=bind,dc=domain,dc=example,dc=com", "app-secret"); final UsersDAO dao = new UsersDAO(bindUserSession); final User newUser = new User(); newUser.setDn(USERS_DN); @@ -54,7 +54,7 @@ public class TestUpdateAsSimpleUser { @Test public void test() { try { - final LDAPSession simpleUserSession = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=plp,ou=users,dc=saastest,dc=example,dc=com", "geheim"); + final LDAPSession simpleUserSession = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=plp,ou=users,dc=domain,dc=example,dc=com", "geheim"); final UsersDAO dao = new UsersDAO(simpleUserSession); final User existingUser = dao.loadUsers().get(USERS_DN); assertNull("user already exists", existingUser); diff --git a/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateUser.java b/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateUser.java index 14c5a59..b806caf 100644 --- a/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateUser.java +++ b/src/test/java/de/jalin/ldapadmin/ldap/TestUpdateUser.java @@ -14,18 +14,18 @@ import de.jalin.ldapadmin.beans.User; public class TestUpdateUser { - private static final String USERS_DN = "uid=kla,ou=users,dc=saastest,dc=example,dc=com"; + private static final String USERS_DN = "uid=kla,ou=users,dc=domain,dc=example,dc=com"; private LDAPSession session; @BeforeClass public static void setupClass() throws Exception { - DirectoryServiceRunner.assureServiceRunning("saastest"); + DirectoryServiceRunner.assureServiceRunning("domain"); } @Before public void setUp() throws Exception { - session = new LDAPSession("ldap://localhost:10389/dc=saastest,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); + session = new LDAPSession("ldap://localhost:10389/dc=domain,dc=example,dc=com", "uid=admin,ou=system", "streng-geheim"); } @After