Search in sources :

Example 11 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class UnboundIDChangeLogEntry method constructPartialEntryBeforeChange.

/**
 * Attempts to construct a partial representation of the target entry as it
 * appeared before the change was processed.  The information contained in the
 * constructed entry will be based solely on information contained in the
 * changelog entry, including information provided in the deletedEntryAttrs,
 * ds-changelog-before-values, ds-changelog-after-values,
 * ds-changelog-entry-key-attr-values, and
 * ds-changelog-attr-exceeded-max-values-count attributes, and optionally
 * virtual versions of all of those elements.
 *
 * @param  includeVirtual  Indicates whether to include both real and virtual
 *                         values (if {@code true}, or only real values (if
 *                         {@code false}), for the attributes to be returned.
 *
 * @return  A partial representation of the target entry as it appeared before
 *          the change was processed, or {@code null} if the change was an
 *          add operation and therefore the entry did not exist before the
 *          change.
 */
@Nullable()
public ReadOnlyEntry constructPartialEntryBeforeChange(final boolean includeVirtual) {
    if (getChangeType() == ChangeType.ADD) {
        return null;
    }
    final Entry e = new Entry(getTargetDN());
    // If there is a set of deleted entry attributes available, then use them.
    final List<Attribute> deletedEntryAttrs = getDeletedEntryAttributes(includeVirtual);
    if (deletedEntryAttrs != null) {
        for (final Attribute a : deletedEntryAttrs) {
            e.addAttribute(a);
        }
    }
    // If there is a set of before attributes, then use them.
    for (final Attribute a : getUpdatedAttributesBeforeChange(includeVirtual)) {
        e.addAttribute(a);
    }
    // the after values and exceeded max values count.
    for (final Attribute a : getKeyEntryAttributes(includeVirtual)) {
        boolean shouldExclude = e.hasAttribute(a.getName());
        for (final Attribute ba : getUpdatedAttributesAfterChange(includeVirtual)) {
            if (ba.getName().equalsIgnoreCase(a.getName())) {
                shouldExclude = true;
            }
        }
        for (final ChangeLogEntryAttributeExceededMaxValuesCount ea : attributesThatExceededMaxValuesCount) {
            if (ea.getAttributeName().equalsIgnoreCase(a.getName())) {
                // TODO:  In the event that the before count was exceeded but the
                // after count was not, then we may be able to reconstruct the before
                // values if the changes included deleting specific values for the
                // attribute.
                shouldExclude = true;
            }
        }
        if (includeVirtual) {
            for (final ChangeLogEntryAttributeExceededMaxValuesCount ea : virtualAttributesThatExceededMaxValuesCount) {
                if (ea.getAttributeName().equalsIgnoreCase(a.getName())) {
                    // TODO:  In the event that the before count was exceeded but the
                    // after count was not, then we may be able to reconstruct the
                    // before values if the changes included deleting specific values
                    // for the attribute.
                    shouldExclude = true;
                }
            }
        }
        if (!shouldExclude) {
            e.addAttribute(a);
        }
    }
    return new ReadOnlyEntry(e);
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) Attribute(com.unboundid.ldap.sdk.Attribute) Nullable(com.unboundid.util.Nullable)

Example 12 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class UnboundIDChangeLogEntry method constructPartialEntryAfterChange.

/**
 * Attempts to construct a partial representation of the target entry as it
 * appeared after the change was processed.  The information contained in the
 * constructed entry will be based solely on information contained in the
 * changelog entry, including information provided in the changes,
 * ds-changelog-after-values, and ds-changelog-entry-key-attr-values
 * attributes, and optionally virtual versions of all of those elements.
 *
 * @param  includeVirtual  Indicates whether to include both real and virtual
 *                         values (if {@code true}, or only real values (if
 *                         {@code false}), for the attributes to be returned.
 *
 * @return  A partial representation of the target entry as it appeared after
 *          the change was processed, or {@code null} if the change was a
 *          delete operation and therefore did not exist after the change.
 */
@Nullable()
public ReadOnlyEntry constructPartialEntryAfterChange(final boolean includeVirtual) {
    final Entry e;
    switch(getChangeType()) {
        case ADD:
        case MODIFY:
            e = new Entry(getTargetDN());
            break;
        case MODIFY_DN:
            e = new Entry(getNewDN());
            break;
        case DELETE:
        default:
            return null;
    }
    // If there is a set of add attributes, then use them.
    final List<Attribute> addAttrs = getAddAttributes(includeVirtual);
    if (addAttrs != null) {
        for (final Attribute a : addAttrs) {
            e.addAttribute(a);
        }
    }
    // If there is a set of modifications and any of them are replace
    // modifications with a set of values, then we can use them to determine
    // the new values of those attributes.
    final List<Modification> mods = getModifications();
    if (mods != null) {
        for (final Modification m : mods) {
            final byte[][] values = m.getValueByteArrays();
            if ((m.getModificationType() == ModificationType.REPLACE) && (values.length > 0)) {
                e.addAttribute(m.getAttributeName(), values);
            }
        }
    }
    // If there is a set of after attributes, then use them.
    for (final Attribute a : getUpdatedAttributesAfterChange(includeVirtual)) {
        e.addAttribute(a);
    }
    // If there is a set of key attributes, then use them.
    for (final Attribute a : getKeyEntryAttributes(includeVirtual)) {
        e.addAttribute(a);
    }
    return new ReadOnlyEntry(e);
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) Attribute(com.unboundid.ldap.sdk.Attribute) Nullable(com.unboundid.util.Nullable)

Example 13 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class GetAuthorizationEntryResponseControl method decodeAuthEntry.

/**
 * Decodes the provided ASN.1 element into an array of auth entry elements.
 * The first element of the array will be the auth ID, and the second element
 * will be the read-only entry.
 *
 * @param  element  The element to decode.
 *
 * @return  The decoded array of elements.
 *
 * @throws  ASN1Exception  If a problem occurs while performing ASN.1 parsing.
 *
 * @throws  LDAPException  If a problem occurs while performing LDAP parsing.
 */
@NotNull()
private static Object[] decodeAuthEntry(@NotNull final ASN1Element element) throws ASN1Exception, LDAPException {
    String authID = null;
    String authDN = null;
    final ArrayList<Attribute> attrs = new ArrayList<>(20);
    for (final ASN1Element e : ASN1Sequence.decodeAsSequence(element).elements()) {
        switch(e.getType()) {
            case TYPE_AUTHID:
                authID = ASN1OctetString.decodeAsOctetString(e).stringValue();
                break;
            case TYPE_AUTHDN:
                authDN = ASN1OctetString.decodeAsOctetString(e).stringValue();
                break;
            case TYPE_ATTRIBUTES:
                for (final ASN1Element ae : ASN1Sequence.decodeAsSequence(e).elements()) {
                    attrs.add(Attribute.decode(ASN1Sequence.decodeAsSequence(ae)));
                }
                break;
            default:
                throw new LDAPException(ResultCode.DECODING_ERROR, ERR_GET_AUTHORIZATION_ENTRY_RESPONSE_INVALID_ENTRY_TYPE.get(StaticUtils.toHex(e.getType())));
        }
    }
    return new Object[] { authID, new ReadOnlyEntry(authDN, attrs) };
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) LDAPException(com.unboundid.ldap.sdk.LDAPException) Attribute(com.unboundid.ldap.sdk.Attribute) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Example 14 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class LDAPObjectHandlerTestCase method testEncodeValidObjectWithImplicitParentDN.

/**
 * Provides test coverage for the {@code encode} method with a valid, complete
 * object and an implicitly-specified parent DN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testEncodeValidObjectWithImplicitParentDN() throws Exception {
    LDAPObjectHandler<TestBasicObject> handler = new LDAPObjectHandler<TestBasicObject>(TestBasicObject.class);
    TestBasicObject o = new TestBasicObject();
    o.setA("eh");
    o.setB("bee");
    o.setC("sea");
    o.setD("dee");
    o.setM("em");
    o.setN("en");
    o.setO("oh");
    assertNull(o.getDN());
    assertNull(o.getEntry());
    Entry e = handler.encode(o, null);
    assertEquals(e, new Entry("dn: a=eh,ou=default,dc=example,dc=com", "objectClass: x", "objectClass: y", "objectClass: z", "a: eh", "b: bee", "c: sea", "m: em", "n: en", "addedInPostEncode: foo"));
    assertNotNull(o.getDN());
    assertEquals(new DN(o.getDN()), new DN("a=eh,ou=default,dc=example,dc=com"));
    assertNotNull(o.getEntry());
    assertEquals(o.getEntry(), new ReadOnlyEntry(e));
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) DN(com.unboundid.ldap.sdk.DN) Test(org.testng.annotations.Test)

Example 15 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class LDAPObjectHandlerTestCase method testEncodeValidObjectWithExplicitEmptyParentDN.

/**
 * Provides test coverage for the {@code encode} method with a valid, complete
 * object and an explicitly-specified empty parent DN.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testEncodeValidObjectWithExplicitEmptyParentDN() throws Exception {
    LDAPObjectHandler<TestBasicObject> handler = new LDAPObjectHandler<TestBasicObject>(TestBasicObject.class);
    TestBasicObject o = new TestBasicObject();
    o.setA("eh");
    o.setB("bee");
    o.setC("sea");
    o.setD("dee");
    o.setM("em");
    o.setN("en");
    o.setO("oh");
    assertNull(o.getDN());
    assertNull(o.getEntry());
    Entry e = handler.encode(o, "");
    assertEquals(e, new Entry("dn: a=eh", "objectClass: x", "objectClass: y", "objectClass: z", "a: eh", "b: bee", "c: sea", "m: em", "n: en", "addedInPostEncode: foo"));
    assertNotNull(o.getDN());
    assertEquals(new DN(o.getDN()), new DN("a=eh"));
    assertNotNull(o.getEntry());
    assertEquals(o.getEntry(), new ReadOnlyEntry(e));
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) DN(com.unboundid.ldap.sdk.DN) Test(org.testng.annotations.Test)

Aggregations

ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)94 Test (org.testng.annotations.Test)64 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)41 Entry (com.unboundid.ldap.sdk.Entry)29 DN (com.unboundid.ldap.sdk.DN)27 Attribute (com.unboundid.ldap.sdk.Attribute)25 Modification (com.unboundid.ldap.sdk.Modification)21 LDAPException (com.unboundid.ldap.sdk.LDAPException)18 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)16 Control (com.unboundid.ldap.sdk.Control)14 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)14 NotNull (com.unboundid.util.NotNull)14 RDN (com.unboundid.ldap.sdk.RDN)12 ArrayList (java.util.ArrayList)12 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)9 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)8 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)8 Schema (com.unboundid.ldap.sdk.schema.Schema)8 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)7 ServerSideSortResponseControl (com.unboundid.ldap.sdk.controls.ServerSideSortResponseControl)7