OPENDJ-1342 Migrate AVA, RDN, and DN classes: replaced calls to DN.rdn(int) and DN(RDN[])
Replaced calls to DN.rdn(int) and DN(RDN[]) constructor by:
- DN.rename(DN, DN)
- DN.parent(int)
- DN.localName(i)
- DN.rootDN().child(RDN)
1 files added
13 files modified
| | |
| | | import javax.swing.SwingUtilities; |
| | | import javax.swing.tree.TreeNode; |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.admin.ads.util.ConnectionUtils; |
| | | import org.opends.guitools.controlpanel.ui.nodes.BasicNode; |
| | | import org.opends.messages.AdminToolMessages; |
| | | import org.opends.server.schema.SchemaConstants; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.LDAPURL; |
| | | import org.opends.server.types.OpenDsException; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | |
| | | /** |
| | | * The class that is in charge of doing the LDAP searches required to update a |
| | |
| | | // if it is the case, do not add the parent. If is not the case, |
| | | // search for the parent and add it. |
| | | RDN[] rdns = new RDN[parentComponents + 1]; |
| | | int diff = dn.size() - rdns.length; |
| | | for (int i=0; i < rdns.length; i++) |
| | | { |
| | | rdns[i] = dn.rdn(i + diff); |
| | | } |
| | | final DN parentToAddDN = new DN(rdns); |
| | | boolean mustAddParent = true; |
| | | for (SearchResult addedEntry : childEntries) |
| | | { |
| | | try |
| | | { |
| | | DN addedDN = DN.valueOf(addedEntry.getName()); |
| | | if (addedDN.equals(parentToAddDN)) |
| | | { |
| | | mustAddParent = false; |
| | | break; |
| | | } |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | throw new RuntimeException("Error decoding dn: "+ |
| | | addedEntry.getName()+" . "+t, t); |
| | | } |
| | | } |
| | | final DN parentToAddDN = dn.parent(dn.size() - rdns.length); |
| | | boolean mustAddParent = mustAddParent(parentToAddDN); |
| | | if (mustAddParent) |
| | | { |
| | | final boolean resultValue[] = {true}; |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean mustAddParent(final DN parentToAddDN) |
| | | { |
| | | for (SearchResult addedEntry : childEntries) |
| | | { |
| | | try |
| | | { |
| | | DN addedDN = DN.valueOf(addedEntry.getName()); |
| | | if (addedDN.equals(parentToAddDN)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | throw new RuntimeException("Error decoding dn: " + addedEntry.getName() + " . " + t, t); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * Returns the entry for the given dn. |
| | | * The code assumes that the request controls are set in the connection. |
| | |
| | | DN newDN; |
| | | if (parent == null) |
| | | { |
| | | newDN = new DN(new RDN[]{newRDN}); |
| | | newDN = DN.rootDN().child(newRDN); |
| | | } |
| | | else |
| | | { |
| | |
| | | import javax.swing.SwingUtilities; |
| | | import javax.swing.tree.TreePath; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.AVA; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.guitools.controlpanel.datamodel.BinaryValue; |
| | | import org.opends.guitools.controlpanel.datamodel.CustomSearchResult; |
| | | import org.opends.guitools.controlpanel.datamodel.ObjectClassValue; |
| | |
| | | import org.opends.guitools.controlpanel.ui.renderer.AttributeCellEditor; |
| | | import org.opends.guitools.controlpanel.ui.renderer.LDAPEntryTableCellRenderer; |
| | | import org.opends.guitools.controlpanel.util.Utilities; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.AVA; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.OpenDsException; |
| | | import org.opends.server.types.Schema; |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.opends.server.util.ServerConstants; |
| | | |
| | |
| | | DN newDN; |
| | | if (parent == null) |
| | | { |
| | | newDN = new DN(new RDN[]{newRDN}); |
| | | newDN = DN.rootDN().child(newRDN); |
| | | } |
| | | else |
| | | { |
| | |
| | | import static org.opends.messages.AccessControlMessages.*; |
| | | import static org.opends.server.authorization.dseecompat.AciHandler.*; |
| | | |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.SortedSet; |
| | | import java.util.concurrent.locks.ReentrantReadWriteLock; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.api.DITCacheMap; |
| | | import org.opends.server.types.Attribute; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | |
| | | /** |
| | | * The AciList class performs caching of the ACI attribute values |
| | |
| | | */ |
| | | public void renameAci(DN oldDN, DN newDN ) { |
| | | |
| | | int oldRDNCount=oldDN.size(); |
| | | int newRDNCount=newDN.size(); |
| | | |
| | | lock.writeLock().lock(); |
| | | try |
| | | { |
| | |
| | | aciList.entrySet().iterator(); |
| | | while (iterator.hasNext()) { |
| | | Map.Entry<DN,List<Aci>> hashEntry = iterator.next(); |
| | | if(hashEntry.getKey().isSubordinateOrEqualTo(oldDN)) { |
| | | int keyRDNCount=hashEntry.getKey().size(); |
| | | int keepRDNCount=keyRDNCount - oldRDNCount; |
| | | RDN[] newRDNs = new RDN[keepRDNCount + newRDNCount]; |
| | | for (int i=0; i < keepRDNCount; i++) { |
| | | newRDNs[i] = hashEntry.getKey().rdn(i); |
| | | } |
| | | for (int i=keepRDNCount, j=0; j < newRDNCount; i++,j++) { |
| | | newRDNs[i] = newDN.rdn(j); |
| | | } |
| | | DN relocateDN=new DN(newRDNs); |
| | | DN keyDn = hashEntry.getKey(); |
| | | if (keyDn.isSubordinateOrEqualTo(oldDN)) { |
| | | DN relocateDN = keyDn.rename(oldDN, newDN); |
| | | List<Aci> acis = new LinkedList<>(); |
| | | for(Aci aci : hashEntry.getValue()) { |
| | | try { |
| | |
| | | DN urlBaseDN = targetDN; |
| | | if (!referralDN.equals(ldapurl.getBaseDN())) |
| | | { |
| | | urlBaseDN = EntryContainer.modDN(targetDN, referralDN.size(), ldapurl.getBaseDN()); |
| | | urlBaseDN = targetDN.rename(referralDN, ldapurl.getBaseDN()); |
| | | } |
| | | ldapurl.setBaseDN(urlBaseDN); |
| | | if (searchScope == null) |
| | |
| | | */ |
| | | static ByteString dnToDNKey(DN dn, int prefixRDNs) |
| | | { |
| | | final ByteStringBuilder builder = new ByteStringBuilder(128); |
| | | final int startSize = dn.size() - prefixRDNs - 1; |
| | | for (int i = startSize; i >= 0; i--) |
| | | { |
| | | builder.appendByte(NORMALIZED_RDN_SEPARATOR); |
| | | dn.rdn(i).toNormalizedByteString(builder); |
| | | } |
| | | return builder.toByteString(); |
| | | return dn.localName(dn.size() - prefixRDNs).toNormalizedByteString(); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.forgerock.opendj.ldap.ByteSequence; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.CanceledOperationException; |
| | | import org.opends.server.types.Control; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.Privilege; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.SortOrder; |
| | | import org.opends.server.types.VirtualAttributeRule; |
| | |
| | | } |
| | | else |
| | | { |
| | | final DN newDN = modDN(oldEntry.getName(), oldTargetDN.size(), newTargetDN); |
| | | final DN newDN = oldEntry.getName().rename(oldTargetDN, newTargetDN); |
| | | newEntry = oldEntry.duplicate(false); |
| | | newEntry.setDN(newDN); |
| | | modifications = invokeSubordinateModifyDNPlugins(oldEntry, newEntry); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Make a new DN for a subordinate entry of a renamed or moved entry. |
| | | * |
| | | * @param oldDN The current DN of the subordinate entry. |
| | | * @param oldSuffixLen The current DN length of the renamed or moved entry. |
| | | * @param newSuffixDN The new DN of the renamed or moved entry. |
| | | * @return The new DN of the subordinate entry. |
| | | */ |
| | | static DN modDN(DN oldDN, int oldSuffixLen, DN newSuffixDN) |
| | | { |
| | | int oldDNNumComponents = oldDN.size(); |
| | | int oldDNKeepComponents = oldDNNumComponents - oldSuffixLen; |
| | | int newSuffixDNComponents = newSuffixDN.size(); |
| | | |
| | | RDN[] newDNComponents = new RDN[oldDNKeepComponents+newSuffixDNComponents]; |
| | | for (int i=0; i < oldDNKeepComponents; i++) |
| | | { |
| | | newDNComponents[i] = oldDN.rdn(i); |
| | | } |
| | | |
| | | for (int i=oldDNKeepComponents, j=0; j < newSuffixDNComponents; i++,j++) |
| | | { |
| | | newDNComponents[i] = newSuffixDN.rdn(j); |
| | | } |
| | | |
| | | return new DN(newDNComponents); |
| | | } |
| | | |
| | | /** |
| | | * Insert a new entry into the attribute indexes. |
| | | * |
| | | * @param buffer The index buffer used to buffer up the index changes. |
| | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.AVA; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.tools.makeldif.DNTagUtils.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | /** |
| | | * This class defines a tag that is used to include the DN of the current entry |
| | | * in the attribute value. |
| | |
| | | } |
| | | |
| | | @Override |
| | | public TagResult generateValue(TemplateEntry templateEntry, |
| | | TemplateValue templateValue) |
| | | public TagResult generateValue(TemplateEntry templateEntry, TemplateValue templateValue) |
| | | { |
| | | DN dn = templateEntry.getDN(); |
| | | if (dn == null || dn.isRootDN()) |
| | | if (dn != null && !dn.isRootDN()) |
| | | { |
| | | return TagResult.SUCCESS_RESULT; |
| | | templateValue.getValue().append(generateDNKeepingRDNs(dn, numComponents)); |
| | | } |
| | | |
| | | if (numComponents == 0) |
| | | { |
| | | templateValue.getValue().append(dn); |
| | | } |
| | | else if (numComponents > 0) |
| | | { |
| | | int count = Math.min(numComponents, dn.size()); |
| | | |
| | | templateValue.getValue().append(dn.rdn(0)); |
| | | for (int i = 1; i < count; i++) |
| | | { |
| | | templateValue.append(","); |
| | | templateValue.getValue().append(dn.rdn(i)); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | int sz = dn.size(); |
| | | int count = Math.min(Math.abs(numComponents), sz); |
| | | |
| | | templateValue.getValue().append(dn.rdn(sz - count)); |
| | | for (int i = 1; i < count; i++) |
| | | { |
| | | templateValue.append(","); |
| | | templateValue.getValue().append(dn.rdn(sz - count + i)); |
| | | } |
| | | } |
| | | |
| | | return TagResult.SUCCESS_RESULT; |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * The contents of this file are subject to the terms of the Common Development and |
| | | * Distribution License (the License). You may not use this file except in compliance with the |
| | | * License. |
| | | * |
| | | * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the |
| | | * specific language governing permission and limitations under the License. |
| | | * |
| | | * When distributing Covered Software, include this CDDL Header Notice in each file and include |
| | | * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | |
| | | /** Utility class for *DNTag classes. */ |
| | | final class DNTagUtils |
| | | { |
| | | private DNTagUtils() |
| | | { |
| | | // private for utility classes |
| | | } |
| | | |
| | | static DN generateDNKeepingRDNs(DN dn, int nbRdnsToInclude) |
| | | { |
| | | if (nbRdnsToInclude == 0) |
| | | { |
| | | return dn; |
| | | } |
| | | else if (nbRdnsToInclude > 0) |
| | | { |
| | | int count = Math.min(nbRdnsToInclude, dn.size()); |
| | | return dn.localName(count); |
| | | } |
| | | else |
| | | { |
| | | int sz = dn.size(); |
| | | int count = Math.min(Math.abs(nbRdnsToInclude), sz); |
| | | return dn.parent(sz - count).localName(count); |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.tools.makeldif.DNTagUtils.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | /** |
| | | * This class defines a tag that is used to include the DN of the current entry |
| | | * in the attribute value, with underscores in place of the commas. |
| | |
| | | TemplateValue templateValue) |
| | | { |
| | | DN dn = templateEntry.getDN(); |
| | | if (dn == null || dn.isRootDN()) |
| | | if (dn != null && !dn.isRootDN()) |
| | | { |
| | | return TagResult.SUCCESS_RESULT; |
| | | Utils.joinAsString(templateValue.getValue(), "_", generateDNKeepingRDNs(dn, numComponents)); |
| | | } |
| | | |
| | | if (numComponents == 0) |
| | | { |
| | | templateValue.getValue().append(dn.rdn(0)); |
| | | for (int i=1; i < dn.size(); i++) |
| | | { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(dn.rdn(i)); |
| | | } |
| | | } |
| | | else if (numComponents > 0) |
| | | { |
| | | int count = Math.min(numComponents, dn.size()); |
| | | |
| | | templateValue.getValue().append(dn.rdn(0)); |
| | | for (int i = 1; i < count; i++) |
| | | { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(dn.rdn(i)); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | int sz = dn.size(); |
| | | int count = Math.min(Math.abs(numComponents), sz); |
| | | |
| | | templateValue.getValue().append(dn.rdn(sz - count)); |
| | | for (int i = 1; i < count; i++) { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(dn.rdn(sz - count + i)); |
| | | } |
| | | } |
| | | |
| | | return TagResult.SUCCESS_RESULT; |
| | | } |
| | | } |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | |
| | | TemplateValue templateValue) |
| | | { |
| | | DN parentDN = templateEntry.getParentDN(); |
| | | if (parentDN == null || parentDN.isRootDN()) |
| | | if (parentDN != null && !parentDN.isRootDN()) |
| | | { |
| | | return TagResult.SUCCESS_RESULT; |
| | | Utils.joinAsString(templateValue.getValue(), "_", parentDN); |
| | | } |
| | | |
| | | templateValue.getValue().append(parentDN.rdn(0)); |
| | | for (int i=1; i < parentDN.size(); i++) |
| | | { |
| | | templateValue.append("_"); |
| | | templateValue.getValue().append(parentDN.rdn(i)); |
| | | } |
| | | |
| | | return TagResult.SUCCESS_RESULT; |
| | | } |
| | | } |
| | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.RDN; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | |
| | | DirectoryServer.getSchema().registerAttributeType(dummy, true); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the create method. |
| | | * |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test |
| | | public void testCreateNullDN1() throws Exception { |
| | | DN dn = new DN(new RDN[0]); |
| | | |
| | | assertEquals(dn, DN.rootDN()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the create method. |
| | | * |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test |
| | | public void testCreateNullDN2() throws Exception { |
| | | DN dn = new DN(); |
| | | |
| | | assertEquals(dn, DN.rootDN()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the create method. |
| | | * |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test |
| | | public void testCreateNullDN3() throws Exception { |
| | | DN dn = new DN((RDN[]) null); |
| | | |
| | | assertEquals(dn, DN.rootDN()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the create method. |
| | | * |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test |
| | | public void testCreateNullDN4() throws Exception { |
| | | DN dn = new DN((ArrayList<RDN>) null); |
| | | |
| | | assertEquals(dn, DN.rootDN()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the create method. |
| | | * |
| | |
| | | */ |
| | | @Test |
| | | public void testCreateWithSingleRDN1() throws Exception { |
| | | DN dn = new DN(new RDN[] { RDN.valueOf("dc=com") }); |
| | | |
| | | DN dn = DN.rootDN().child(RDN.valueOf("dc=com")); |
| | | assertEquals(dn, DN.valueOf("dc=com")); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Test |
| | | public void testCreateWithMultipleRDNs1() throws Exception { |
| | | DN dn = new DN(new RDN[] { RDN.valueOf("dc=foo"), |
| | | RDN.valueOf("dc=opends"), RDN.valueOf("dc=org") }); |
| | | |
| | | DN dn = DN.rootDN().child(RDN.valueOf("dc=org")).child(RDN.valueOf("dc=opends")).child(RDN.valueOf("dc=foo")); |
| | | assertEquals(dn, DN.valueOf("dc=foo,dc=opends,dc=org")); |
| | | } |
| | | |