Moved everything from mvn-build to trunk root.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
|
||||
public class HtmlRowLdapTreeVisitor implements LdapTreeVisitor {
|
||||
|
||||
private List<String> rows = new LinkedList<String>();
|
||||
|
||||
public void visit(DirContextOperations node, int currentDepth) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < currentDepth; i++) {
|
||||
sb.append(" ");
|
||||
}
|
||||
|
||||
sb.append("<a href='").append(getLinkForNode(node)).append("'>").append(node.getDn()).append("</a>")
|
||||
.append("<br>\n");
|
||||
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
protected String getLinkForNode(DirContextOperations node) {
|
||||
return "#";
|
||||
}
|
||||
|
||||
public List<String> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
|
||||
public class LdapTree {
|
||||
private final DirContextOperations node;
|
||||
|
||||
private List<LdapTree> subContexts = new LinkedList<LdapTree>();
|
||||
|
||||
public LdapTree(DirContextOperations node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public DirContextOperations getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public List<LdapTree> getSubContexts() {
|
||||
return subContexts;
|
||||
}
|
||||
|
||||
public void setSubContexts(List<LdapTree> subContexts) {
|
||||
this.subContexts = subContexts;
|
||||
}
|
||||
|
||||
public void addSubTree(LdapTree ldapTree) {
|
||||
subContexts.add(ldapTree);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void traverse(LdapTreeVisitor visitor) {
|
||||
traverse(visitor, 0);
|
||||
}
|
||||
|
||||
private void traverse(LdapTreeVisitor visitor, int currentDepth) {
|
||||
visitor.visit(node, currentDepth);
|
||||
for (LdapTree subContext : subContexts) {
|
||||
subContext.traverse(visitor, currentDepth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
|
||||
public class LdapTreeBuilder {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
public LdapTreeBuilder(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
public LdapTree getLdapTree(DistinguishedName root) {
|
||||
DirContextOperations context = ldapTemplate.lookupContext(root.toString());
|
||||
return getLdapTree(context);
|
||||
}
|
||||
|
||||
private LdapTree getLdapTree(final DirContextOperations rootContext) {
|
||||
final LdapTree ldapTree = new LdapTree(rootContext);
|
||||
ldapTemplate.listBindings(rootContext.getDn(), new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
DistinguishedName dn = (DistinguishedName) ctx.getDn();
|
||||
dn.prepend((DistinguishedName) rootContext.getDn());
|
||||
|
||||
ldapTree.addSubTree(getLdapTree(ctx));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
return ldapTree;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
|
||||
public interface LdapTreeVisitor {
|
||||
|
||||
public void visit(DirContextOperations node, int currentDepth);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.springframework.ldap.samples.utils;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.DirContextOperations;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
@ContextConfiguration(locations = { "/conf/testContext.xml" })
|
||||
public class LdapTreeBuilderIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
private LdapTreeBuilder tested;
|
||||
|
||||
@Test
|
||||
public void testGetLdapTree() {
|
||||
LdapTree ldapTree = tested.getLdapTree(new DistinguishedName("c=Sweden"));
|
||||
ldapTree.traverse(new TestVisitor());
|
||||
}
|
||||
|
||||
private static final class TestVisitor implements LdapTreeVisitor {
|
||||
private static final DistinguishedName DN_1 = new DistinguishedName("c=Sweden");
|
||||
|
||||
private static final DistinguishedName DN_2 = new DistinguishedName("ou=company1,c=Sweden");
|
||||
|
||||
private static final DistinguishedName DN_3 = new DistinguishedName("cn=Some Person,ou=company1,c=Sweden");
|
||||
|
||||
private static final DistinguishedName DN_4 = new DistinguishedName("cn=Some Person2,ou=company1,c=Sweden");
|
||||
|
||||
private Map<DistinguishedName, Integer> names = new LinkedHashMap<DistinguishedName, Integer>();
|
||||
|
||||
private Iterator<DistinguishedName> keyIterator;
|
||||
|
||||
public TestVisitor() {
|
||||
names.put(DN_1, 0);
|
||||
names.put(DN_2, 1);
|
||||
names.put(DN_3, 2);
|
||||
names.put(DN_4, 2);
|
||||
|
||||
keyIterator = names.keySet().iterator();
|
||||
}
|
||||
|
||||
public void visit(DirContextOperations node, int currentDepth) {
|
||||
DistinguishedName next = keyIterator.next();
|
||||
assertEquals(next, node.getDn());
|
||||
assertEquals(names.get(next).intValue(), currentDepth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<!--
|
||||
This context configuration file defines common beans,
|
||||
minimizing duplication in the various test context files.
|
||||
-->
|
||||
|
||||
<bean id="placeholderConfig"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:/conf/ldap.properties" />
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -0,0 +1,4 @@
|
||||
urls=ldap://127.0.0.1:3900
|
||||
userDn=uid=admin,ou=system
|
||||
password=secret
|
||||
base=dc=jayway,dc=se
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<import resource="classpath:/conf/commonTestContext.xml" />
|
||||
|
||||
<bean id="contextSource"
|
||||
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
|
||||
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
|
||||
<property name="defaultPartitionName" value="jayway" />
|
||||
<property name="principal" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
<property name="ldifFile" value="classpath:/setup_data.ldif" />
|
||||
<property name="port" value="3900" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean
|
||||
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">
|
||||
<constructor-arg ref="ldapTemplate" />
|
||||
</bean>
|
||||
</beans>
|
||||
36
samples/samples-utils/src/test/resources/setup_data.ldif
Normal file
36
samples/samples-utils/src/test/resources/setup_data.ldif
Normal file
@@ -0,0 +1,36 @@
|
||||
dn: c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Sweden
|
||||
description: The country of Sweden
|
||||
|
||||
dn: ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Sweden
|
||||
|
||||
dn: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company1, Some Person
|
||||
telephoneNumber: +46 555-123456
|
||||
|
||||
dn: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person2
|
||||
userPassword: password
|
||||
cn: Some Person2
|
||||
sn: Person2
|
||||
description: Sweden, Company1, Some Person2
|
||||
telephoneNumber: +46 555-654321
|
||||
|
||||
Reference in New Issue
Block a user