| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | * Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.adapter.server3x; |
| | | |
| | |
| | | */ |
| | | public static org.opends.server.types.RDN to(final RDN rdn) { |
| | | try { |
| | | return org.opends.server.types.RDN.decode(rdn.toString()); |
| | | return org.opends.server.types.RDN.valueOf(rdn.toString()); |
| | | } catch (Exception e) { |
| | | throw new IllegalStateException(e.getMessage(), e); |
| | | } |
| | |
| | | { |
| | | if (newRDN == null) |
| | | { |
| | | newRDN = RDN.decode(rawNewRDN.toString()); |
| | | newRDN = RDN.valueOf(rawNewRDN.toString()); |
| | | } |
| | | } |
| | | catch (DirectoryException de) |
| | |
| | | RDN newRDN; |
| | | try |
| | | { |
| | | newRDN = RDN.decode(rawNewRDN.toString()); |
| | | newRDN = RDN.valueOf(rawNewRDN.toString()); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyDNRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.api.ClientConnection; |
| | |
| | | return modifyDNOperation; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Processes an internal modify DN operation with the provided |
| | | * information. |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes an internal modify DN operation with the provided information. |
| | | * |
| | | * @param modifyDNRequest |
| | | * The modify DN request with information about the processing to perform. |
| | | * @return A reference to the modify DN operation that was processed and contains information about |
| | | * the result of the processing. |
| | | */ |
| | | public ModifyDNOperation processModifyDN(ModifyDNRequest modifyDNRequest) |
| | | { |
| | | org.forgerock.opendj.ldap.DN newSuperior = modifyDNRequest.getNewSuperior(); |
| | | return processModifyDN(to(modifyDNRequest.getName()), |
| | | to(modifyDNRequest.getNewRDN()), |
| | | modifyDNRequest.isDeleteOldRDN(), |
| | | newSuperior != null ? to(newSuperior) : null); |
| | | } |
| | | |
| | | /** |
| | | * Processes an internal search operation with the provided |
| | | * information. |
| | | * |
| | |
| | | String newRDN = "entryuuid=" + entryUUID + "+" + dn.rdn(); |
| | | try |
| | | { |
| | | return RDN.decode(newRDN); |
| | | return RDN.valueOf(newRDN); |
| | | } catch (DirectoryException e) |
| | | { |
| | | // cannot happen |
| | |
| | | return DN.valueOf(newRDN + "," + newSuperior); |
| | | } |
| | | final DN parentDn = getDN().parent(); |
| | | return parentDn.child(RDN.decode(newRDN)); |
| | | return parentDn.child(RDN.valueOf(newRDN)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * If a problem occurs while trying to decode the provided |
| | | * string as a RDN. |
| | | */ |
| | | public static RDN decode(String rdnString) throws DirectoryException |
| | | public static RDN valueOf(String rdnString) throws DirectoryException |
| | | { |
| | | // A null or empty RDN is not acceptable. |
| | | if (rdnString == null) |
| | |
| | | |
| | | try |
| | | { |
| | | newRDN = RDN.decode(rdnStr); |
| | | newRDN = RDN.valueOf(rdnStr); |
| | | } catch (DirectoryException de) |
| | | { |
| | | logger.traceException(de); |
| | |
| | | // moddn robert to robert2 |
| | | ModifyDNOperation modDNOp = connection.processModifyDN( |
| | | DN.valueOf("cn=Robert Hue," + baseDN5), |
| | | RDN.decode("cn=Robert Hue2"), true, |
| | | RDN.valueOf("cn=Robert Hue2"), true, |
| | | baseDN5); |
| | | waitForSearchOpResult(modDNOp, ResultCode.SUCCESS); |
| | | |
| | |
| | | final DN newSuperior = DN_OTEST2; |
| | | ModifyDNOperation op = new ModifyDNOperationBasis(connection, 1, 1, null, |
| | | DN.valueOf("uid=" + testName + "4," + replicaId.getBaseDN()), // entryDN |
| | | RDN.decode("uid=" + testName + "new4"), // new rdn |
| | | RDN.valueOf("uid=" + testName + "new4"), // new rdn |
| | | true, // deleteoldrdn |
| | | newSuperior); |
| | | op.setAttachment(SYNCHROCONTEXT, new ModifyDnContext(csn, testName + "uuid4", "newparentId")); |
| | |
| | | assertTrue(groupInstance.isMember(user1DN)); |
| | | |
| | | |
| | | // Rename the group and make sure the old one no longer exists but the new |
| | | // one does. |
| | | RDN newRDN = RDN.decode("cn=Renamed Group"); |
| | | // Rename the group and make sure the old one no longer exists but the new one does |
| | | RDN newRDN = RDN.valueOf("cn=Renamed Group"); |
| | | DN newDN = DN.valueOf("cn=Renamed Group,ou=Groups,o=test"); |
| | | |
| | | ModifyDNOperation modifyDNOperation = |
| | |
| | | |
| | | private RDN rdn(String s) throws DirectoryException |
| | | { |
| | | return s != null ? RDN.decode(s) : null; |
| | | return s != null ? RDN.valueOf(s) : null; |
| | | } |
| | | |
| | | private void assertSuccessAndEntryExists(ModifyDNOperation modifyDNOperation, |
| | |
| | | "cn: test"); |
| | | |
| | | ModifyDNOperation modifyDNOperation = |
| | | getRootConnection().processModifyDN(e.getName(), RDN.decode("cn=test2"), false); |
| | | getRootConnection().processModifyDN(e.getName(), RDN.valueOf("cn=test2"), false); |
| | | assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | e = DirectoryConfig.getEntry(DN.valueOf("cn=test2,o=test")); |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.requests.ModifyDNRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | * Perform modify DN operation. |
| | | * |
| | | * @param dn The DN to rename or move. |
| | | * @param rdn RDN value. |
| | | * @param newRDN RDN value. |
| | | * @param newSuperior New superior to move to. |
| | | * @throws Exception If the operation can't be performed. |
| | | */ |
| | | private void doModDN(String dn, String rdn, String newSuperior) throws Exception |
| | | private void doModDN(String dn, String newRDN, String newSuperior) throws Exception |
| | | { |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyDNOperation modDNop; |
| | | if(newSuperior != null) |
| | | ModifyDNRequest modifyDNRequest = Requests.newModifyDNRequest(dn, newRDN); |
| | | if (newSuperior != null) |
| | | { |
| | | modDNop = conn.processModifyDN(DN.valueOf(dn), RDN.decode(rdn), true, |
| | | DN.valueOf(newSuperior)); |
| | | modifyDNRequest.setDeleteOldRDN(true).setNewSuperior(newSuperior); |
| | | } |
| | | else |
| | | { |
| | | modDNop = conn.processModifyDN(DN.valueOf(dn), RDN.decode(rdn), |
| | | false, null); |
| | | } |
| | | ModifyDNOperation modDNop = getRootConnection().processModifyDN(modifyDNRequest); |
| | | assertEquals(modDNop.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | package org.opends.server.plugins; |
| | | |
| | | import java.util.HashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyDNRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.server.AdminTestCaseUtils; |
| | | import org.opends.server.admin.std.meta.UniqueAttributePluginCfgDefn; |
| | |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.testng.annotations.*; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.BeforeMethod; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.core.DirectoryServer.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * Unit test to test the unique attribute plugin. |
| | | */ |
| | | /** Unit test to test the unique attribute plugin. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class UniqueAttributePluginTestCase extends PluginTestCase { |
| | | |
| | | private DN uidConfigDN; |
| | | private DN testConfigDN; |
| | | private String uidConfigDN; |
| | | private String testConfigDN; |
| | | private String dsConfigAttrType="ds-cfg-type"; |
| | | private String dsConfigBaseDN="ds-cfg-base-dn"; |
| | | |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass |
| | | public void startServer() |
| | | throws Exception |
| | | public void startServer() throws Exception |
| | | { |
| | | TestCaseUtils.restartServer(); |
| | | TestCaseUtils.initializeTestBackend(true); |
| | |
| | | addTestEntries("o=test", 't'); |
| | | TestCaseUtils.clearBackend("userRoot", "dc=example,dc=com"); |
| | | addTestEntries("dc=example,dc=com", 'x'); |
| | | uidConfigDN=DN.valueOf("cn=UID Unique Attribute ,cn=Plugins,cn=config"); |
| | | testConfigDN=DN.valueOf("cn=Test Unique Attribute,cn=Plugins,cn=config"); |
| | | uidConfigDN = "cn=UID Unique Attribute ,cn=Plugins,cn=config"; |
| | | testConfigDN = "cn=Test Unique Attribute,cn=Plugins,cn=config"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Clears configuration information before each method run. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeMethod |
| | | public void clearConfigEntries() throws Exception { |
| | | deleteAttrsFromEntry(uidConfigDN, dsConfigBaseDN); |
| | | deleteAttrsFromEntry(testConfigDN, dsConfigBaseDN); |
| | | //Put an attribute type there that won't impact the rest of the unit |
| | | //tests. |
| | | // Put an attribute type there that won't impact the rest of the unit tests. |
| | | replaceAttrInEntry(uidConfigDN, dsConfigAttrType,"oncRpcNumber"); |
| | | replaceAttrInEntry(testConfigDN, dsConfigAttrType,"bootParameter"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Clears things up after the unit test is completed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @AfterClass |
| | | public void tearDown() throws Exception { |
| | | clearConfigEntries(); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Test modify DN operation with various scenerios. See method comments. |
| | | * Test modify DN operation with various scenarios. See method comments. |
| | | * |
| | | * @throws Exception If an unexpected result occurs. |
| | | */ |
| | |
| | | //that will be tested for. |
| | | Entry e = makeEntry("cn=test user, ou=new people,o=test"); |
| | | addAttribute(e, "uid", "3user.3"); |
| | | addEntry(e, ResultCode.SUCCESS); |
| | | addEntry(e, SUCCESS); |
| | | //Setup uid attribute to be unique. Test using public naming contexts |
| | | //for base DNs. |
| | | replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"uid"); |
| | | //Rename with new rdn, should fail, there is an entry already with that |
| | | //uid value. |
| | | doModDN(DN.valueOf("uid=3user.3, ou=people, o=test"), RDN.decode("uid=4"), |
| | | false, null, ResultCode.CONSTRAINT_VIOLATION); |
| | | // Rename with new rdn, should fail, there is an entry already with that uid value |
| | | doModDN("uid=3user.3, ou=people, o=test", "uid=4", null, CONSTRAINT_VIOLATION); |
| | | //Rename with multi-valued RDN, should fail there is an entry already with |
| | | //that uid value. |
| | | doModDN(DN.valueOf("uid=3user.3, ou=people, o=test"), |
| | | RDN.decode("sn=xx+uid=4"), |
| | | false, null, ResultCode.CONSTRAINT_VIOLATION); |
| | | doModDN("uid=3user.3, ou=people, o=test", "sn=xx+uid=4", null, CONSTRAINT_VIOLATION); |
| | | //Now add a base dn to be unique under, so new superior move can be tested. |
| | | replaceAttrInEntry(uidConfigDN,dsConfigBaseDN,"ou=new people,o=test"); |
| | | |
| | |
| | | //Try to move the entry to a new superior. |
| | | //Should fail, there is an entry under the new superior already with |
| | | //that uid value. |
| | | doModDN(DN.valueOf("uid=3user.3, ou=people, o=test"), |
| | | RDN.decode("uid=3user.3"), false, |
| | | DN.valueOf("ou=new people, o=test"), |
| | | ResultCode.CONSTRAINT_VIOLATION); |
| | | doModDN("uid=3user.3, ou=people, o=test", "uid=3user.3", "ou=new people, o=test", CONSTRAINT_VIOLATION); |
| | | //Test again with different superior, should succeed, new superior DN is |
| | | //not in base DN scope. |
| | | doModDN(DN.valueOf("uid=3user.3, ou=people, o=test"), |
| | | RDN.decode("uid=3user.3"), false, |
| | | DN.valueOf("ou=new people1, o=test"), |
| | | ResultCode.SUCCESS); |
| | | doModDN("uid=3user.3, ou=people, o=test", "uid=3user.3", "ou=new people1, o=test", SUCCESS); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Test |
| | | public void testModOperationNameContexts() throws Exception { |
| | | replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mail"); |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | addMods(mods,"mail",ModificationType.REPLACE,"userx@test","userxx@test", "user1t@test"); |
| | | //Fail because user1t@test already exists under "o=people,o=test". |
| | | doMods(mods, DN.valueOf("uid=5user.5,ou=People,o=test"), |
| | | ResultCode.CONSTRAINT_VIOLATION); |
| | | mods.clear(); |
| | | addMods(mods,"pager",ModificationType.ADD,"2-999-1234","1-999-5678"); |
| | | addMods(mods,"mail",ModificationType.ADD,"userx@test","userxx@test", |
| | | "user1t@test"); |
| | | ModifyRequest modifyRequest = newModifyRequest("uid=5user.5,ou=People,o=test") |
| | | .addModification(REPLACE, "mail", "userx@test", "userxx@test", "user1t@test"); |
| | | doMods(modifyRequest, CONSTRAINT_VIOLATION); |
| | | //Fail because user1t@test already exists under "o=people,o=test". |
| | | doMods(mods, DN.valueOf("uid=5user.5,ou=People,o=test"), |
| | | ResultCode.CONSTRAINT_VIOLATION); |
| | | mods.clear(); |
| | | addMods(mods,"pager",ModificationType.ADD,"2-999-1234","1-999-5678"); |
| | | addMods(mods,"mail",ModificationType.REPLACE,"userx@test","userxx@test", "user1t@test"); |
| | | modifyRequest = newModifyRequest("uid=5user.5,ou=People,o=test") |
| | | .addModification(ADD, "pager", "2-999-1234", "1-999-5678") |
| | | .addModification(ADD, "mail", "userx@test", "userxx@test", "user1t@test"); |
| | | doMods(modifyRequest, CONSTRAINT_VIOLATION); |
| | | //Ok because adding mail value user1t@test to entry that already |
| | | //contains mail value user1t@test. |
| | | doMods(mods, DN.valueOf("uid=1user.1,ou=People,o=test"), |
| | | ResultCode.SUCCESS); |
| | | mods.clear(); |
| | | modifyRequest = newModifyRequest("uid=1user.1,ou=People,o=test") |
| | | .addModification(ADD, "pager", "2-999-1234", "1-999-5678") |
| | | .addModification(REPLACE, "mail", "userx@test", "userxx@test", "user1t@test"); |
| | | doMods(modifyRequest, SUCCESS); |
| | | //Replace employeenumber as the unique attribute. |
| | | replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"employeenumber"); |
| | | addMods(mods,"employeenumber",ModificationType.INCREMENT,"1"); |
| | | //Test modify increment extension. |
| | | //Fail because incremented value of employeenumber (2) already exists. |
| | | doMods(mods, DN.valueOf("uid=1user.1,ou=People,o=test"), |
| | | ResultCode.CONSTRAINT_VIOLATION); |
| | | modifyRequest = newModifyRequest("uid=1user.1,ou=People,o=test") |
| | | .addModification(INCREMENT, "employeenumber", "1"); |
| | | doMods(modifyRequest, CONSTRAINT_VIOLATION); |
| | | } |
| | | |
| | | |
| | |
| | | //base DNs. |
| | | Entry e1 = makeEntry("cn=test user1, ou=People,o=test"); |
| | | addAttribute(e1, "mail", "mailtest@test"); |
| | | addEntry(e1, ResultCode.SUCCESS); |
| | | addEntry(e1, SUCCESS); |
| | | Entry e2 = makeEntry("cn=test user2, ou=People1,o=test"); |
| | | addAttribute(e2, "mail", "mailtest@test"); |
| | | addEntry(e2, ResultCode.SUCCESS); |
| | | addEntry(e2, SUCCESS); |
| | | //Now try to add two more entries with the same mail attribute value. |
| | | Entry e3 = makeEntry("cn=test user3, ou=People,o=test"); |
| | | addAttribute(e3, "mail", "mailtest@test"); |
| | | addEntry(e3, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e3, CONSTRAINT_VIOLATION); |
| | | Entry e4 = makeEntry("cn=test user4, ou=People1,o=test"); |
| | | addAttribute(e4, "mail", "mailtest@test"); |
| | | addEntry(e4, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e4, CONSTRAINT_VIOLATION); |
| | | } |
| | | |
| | | /** |
| | | * Test various add operation scenerios using defined base DNs. |
| | | * Test various add operation scenarios using defined base DNs. |
| | | * See comments in method. |
| | | * |
| | | * @throws Exception If an unexpected result occurs. |
| | |
| | | Entry e = makeEntry("cn=test user, ou=People,o=test"); |
| | | addAttribute(e, "mail", "user1t@test"); |
| | | //Fail because mail attribute already exists under "ou=people,o=test". |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | delAttribute(e, "mail"); |
| | | //Replace mobile, pager, telephonenumber to config. |
| | | replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mobile", |
| | | "pager","telephonenumber"); |
| | | addAttribute(e, "mobile", "1-999-1234","1-999-5678","1-444-9012"); |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | e.setDN(DN.valueOf("cn=test user, ou=People,o=test")); |
| | | //Fail because "2-333-9012" already exists in "ou=people,o=test" in |
| | | //telephonenumber attribute. |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | delAttribute(e, "mobile"); |
| | | addAttribute(e, "pager", "2-111-1234","1-999-5678","1-999-9012"); |
| | | //Fail because "2-111-9012" already exists in "ou=people1,o=test" in |
| | | //mobile attribute. |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | //Test two plugin configuration. Add mail attribute to second plugin |
| | | //instance, leave the first instance as it is. |
| | | replaceAttrInEntry(testConfigDN,dsConfigAttrType,"mail"); |
| | |
| | | //Add a value that will fail the second plugin. |
| | | addAttribute(e, "mail", "user1t@test"); |
| | | //Should pass frirail through second plugin configuration. |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | } |
| | | |
| | | |
| | |
| | | addAttribute(e, "mail", "user77x@test"); |
| | | //Fail because mail value "user77x@test" is a value under the |
| | | //"dc=example,dc=com" naming context. |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | delAttribute(e, "mail"); |
| | | replaceAttrInEntry(uidConfigDN,dsConfigAttrType,"mobile", |
| | | "pager","telephonenumber"); |
| | | addAttribute(e, "mobile", "1-999-1234","1-999-5678","2-777-9012"); |
| | | //Fail because "2-777-9012" is a telephone value under the |
| | | //"dc=example,dc=com" naming context. |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | e.setDN(DN.valueOf("cn=test user, ou=People,o=test")); |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | delAttribute(e, "mobile"); |
| | | addAttribute(e, "pager", "2-777-1234","1-999-5678","1-999-9012"); |
| | | //Fail because "2-777-9012" is a telephone value under the |
| | | //"dc=example,dc=com" naming context. |
| | | addEntry(e, ResultCode.CONSTRAINT_VIOLATION); |
| | | addEntry(e, CONSTRAINT_VIOLATION); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | private void clearAcis(String suffix) throws Exception |
| | | { |
| | | deleteAttrsFromEntry(DN.valueOf("ou=People," + suffix), "aci"); |
| | | deleteAttrsFromEntry(DN.valueOf("ou=People1," + suffix), "aci"); |
| | | deleteAttrsFromEntry("ou=People," + suffix, "aci"); |
| | | deleteAttrsFromEntry("ou=People1," + suffix, "aci"); |
| | | } |
| | | |
| | | /** |
| | |
| | | * entry. |
| | | * @throws Exception If an error occurs. |
| | | */ |
| | | private void |
| | | deleteAttrsFromEntry(DN dn, String... attrTypeStrings) throws Exception { |
| | | LinkedList<Modification> mods = new LinkedList<>(); |
| | | private void deleteAttrsFromEntry(String dn, String... attrTypeStrings) throws Exception { |
| | | ModifyRequest modifyRequest = newModifyRequest(dn); |
| | | for(String attrTypeString : attrTypeStrings) { |
| | | AttributeType attrType = getAttributeType(attrTypeString); |
| | | mods.add(new Modification(ModificationType.DELETE, |
| | | Attributes.empty(attrType))); |
| | | modifyRequest.addModification(DELETE, attrTypeString); |
| | | } |
| | | getRootConnection().processModify(dn, mods); |
| | | getRootConnection().processModify(modifyRequest); |
| | | } |
| | | |
| | | private void replaceAttrInEntry(DN dn, String attrName, String... attrValStrings) { |
| | | LinkedList<Modification> mods = newLinkedList( |
| | | new Modification(ModificationType.REPLACE, Attributes.create(attrName, attrValStrings))); |
| | | getRootConnection().processModify(dn, mods); |
| | | private void replaceAttrInEntry(String dn, String attrName, Object... attrValStrings) { |
| | | ModifyRequest modifyRequest = newModifyRequest(dn) |
| | | .addModification(REPLACE, attrName, attrValStrings); |
| | | getRootConnection().processModify(modifyRequest); |
| | | } |
| | | |
| | | |
| | |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * Remove an attribute from the specified entry. |
| | | * |
| | | * @param entry The entry to remove the attribute from. |
| | | * @param attrTypeString The attribute type string to remove. |
| | | */ |
| | | private void delAttribute(Entry entry, String attrTypeString) { |
| | | entry.removeAttribute(getAttributeType(attrTypeString)); |
| | | } |
| | | |
| | | /** |
| | | * Add an attribute to an entry with specified values. |
| | | * |
| | | * @param entry The entry to add the attribute to. |
| | | * @param attrName The attribute type string name. |
| | | * @param attrValues The values use in building the attribute. |
| | | */ |
| | | private void addAttribute(Entry entry, String attrName, String... attrValues) { |
| | | entry.addAttribute(Attributes.create(attrName, attrValues), null); |
| | | } |
| | | |
| | | /** |
| | | * Add a new modification for attribute type string and values of modification |
| | | * type to a list of modifications. |
| | | * |
| | | * @param mods The modification list to add to. |
| | | * @param attrName The attribute type string name. |
| | | * @param modificationType The modification type. |
| | | * @param attrValues The values to build the modification from. |
| | | */ |
| | | private void |
| | | addMods(LinkedList<Modification> mods, String attrName, |
| | | ModificationType modificationType, String... attrValues) { |
| | | mods.add(new Modification(modificationType, |
| | | Attributes.create(attrName, attrValues))); |
| | | } |
| | | |
| | | /** |
| | | * Perform modify operation with list of modifications. Expect return code |
| | | * of value rc. |
| | | * |
| | | * @param mods The modification list to use. |
| | | * @param dn The DN of the entry to modify. |
| | | * @param rc The expected return code. |
| | | */ |
| | | private void doMods(LinkedList<Modification> mods, DN dn, ResultCode rc) { |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(dn, mods); |
| | | private void doMods(ModifyRequest modifyRequest, ResultCode rc) throws DirectoryException { |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(modifyRequest); |
| | | assertEquals(modifyOperation.getResultCode(), rc); |
| | | } |
| | | |
| | | /** |
| | | * Perform modify DN operation. Expect return value of rc. |
| | | * |
| | | * @param dn The DN to rename or move. |
| | | * @param rdn RDN value. |
| | | * @param delOld Delete old flag. |
| | | * @param newSuperior New superior to move to. |
| | | * @param rc Expected return code from operation. |
| | | */ |
| | | private void doModDN(DN dn, RDN rdn, boolean delOld, DN newSuperior, ResultCode rc) { |
| | | ModifyDNOperation modifyDNOperation = getRootConnection().processModifyDN(dn, rdn, delOld, newSuperior); |
| | | private void doModDN(String dn, String newRdn, String newSuperior, ResultCode rc) |
| | | throws DirectoryException { |
| | | ModifyDNRequest modifyDNRequest = newModifyDNRequest(dn, newRdn); |
| | | if (newSuperior != null) |
| | | { |
| | | modifyDNRequest.setNewSuperior(newSuperior); |
| | | } |
| | | ModifyDNOperation modifyDNOperation = getRootConnection().processModifyDN(modifyDNRequest); |
| | | assertEquals(modifyDNOperation.getResultCode(), rc); |
| | | } |
| | | } |
| | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyDNOperation modifyDNOperation = |
| | | conn.processModifyDN(DN.valueOf("cn=test,o=test"), |
| | | RDN.decode("cn=test2"), true); |
| | | RDN.valueOf("cn=test2"), true); |
| | | assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyDNOperation modifyDNOperation = |
| | | conn.processModifyDN(DN.valueOf("cn=test,o=test"), |
| | | RDN.decode("cn=test2"), true, |
| | | RDN.valueOf("cn=test2"), true, |
| | | DN.valueOf("dc=example,dc=com")); |
| | | assertEquals(modifyDNOperation.getResultCode(), |
| | | ResultCode.UNWILLING_TO_PERFORM); |
| | |
| | | // Try to rename the entry. |
| | | ModifyDNOperationBasis modifyDNOp = new ModifyDNOperationBasis( |
| | | conn, conn.nextOperationID(), conn.nextMessageID(), controls, |
| | | e.getName(), RDN.decode("cn=Proxy V1 Test"), true, null); |
| | | e.getName(), RDN.valueOf("cn=Proxy V1 Test"), true, null); |
| | | assertSuccess(hasProxyPrivilege, modifyDNOp); |
| | | DN newEntryDN = hasProxyPrivilege ? modifyDNOp.getNewDN() : e.getName(); |
| | | |
| | |
| | | // Try to rename the entry. |
| | | ModifyDNOperationBasis modifyDNOp = new ModifyDNOperationBasis( |
| | | conn, conn.nextOperationID(), conn.nextMessageID(), controls, |
| | | e.getName(), RDN.decode("cn=Proxy V2 Test"), true, null); |
| | | e.getName(), RDN.valueOf("cn=Proxy V2 Test"), true, null); |
| | | assertSuccess(hasProxyPrivilege, authDN, modifyDNOp); |
| | | |
| | | DN newEntryDN = hasProxyPrivilege ? modifyDNOp.getNewDN() : e.getName(); |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.requests.ModifyDNRequest; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.TestCaseUtils; |
| | |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.OperationType; |
| | | import org.opends.server.types.RDN; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TimeThread; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.ModificationType.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.replication.plugin.LDAPReplicationDomain.*; |
| | |
| | | personWithUUIDEntry.getAttributes(), new ArrayList<Attribute>()); |
| | | |
| | | // - MODDN parent entry 1 to baseDn2 in the LDAP server |
| | | connection.processModifyDN( |
| | | baseDN1, |
| | | RDN.decode("ou=baseDn2"), true, |
| | | baseDN); |
| | | ModifyDNRequest modifyDNRequest = newModifyDNRequest(baseDN1.toString(), "ou=baseDn2") |
| | | .setDeleteOldRDN(true) |
| | | .setNewSuperior(baseDN.toString()); |
| | | connection.processModifyDN(modifyDNRequest); |
| | | assertNotNull(getEntry(baseDN2, 10000, true), |
| | | "Entry not moved from " + baseDN1 + " to " + baseDN2); |
| | | |
| | |
| | | assertClientReceivesExpectedMsg(broker, ModifyMsg.class, personEntry.getName()); |
| | | |
| | | // Modify the entry DN |
| | | ModifyDNRequest modifyDNRequest = newModifyDNRequest(personEntry.getName().toString(), "uid=new person") |
| | | .setDeleteOldRDN(true) |
| | | .setNewSuperior(baseDN.toString()); |
| | | connection.processModifyDN(modifyDNRequest); |
| | | DN newDN = DN.valueOf("uid= new person," + baseDN); |
| | | connection.processModifyDN(personEntry.getName(), |
| | | RDN.decode("uid=new person"), true, baseDN); |
| | | assertTrue(DirectoryServer.entryExists(newDN), |
| | | "The MOD_DN operation didn't create the new person entry"); |
| | | assertFalse(DirectoryServer.entryExists(personEntry.getName()), |
| | |
| | | |
| | | // Now delete the first entry that was added at the beginning |
| | | ModifyDNOperation modDNOperation = |
| | | getRootConnection().processModifyDN(entry.getName(), RDN.decode("cn=foo"), false); |
| | | getRootConnection().processModifyDN(entry.getName(), RDN.valueOf("cn=foo"), false); |
| | | assertEquals(modDNOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | // Expect the conflict resolution : the second entry should now |
| | |
| | | */ |
| | | package org.opends.server.replication.protocol; |
| | | |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.UUID; |
| | | import java.util.zip.DataFormatException; |
| | | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.requests.ModifyDNRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.controls.SubtreeDeleteControl; |
| | | import org.opends.server.core.*; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.AddOperationBasis; |
| | | import org.opends.server.core.DeleteOperation; |
| | | import org.opends.server.core.DeleteOperationBasis; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.ModifyOperationBasis; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.replication.ReplicationTestCase; |
| | | import org.opends.server.replication.common.*; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.replication.common.AssuredMode; |
| | | import org.opends.server.replication.common.CSN; |
| | | import org.opends.server.replication.common.DSInfo; |
| | | import org.opends.server.replication.common.RSInfo; |
| | | import org.opends.server.replication.common.ServerState; |
| | | import org.opends.server.replication.common.ServerStatus; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.RawAttribute; |
| | | import org.opends.server.util.TimeThread; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendAddOperation; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendDeleteOperation; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.replication.protocol.OperationContext.*; |
| | | import static org.opends.server.replication.protocol.ProtocolVersion.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | |
| | | List<Attribute> entryAttrList) |
| | | throws Exception |
| | | { |
| | | DN dn = DN.valueOf(rawdn); |
| | | InternalClientConnection connection = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyMsg msg = new ModifyMsg(csn, dn, mods, "fakeuniqueid"); |
| | | |
| | | ModifyMsg msg = new ModifyMsg(csn, DN.valueOf(rawdn), mods, "fakeuniqueid"); |
| | | msg.setAssured(isAssured); |
| | | msg.setAssuredMode(assuredMode); |
| | | msg.setSafeDataLevel(safeDataLevel); |
| | |
| | | // Get ECL entry attributes |
| | | assertAttributesEqual(generatedMsg.getEclIncludes(), entryAttrList); |
| | | |
| | | ModifyOperation mod1 = (ModifyOperation) msg.createOperation(connection); |
| | | ModifyOperation mod2 = (ModifyOperation) generatedMsg.createOperation(connection); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyOperation mod1 = (ModifyOperation) msg.createOperation(conn); |
| | | ModifyOperation mod2 = (ModifyOperation) generatedMsg.createOperation(conn); |
| | | |
| | | assertEquals(mod1.getRawEntryDN(), mod2.getRawEntryDN()); |
| | | assertEquals(mod1.getAttachment(SYNCHROCONTEXT), |
| | |
| | | boolean subtree) |
| | | throws Exception |
| | | { |
| | | InternalClientConnection connection = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOp = |
| | | new DeleteOperationBasis(connection, 1, 1,null, DN.valueOf(rawDN)); |
| | | if (subtree) |
| | |
| | | // Get ECL entry attributes |
| | | assertAttributesEqual(generatedMsg.getEclIncludes(), entryAttrList); |
| | | |
| | | DeleteOperation mod2 = (DeleteOperation) generatedMsg.createOperation(connection); |
| | | DeleteOperation mod2 = (DeleteOperation) generatedMsg.createOperation(getRootConnection()); |
| | | assertEquals(mod2.getRequestControl(SubtreeDeleteControl.DECODER) != null, subtree); |
| | | assertEquals(op.getRawEntryDN(), mod2.getRawEntryDN()); |
| | | |
| | |
| | | byte safeDataLevel, List<Attribute> entryAttrList) |
| | | throws Exception |
| | | { |
| | | InternalClientConnection connection = |
| | | InternalClientConnection.getRootConnection(); |
| | | ModifyDNOperation op = new ModifyDNOperationBasis(connection, 1, 1, null, |
| | | DN.valueOf(rawDN), RDN.decode(newRdn), deleteOldRdn, |
| | | (newSuperior.length() != 0 ? DN.valueOf(newSuperior) : null)); |
| | | ModifyDNRequest modifyDNRequest = newModifyDNRequest(rawDN, newRdn) |
| | | .setDeleteOldRDN(deleteOldRdn); |
| | | if (newSuperior.length() != 0) |
| | | { |
| | | modifyDNRequest.setNewSuperior(newSuperior); |
| | | } |
| | | ModifyDNOperation op = getRootConnection().processModifyDN(modifyDNRequest); |
| | | |
| | | CSN csn = new CSN(TimeThread.getTime(), 123, 45); |
| | | op.setAttachment(SYNCHROCONTEXT, |
| | |
| | | // Get ECL entry attributes |
| | | assertAttributesEqual(generatedMsg.getEclIncludes(), entryAttrList); |
| | | |
| | | ModifyDNOperation moddn1 = (ModifyDNOperation) msg.createOperation(connection); |
| | | ModifyDNOperation moddn2 = (ModifyDNOperation) generatedMsg.createOperation(connection); |
| | | ModifyDNOperation moddn1 = (ModifyDNOperation) msg.createOperation(getRootConnection()); |
| | | ModifyDNOperation moddn2 = (ModifyDNOperation) generatedMsg.createOperation(getRootConnection()); |
| | | |
| | | assertEquals(msg.getCSN(), generatedMsg.getCSN()); |
| | | assertEquals(moddn1.getRawEntryDN(), moddn2.getRawEntryDN()); |
| | |
| | | assertAttributesEqual(generatedMsg.getEclIncludes(), entryAttrList); |
| | | |
| | | // Create an new Add Operation from the current addMsg |
| | | InternalClientConnection connection = |
| | | InternalClientConnection.getRootConnection(); |
| | | AddOperation addOp = msg.createOperation(connection, dn); |
| | | AddOperation genAddOp = generatedMsg.createOperation(connection, dn); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | AddOperation addOp = msg.createOperation(conn, dn); |
| | | AddOperation genAddOp = generatedMsg.createOperation(conn, dn); |
| | | |
| | | assertEquals(addOp.getRawEntryDN(), genAddOp.getRawEntryDN()); |
| | | assertEquals(addOp.getAttachment(SYNCHROCONTEXT), genAddOp.getAttachment(SYNCHROCONTEXT)); |
| | |
| | | assertEquals(msg.toString(), generatedMsg.toString()); |
| | | |
| | | //Create an Add operation and generate and Add msg from it |
| | | AddOperation addOpB = new AddOperationBasis(connection, |
| | | AddOperation addOpB = new AddOperationBasis(conn, |
| | | 1, 1, null, dn, objectClassList, userAttList, opList); |
| | | LocalBackendAddOperation localAddOp = new LocalBackendAddOperation(addOpB); |
| | | OperationContext opCtx = new AddContext(csn, "thisIsaUniqueID", |
| | |
| | | public void deleteMsgPerfs(String rawDN, List<Attribute> entryAttrList) |
| | | throws Exception |
| | | { |
| | | InternalClientConnection connection = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | long createop = 0; |
| | | long createmsgfromop = 0; |
| | | long encodemsg = 0; |
| | |
| | | |
| | | // create op |
| | | DeleteOperation deleteOp = |
| | | new DeleteOperationBasis(connection, 1, 1,null, DN.valueOf(rawDN)); |
| | | new DeleteOperationBasis(getRootConnection(), 1, 1,null, DN.valueOf(rawDN)); |
| | | LocalBackendDeleteOperation op = |
| | | new LocalBackendDeleteOperation(deleteOp); |
| | | CSN csn = new CSN(TimeThread.getTime(), 123, 45); |
| | |
| | | private ModifyDNMsg modDNMsg(CSNGenerator csnGen) throws DirectoryException |
| | | { |
| | | ModifyDNOperationBasis op = new ModifyDNOperationBasis( |
| | | connection, 1, 1, null, EXAMPLE_DN, RDN.decode("o=example2"), true, null); |
| | | connection, 1, 1, null, EXAMPLE_DN, RDN.valueOf("o=example2"), true, null); |
| | | op.setAttachment(SYNCHROCONTEXT, new ModifyDnContext(csnGen.newCSN(), "uniqueid", "newparentId")); |
| | | LocalBackendModifyDNOperation localOp = new LocalBackendModifyDNOperation(op); |
| | | return new ModifyDNMsg(localOp); |
| | |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.types.Privilege.*; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | |
| | | |
| | | private void assertPrivilege(ResultCode actual, boolean hasPrivilege) |
| | | { |
| | | assertEquals(actual, hasPrivilege ? SUCCESS : INSUFFICIENT_ACCESS_RIGHTS); |
| | | assertEquals(actual, hasPrivilegeRC(hasPrivilege)); |
| | | } |
| | | |
| | | private ResultCode hasPrivilegeRC(boolean hasPrivilege) |
| | | { |
| | | return hasPrivilege ? SUCCESS : INSUFFICIENT_ACCESS_RIGHTS; |
| | | } |
| | | |
| | | private void assertProxyPrivilege(ResultCode actual, boolean hasProxyPrivilege) |
| | |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.CONFIG_WRITE, null), hasPrivilege); |
| | | |
| | | ModifyDNOperation modifyDNOperation = |
| | | conn.processModifyDN(DN.valueOf("cn=Work Queue,cn=config"), |
| | | RDN.decode("cn=New RDN for Work Queue"), true, |
| | | null); |
| | | if (hasPrivilege) |
| | | { |
| | | // We don't support modify DN operations in the server configuration, but |
| | | // at least we need to make sure we're getting past the privilege check. |
| | | assertEquals(modifyDNOperation.getResultCode(), UNWILLING_TO_PERFORM); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(modifyDNOperation.getResultCode(), INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | processModifyDN( |
| | | conn, "cn=Work Queue,cn=config", "cn=New RDN for Work Queue", |
| | | // We don't support modify DN operations in the server configuration, but |
| | | // at least we need to make sure we're getting past the privilege check. |
| | | (hasPrivilege ? UNWILLING_TO_PERFORM : INSUFFICIENT_ACCESS_RIGHTS)); |
| | | } |
| | | |
| | | |
| | |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.SUBENTRY_WRITE, null), |
| | | hasPrivilege); |
| | | assertEquals(conn.hasPrivilege(SUBENTRY_WRITE, null), hasPrivilege); |
| | | |
| | | ModifyDNOperation modifyDNOperation = |
| | | conn.processModifyDN(DN.valueOf("cn=Subentry Target,o=test"), |
| | | RDN.decode("cn=New Subentry Target"), |
| | | true, null); |
| | | assertPrivilege(modifyDNOperation.getResultCode(), hasPrivilege); |
| | | processModifyDN(conn, "cn=Subentry Target,o=test", "cn=New Subentry Target", hasPrivilegeRC(hasPrivilege)); |
| | | if (hasPrivilege) |
| | | { |
| | | modifyDNOperation = |
| | | conn.processModifyDN(DN.valueOf("cn=New Subentry Target,o=test"), |
| | | RDN.decode("cn=Subentry Target"), |
| | | true, null); |
| | | assertEquals(modifyDNOperation.getResultCode(), ResultCode.SUCCESS); |
| | | processModifyDN(conn, "cn=New Subentry Target,o=test", "cn=Subentry Target", SUCCESS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that modify operations which attempt to reset a user's |
| | | * password properly respect the PASSWORD_RESET privilege. |
| | |
| | | userPassword = "password"; |
| | | } |
| | | |
| | | assertEquals(conn.hasPrivilege(Privilege.PASSWORD_RESET, null), |
| | | hasPrivilege); |
| | | assertEquals(conn.hasPrivilege(PASSWORD_RESET, null), hasPrivilege); |
| | | |
| | | String path = TestCaseUtils.createTempFile( |
| | | "dn: cn=PWReset Target,o=test", |
| | |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.UPDATE_SCHEMA, null), |
| | | hasPrivilege); |
| | | assertEquals(conn.hasPrivilege(UPDATE_SCHEMA, null), hasPrivilege); |
| | | |
| | | String attrDefinition = |
| | | "( testupdateschemaat-oid NAME 'testUpdateSchemaAT' " + |
| | |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.UPDATE_SCHEMA, null), |
| | | hasPrivilege); |
| | | |
| | | |
| | | String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath(); |
| | | assertEquals(conn.hasPrivilege(UPDATE_SCHEMA, null), hasPrivilege); |
| | | |
| | | String identifier; |
| | | Entry authNEntry = conn.getAuthenticationInfo().getAuthenticationEntry(); |
| | |
| | | + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" |
| | | }; |
| | | |
| | | String schemaDirectory = SchemaConfigManager.getSchemaDirectoryPath(); |
| | | File validFile = new File(schemaDirectory, "05-" + identifier + ".ldif"); |
| | | try (BufferedWriter writer = new BufferedWriter(new FileWriter(validFile))) |
| | | { |
| | |
| | | // Try to rename the entry. |
| | | ModifyDNOperation modifyDNOperation = new ModifyDNOperationBasis(conn, nextOperationID(), |
| | | nextMessageID(), controls, e.getName(), |
| | | RDN.decode("cn=Proxy V1 Test"), true, null); |
| | | RDN.valueOf("cn=Proxy V1 Test"), true, null); |
| | | modifyDNOperation.run(); |
| | | assertProxyPrivilege(modifyOperation.getResultCode(), hasProxyPrivilege); |
| | | |
| | |
| | | // Try to rename the entry. |
| | | ModifyDNOperation modifyDNOperation = new ModifyDNOperationBasis(conn, nextOperationID(), |
| | | nextMessageID(), controls, e.getName(), |
| | | RDN.decode("cn=Proxy V2 Test"), true, null); |
| | | RDN.valueOf("cn=Proxy V2 Test"), true, null); |
| | | modifyDNOperation.run(); |
| | | assertProxyPrivilege(modifyDNOperation.getResultCode(), hasProxyPrivilege); |
| | | |
| | |
| | | |
| | | return task; |
| | | } |
| | | |
| | | private void processModifyDN(InternalClientConnection conn, String dn, String newRdn, ResultCode expectedRC) |
| | | { |
| | | ModifyDNOperation op = conn.processModifyDN(newModifyDNRequest(dn, newRdn).setDeleteOldRDN(true)); |
| | | assertEquals(op.getResultCode(), expectedRC); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Test |
| | | public void testCreateWithSingleRDN1() throws Exception { |
| | | DN dn = new DN(new RDN[] { RDN.decode("dc=com") }); |
| | | DN dn = new DN(new RDN[] { RDN.valueOf("dc=com") }); |
| | | |
| | | assertEquals(dn, DN.valueOf("dc=com")); |
| | | } |
| | |
| | | */ |
| | | @Test |
| | | public void testCreateWithMultipleRDNs1() throws Exception { |
| | | DN dn = new DN(new RDN[] { RDN.decode("dc=foo"), |
| | | RDN.decode("dc=opends"), RDN.decode("dc=org") }); |
| | | DN dn = new DN(new RDN[] { RDN.valueOf("dc=foo"), |
| | | RDN.valueOf("dc=opends"), RDN.valueOf("dc=org") }); |
| | | |
| | | assertEquals(dn, DN.valueOf("dc=foo,dc=opends,dc=org")); |
| | | } |
| | |
| | | @Test |
| | | public void testCreateWithMultipleRDNs2() throws Exception { |
| | | ArrayList<RDN> rdnList = new ArrayList<>(); |
| | | rdnList.add(RDN.decode("dc=foo")); |
| | | rdnList.add(RDN.decode("dc=opends")); |
| | | rdnList.add(RDN.decode("dc=org")); |
| | | rdnList.add(RDN.valueOf("dc=foo")); |
| | | rdnList.add(RDN.valueOf("dc=opends")); |
| | | rdnList.add(RDN.valueOf("dc=org")); |
| | | DN dn = new DN(rdnList); |
| | | |
| | | assertEquals(dn, DN.valueOf("dc=foo,dc=opends,dc=org")); |
| | |
| | | public void testGetParentDNInSuffix(DN namingContext) throws Exception { |
| | | assertNull(DirectoryServer.getParentDNInSuffix(namingContext)); |
| | | |
| | | DN childDN = namingContext.child(RDN.decode("ou=People")); |
| | | DN childDN = namingContext.child(RDN.valueOf("ou=People")); |
| | | assertNotNull(DirectoryServer.getParentDNInSuffix(childDN)); |
| | | assertEquals(DirectoryServer.getParentDNInSuffix(childDN), namingContext); |
| | | } |
| | |
| | | assertEquals(p.toNormalizedUrlSafeString(), e.toNormalizedUrlSafeString()); |
| | | assertEquals(p.toString(), e.toString()); |
| | | |
| | | assertEquals(p.rdn(), RDN.decode("dc=bar")); |
| | | assertEquals(p.rdn(), RDN.valueOf("dc=bar")); |
| | | |
| | | assertEquals(p.getRDN(0), RDN.decode("dc=bar")); |
| | | assertEquals(p.getRDN(1), RDN.decode("dc=opends")); |
| | | assertEquals(p.getRDN(2), RDN.decode("dc=org")); |
| | | assertEquals(p.getRDN(0), RDN.valueOf("dc=bar")); |
| | | assertEquals(p.getRDN(1), RDN.valueOf("dc=opends")); |
| | | assertEquals(p.getRDN(2), RDN.valueOf("dc=org")); |
| | | |
| | | assertEquals(p.parent(), DN.valueOf("dc=opends,dc=org")); |
| | | assertEquals(p.parent(), e.parent()); |
| | | |
| | | assertEquals(p.child(RDN.decode("dc=foo")), DN |
| | | assertEquals(p.child(RDN.valueOf("dc=foo")), DN |
| | | .valueOf("dc=foo,dc=bar,dc=opends,dc=org")); |
| | | assertEquals(p.child(RDN.decode("dc=foo")), c); |
| | | assertEquals(p.child(RDN.valueOf("dc=foo")), c); |
| | | assertEquals(p.child(DN.valueOf("dc=xxx,dc=foo")), DN |
| | | .valueOf("dc=xxx,dc=foo,dc=bar,dc=opends,dc=org")); |
| | | } |
| | |
| | | public void testGetRDN(String s, String p, String r) |
| | | throws Exception { |
| | | DN dn = DN.valueOf(s); |
| | | RDN rdn = r != null ? RDN.decode(r) : null; |
| | | RDN rdn = r != null ? RDN.valueOf(r) : null; |
| | | |
| | | assertEquals(dn.rdn(), rdn, "For DN " + s); |
| | | } |
| | |
| | | public void testGetRDNIndexed(String s, int i, String r) |
| | | throws Exception { |
| | | DN dn = DN.valueOf(s); |
| | | RDN rdn = RDN.decode(r); |
| | | RDN rdn = RDN.valueOf(r); |
| | | |
| | | assertEquals(dn.getRDN(i), rdn, "For DN " + s); |
| | | } |
| | |
| | | assertEquals(c.toNormalizedUrlSafeString(), e.toNormalizedUrlSafeString()); |
| | | assertEquals(c.toString(), e.toString()); |
| | | |
| | | assertEquals(c.rdn(), RDN.decode("dc=foo")); |
| | | assertEquals(c.rdn(), RDN.valueOf("dc=foo")); |
| | | |
| | | assertEquals(c.getRDN(0), RDN.decode("dc=foo")); |
| | | assertEquals(c.getRDN(1), RDN.decode("dc=bar")); |
| | | assertEquals(c.getRDN(2), RDN.decode("dc=opends")); |
| | | assertEquals(c.getRDN(3), RDN.decode("dc=org")); |
| | | assertEquals(c.getRDN(0), RDN.valueOf("dc=foo")); |
| | | assertEquals(c.getRDN(1), RDN.valueOf("dc=bar")); |
| | | assertEquals(c.getRDN(2), RDN.valueOf("dc=opends")); |
| | | assertEquals(c.getRDN(3), RDN.valueOf("dc=org")); |
| | | |
| | | assertEquals(c.parent(), DN.valueOf("dc=bar,dc=opends,dc=org")); |
| | | assertEquals(c.parent(), e.parent()); |
| | | |
| | | assertEquals(c.child(RDN.decode("dc=xxx")), DN |
| | | assertEquals(c.child(RDN.valueOf("dc=xxx")), DN |
| | | .valueOf("dc=xxx,dc=foo,dc=bar,dc=opends,dc=org")); |
| | | assertEquals(c.child(DN.valueOf("dc=xxx,dc=yyy")), DN |
| | | .valueOf("dc=xxx,dc=yyy,dc=foo,dc=bar,dc=opends,dc=org")); |
| | |
| | | public void testConcatSingleRDN(String s, String r, String e) |
| | | throws Exception { |
| | | DN dn = DN.valueOf(s); |
| | | RDN rdn = RDN.decode(r); |
| | | RDN rdn = RDN.valueOf(r); |
| | | DN expected = DN.valueOf(e); |
| | | |
| | | assertEquals(dn.child(rdn), expected); |
| | |
| | | */ |
| | | @Test(dataProvider = "testRDNs") |
| | | public void testNormalizationToSafeUrlString(String rawRDN, String normRDN, String stringRDN) throws Exception { |
| | | RDN rdn = RDN.decode(rawRDN); |
| | | RDN rdn = RDN.valueOf(rawRDN); |
| | | assertEquals(rdn.toNormalizedUrlSafeString(), normRDN); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Test(dataProvider = "illegalRDNs", expectedExceptions = DirectoryException.class) |
| | | public void testDecodeString(String rawRDN) throws Exception { |
| | | RDN.decode(rawRDN); |
| | | RDN.valueOf(rawRDN); |
| | | |
| | | fail("Expected exception for value \"" + rawRDN + "\""); |
| | | } |
| | |
| | | @Test(dataProvider = "testRDNs") |
| | | public void testToString(String rawRDN, String normRDN, |
| | | String stringRDN) throws Exception { |
| | | RDN rdn = RDN.decode(rawRDN); |
| | | RDN rdn = RDN.valueOf(rawRDN); |
| | | assertEquals(rdn.toString(), stringRDN); |
| | | } |
| | | |
| | |
| | | @Test(dataProvider = "createRDNEqualityData") |
| | | public void testEquality(String first, String second, int result) |
| | | throws Exception { |
| | | RDN rdn1 = RDN.decode(first); |
| | | RDN rdn2 = RDN.decode(second); |
| | | RDN rdn1 = RDN.valueOf(first); |
| | | RDN rdn2 = RDN.valueOf(second); |
| | | |
| | | if (result == 0) { |
| | | assertEquals(rdn1, rdn2, |
| | |
| | | @Test(dataProvider = "createRDNEqualityData") |
| | | public void testHashCode(String first, String second, int result) |
| | | throws Exception { |
| | | RDN rdn1 = RDN.decode(first); |
| | | RDN rdn2 = RDN.decode(second); |
| | | RDN rdn1 = RDN.valueOf(first); |
| | | RDN rdn2 = RDN.valueOf(second); |
| | | |
| | | int h1 = rdn1.hashCode(); |
| | | int h2 = rdn2.hashCode(); |
| | |
| | | @Test(dataProvider = "createRDNEqualityData") |
| | | public void testCompareTo(String first, String second, int result) |
| | | throws Exception { |
| | | RDN rdn1 = RDN.decode(first); |
| | | RDN rdn2 = RDN.decode(second); |
| | | RDN rdn1 = RDN.valueOf(first); |
| | | RDN rdn2 = RDN.valueOf(second); |
| | | |
| | | int rc = rdn1.compareTo(rdn2); |
| | | |
| | |
| | | .valueOf("cn=Paul Jensen, ou=Product Development, dc=airius, dc=com"); |
| | | Assert.assertEquals(modifyDN.getDN(), dn); |
| | | |
| | | rdn = RDN.decode("cn=paula jensen"); |
| | | rdn = RDN.valueOf("cn=paula jensen"); |
| | | Assert.assertEquals(modifyDN.getNewRDN(), rdn); |
| | | Assert.assertNull(modifyDN.getNewSuperiorDN()); |
| | | Assert.assertTrue(modifyDN.deleteOldRDN()); |
| | |
| | | .valueOf("ou=PD Accountants, ou=Product Development, dc=airius, dc=com"); |
| | | Assert.assertEquals(modifyDN.getDN(), dn); |
| | | |
| | | rdn = RDN.decode("ou=Product Development Accountants"); |
| | | rdn = RDN.valueOf("ou=Product Development Accountants"); |
| | | Assert.assertEquals(modifyDN.getNewRDN(), rdn); |
| | | dn = DN.valueOf("ou=Accounting, dc=airius, dc=com"); |
| | | Assert.assertEquals(modifyDN.getNewSuperiorDN(), dn); |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | |
| | | TestCaseUtils.startServer(); |
| | | |
| | | newSuperiorDN = DN.valueOf("dc=com"); |
| | | newRDN = RDN.decode("dc=foo"); |
| | | newRDN = RDN.valueOf("dc=foo"); |
| | | } |
| | | |
| | | /** |