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);
}
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);
}
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) };
}
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));
}
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));
}
Aggregations