public void testChangingMapBaseDN()
throws Exception
{
String mapperDNString = "cn=Exact Match,cn=Identity Mappers,cn=config";
DN mapperDN = DN.decode(mapperDNString);
IdentityMapper mapper = DirectoryServer.getIdentityMapper(mapperDN);
assertNotNull(mapper);
assertTrue(mapper instanceof ExactMatchIdentityMapper);
// Create a user entry and add it to the directory.
TestCaseUtils.initializeTestBackend(true);
Entry userEntry = TestCaseUtils.makeEntry(
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password");
InternalClientConnection conn =
InternalClientConnection.getRootConnection();
AddOperation addOperation =
conn.processAdd(userEntry.getDN(), userEntry.getObjectClasses(),
userEntry.getUserAttributes(),
userEntry.getOperationalAttributes());
assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS);
// Verify that we can retrieve the user.
Entry mappedEntry = mapper.getEntryForID("test");
assertNotNull(mappedEntry);
assertEquals(mappedEntry.getDN(), DN.decode("uid=test,o=test"));
// Create a modification to set the map base DN to "dc=example,dc=com".
ArrayList<ByteString> values = new ArrayList<ByteString>();
values.add(ByteString.valueOf("dc=example,dc=com"));
ArrayList<RawModification> mods = new ArrayList<RawModification>();
mods.add(new LDAPModification(ModificationType.REPLACE,
new LDAPAttribute("ds-cfg-match-base-dn",
values)));
ModifyOperation modifyOperation =
conn.processModify(ByteString.valueOf(mapperDNString), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
// Verify that we can't find the user anymore.
mappedEntry = mapper.getEntryForID("test");
assertNull(mappedEntry);
// Change the base DN to "o=test".
values.set(0, ByteString.valueOf("o=test"));
modifyOperation =
conn.processModify(ByteString.valueOf(mapperDNString), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
// Verify that we can retrieve the user again.
mappedEntry = mapper.getEntryForID("test");
assertNotNull(mappedEntry);
assertEquals(mappedEntry.getDN(), DN.decode("uid=test,o=test"));
// Change the configuration back to its original setting.
values.clear();
modifyOperation =
conn.processModify(ByteString.valueOf(mapperDNString), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
// Verify that we can still retrieve the user.
mappedEntry = mapper.getEntryForID("test");
assertNotNull(mappedEntry);
assertEquals(mappedEntry.getDN(), DN.decode("uid=test,o=test"));
}