LDAP-248: DirContextAdapter now handles javax.naming.Name instances properly with regards to equality

LDAP-274: ODM now uses standard Spring converter (if present).
LDAP-275: Support for different Collection types in ODM
This commit is contained in:
Mattias Hellborg Arthursson
2013-10-24 10:25:22 +02:00
parent 27593ac973
commit c2abc9660e
25 changed files with 1422 additions and 133 deletions

View File

@@ -0,0 +1,74 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* 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.springframework.ldap.itest.odm;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.DnAttribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import javax.naming.Name;
import java.util.Set;
/**
* @author Mattias Hellborg Arthursson
*/
@Entry(objectClasses = {"top", "groupOfUniqueNames"}, base = "cn=groups")
public class Group {
@Id
private Name dn;
@Attribute(name="cn")
@DnAttribute("cn")
private String name;
@Attribute(name="uniqueMember")
private Set<Name> members;
public Name getDn() {
return dn;
}
public void setDn(Name dn) {
this.dn = dn;
}
public Set<Name> getMembers() {
return members;
}
public void setMembers(Set<Name> members) {
this.members = members;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void addMember(Name member) {
members.add(member);
}
public void removeMember(Name member) {
members.remove(member);
}
}

View File

@@ -58,6 +58,16 @@ public class LdapTemplateBindUnbindITest extends
verifyCleanup();
}
@Test
public void testBindGroupOfUniqueNamesWithNameValues() {
DirContextAdapter ctx = new DirContextAdapter(LdapUtils.newLdapName("cn=TEST,ou=groups"));
ctx.addAttributeValue("cn", "TEST");
ctx.addAttributeValue("objectclass", "top");
ctx.addAttributeValue("objectclass", "groupOfUniqueNames");
ctx.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se"));
tested.bind(ctx);
}
@Test
public void testBindAndUnbindWithAttributesUsingLdapName() {
Attributes attributes = setupAttributes();

View File

@@ -0,0 +1,148 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* 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.springframework.ldap.itest.odm;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.Name;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.ldap.query.LdapQueryBuilder.query;
/**
* @author Mattias Hellborg Arthursson
*/
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
@Test
public void testFindOne() {
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
assertNotNull(group);
assertEquals("ROLE_USER", group.getName());
assertEquals(5, group.getMembers().size());
Set<Name> members = group.getMembers();
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se")));
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se")));
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Norway,dc=jayway,dc=se")));
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company2,c=Sweden,dc=jayway,dc=se")));
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se")));
}
@Test
public void testRemoveMember() {
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
group.removeMember(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se"));
tested.update(group);
Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
Set<Name> members = verification.getMembers();
assertEquals(4, members.size());
assertFalse(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se")));
}
@Test
public void testRemoveMemberSyntacticallyEqual() {
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
group.removeMember(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden, DC=jayway,DC=se"));
tested.update(group);
Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
Set<Name> members = verification.getMembers();
assertEquals(4, members.size());
assertFalse(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se")));
}
@Test
public void testAddMember() {
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
group.addMember(LdapUtils.newLdapName("cn=Some Person+sn=Person,ou=company1,c=Norway,dc=jayway,dc=se"));
tested.update(group);
Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
Set<Name> members = verification.getMembers();
assertEquals(6, members.size());
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person+sn=Person,ou=company1,c=Norway,dc=jayway,dc=se")));
}
@Test
public void testAddMemberDuplicate() {
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
group.addMember(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se"));
tested.update(group);
Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
Set<Name> members = verification.getMembers();
assertEquals(5, members.size());
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se")));
}
@Test
public void testAddMemberSyntacticallyEqualDuplicate() {
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
group.addMember(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,DC=jayway,DC=se"));
tested.update(group);
Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
Set<Name> members = verification.getMembers();
assertEquals(5, members.size());
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se")));
}
@Test
public void testSetMembersSyntacticallyEqual() {
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
group.setMembers(new HashSet<Name>(){{
add(LdapUtils.newLdapName("CN=Some Person,OU=company1, C=Sweden, DC=jayway,DC=se"));
add(LdapUtils.newLdapName("CN=Some Person2, OU=company1,C=Sweden,DC=jayway, DC=se"));
}});
tested.update(group);
Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
Set<Name> members = verification.getMembers();
assertEquals(2, members.size());
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se")));
assertTrue(members.contains(LdapUtils.newLdapName("cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se")));
}
}