Search in sources :

Example 16 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class EntryChangeControlTest method testEncodeEntryChangeControlLong.

/**
 * Test encoding of a EntryChangeControl with a long changeNumber.
 */
@Test
public void testEncodeEntryChangeControlLong() throws Exception {
    ByteBuffer bb = ByteBuffer.allocate(0x13);
    bb.put(new byte[] { // EntryChangeNotification ::= SEQUENCE {
    0x30, // EntryChangeNotification ::= SEQUENCE {
    0x11, 0x0A, 0x01, // changeType ENUMERATED {
    0x08, // }
    0x04, 0x03, 'a', '=', // previousDN LDAPDN OPTIONAL, -- modifyDN ops. only
    'b', 0x02, // changeNumber INTEGER OPTIONAL -- if supported
    0x07, 0x12, 0x34, 0x56, 0x78, (byte) 0x9a, (byte) 0xbc, (byte) 0xde });
    String expected = Strings.dumpBytes(bb.array());
    bb.flip();
    EntryChangeDecorator decorator = new EntryChangeDecorator(codec);
    EntryChange entryChange = (EntryChange) decorator.getDecorated();
    entryChange.setChangeType(ChangeType.MODDN);
    entryChange.setChangeNumber(5124095576030430L);
    entryChange.setPreviousDn(new Dn("a=b"));
    bb = decorator.encode(ByteBuffer.allocate(decorator.computeLength()));
    String decoded = Strings.dumpBytes(bb.array());
    assertEquals(expected, decoded);
}
Also used : EntryChangeDecorator(org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeDecorator) Dn(org.apache.directory.api.ldap.model.name.Dn) EntryChange(org.apache.directory.api.ldap.model.message.controls.EntryChange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 17 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdapResultDsml method toDsml.

/**
 * {@inheritDoc}
 */
@Override
public Element toDsml(Element root) {
    // RequestID
    int requestID = message.getMessageId();
    if (requestID > 0) {
        root.addAttribute("requestID", Integer.toString(requestID));
    }
    // Matched Dn
    Dn matchedDn = result.getMatchedDn();
    if (!Dn.isNullOrEmpty(matchedDn)) {
        root.addAttribute("matchedDn", matchedDn.getName());
    }
    // Controls
    ParserUtils.addControls(codec, root, message.getControls().values());
    // ResultCode
    Element resultCodeElement = root.addElement("resultCode");
    resultCodeElement.addAttribute("code", Integer.toString(result.getResultCode().getResultCode()));
    resultCodeElement.addAttribute("descr", result.getResultCode().getMessage());
    // ErrorMessage
    String errorMessage = result.getDiagnosticMessage();
    if ((errorMessage != null) && (errorMessage.length() != 0)) {
        Element errorMessageElement = root.addElement("errorMessage");
        errorMessageElement.addText(errorMessage);
    }
    // Referrals
    Referral referral = result.getReferral();
    if (referral != null) {
        Collection<String> ldapUrls = referral.getLdapUrls();
        if (ldapUrls != null) {
            for (String ldapUrl : ldapUrls) {
                Element referalElement = root.addElement("referal");
                referalElement.addText(ldapUrl);
            }
        }
    }
    return root;
}
Also used : Referral(org.apache.directory.api.ldap.model.message.Referral) Element(org.dom4j.Element) Dn(org.apache.directory.api.ldap.model.name.Dn)

Example 18 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class BindRequestDsml method toDsml.

/**
 * {@inheritDoc}
 */
@Override
public Element toDsml(Element root) {
    Element element = super.toDsml(root);
    BindRequest request = getDecorated();
    // Principal
    Dn dn = request.getDn();
    if (!Dn.isNullOrEmpty(dn)) {
        // A DN has been provided
        element.addAttribute("principal", dn.getName());
    } else {
        // No DN has been provided, let's use the name as a string instead
        String name = request.getName();
        element.addAttribute("principal", name);
    }
    return element;
}
Also used : Element(org.dom4j.Element) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) Dn(org.apache.directory.api.ldap.model.name.Dn)

Example 19 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdifAnonymizer method anonymizeChangeModDn.

/**
 * Anonymize a Delete change
 */
private LdifEntry anonymizeChangeModDn(LdifEntry ldifEntry) throws LdapException {
    Dn entryDn = ldifEntry.getDn();
    // Process the DN
    Dn anonymizedDn = anonymizeDn(entryDn);
    ldifEntry.setDn(anonymizedDn);
    // Anonymize the newRdn if any
    String newRdnStr = ldifEntry.getNewRdn();
    if (newRdnStr != null) {
        Dn newRdn = new Dn(schemaManager, newRdnStr);
        Dn anonymizedRdn = anonymizeDn(newRdn);
        ldifEntry.setNewRdn(anonymizedRdn.toString());
    }
    // Anonymize the neSuperior if any
    String newSuperiorStr = ldifEntry.getNewSuperior();
    if (newSuperiorStr != null) {
        Dn newSuperior = new Dn(schemaManager, newSuperiorStr);
        Dn anonymizedSuperior = anonymizeDn(newSuperior);
        ldifEntry.setNewSuperior(anonymizedSuperior.toString());
    }
    return ldifEntry;
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn)

Example 20 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdifAnonymizer method anonymizeChangeDelete.

/**
 * Anonymize a Delete change
 */
private LdifEntry anonymizeChangeDelete(LdifEntry ldifEntry) throws LdapException {
    Dn entryDn = ldifEntry.getDn();
    // Process the DN, there is nothing more in the entry
    Dn anonymizedDn = anonymizeDn(entryDn);
    ldifEntry.setDn(anonymizedDn);
    return ldifEntry;
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)307 Test (org.junit.Test)183 Rdn (org.apache.directory.api.ldap.model.name.Rdn)63 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)50 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)39 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DnNode (org.apache.directory.api.ldap.util.tree.DnNode)30 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)20 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)19 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)17 Modification (org.apache.directory.api.ldap.model.entry.Modification)17 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)16 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)10 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 Referral (org.apache.directory.api.ldap.model.message.Referral)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 Value (org.apache.directory.api.ldap.model.entry.Value)8