Search in sources :

Example 26 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryOperationInterceptorRequestHandler method transformIntermediateResponse.

/**
 * Transforms the provided intermediate response and/or set of controls to
 * alter what will be returned to the client.
 *
 * @param  messageID  The message ID for the associated search operation.
 * @param  response   The intermediate response to be processed.  It will not
 *                    be {@code null}.
 * @param  controls   The set of controls to be processed.  It will not be
 *                    {@code null} but may be empty if there are no controls.
 *
 * @return  An {@link ObjectPair} containing a possibly updated intermediate
 *          response and set of controls, or {@code null} to indicate that the
 *          response should not be returned to the client.
 */
@Override()
@Nullable()
public ObjectPair<IntermediateResponseProtocolOp, Control[]> transformIntermediateResponse(final int messageID, @NotNull final IntermediateResponseProtocolOp response, @NotNull final Control[] controls) {
    final InterceptedOperation op = activeOperations.get(messageID);
    if (op == null) {
        return new ObjectPair<>(response, controls);
    }
    final InterceptedIntermediateResponse r = new InterceptedIntermediateResponse(op, response, controls);
    for (final InMemoryOperationInterceptor i : interceptors) {
        try {
            i.processIntermediateResponse(r);
            if (r.getIntermediateResponse() == null) {
                return null;
            }
        } catch (final Exception ex) {
            Debug.debugException(ex);
            return null;
        }
    }
    return new ObjectPair<>(new IntermediateResponseProtocolOp(r.getIntermediateResponse()), r.getIntermediateResponse().getControls());
}
Also used : IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ObjectPair(com.unboundid.util.ObjectPair) Nullable(com.unboundid.util.Nullable)

Example 27 with Nullable

use of com.unboundid.util.Nullable 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 28 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class UnboundIDChangeLogEntry method getAttributeAfterChange.

/**
 * Retrieves the specified attribute as it appeared in the target entry after
 * the change was processed, if available.  It may optionally include virtual
 * values.
 *
 * @param  name            The name of the attribute to retrieve as it
 *                         appeared after the change.
 * @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  The requested attribute as it appeared in the target entry after
 *          the change was processed, or {@code null} if it was not available
 *          in the changelog entry.
 *
 * @throws  ChangeLogEntryAttributeExceededMaxValuesException  If the
 *               specified attribute had more values before the change than
 *               may be included in a changelog entry.
 */
@Nullable()
public Attribute getAttributeAfterChange(@NotNull final String name, final boolean includeVirtual) throws ChangeLogEntryAttributeExceededMaxValuesException {
    if (getChangeType() == ChangeType.DELETE) {
        return null;
    }
    for (final Attribute a : getUpdatedAttributesAfterChange(includeVirtual)) {
        if (a.getName().equalsIgnoreCase(name)) {
            return a;
        }
    }
    for (final Attribute a : getKeyEntryAttributes(includeVirtual)) {
        if (a.getName().equalsIgnoreCase(name)) {
            return a;
        }
    }
    for (final ChangeLogEntryAttributeExceededMaxValuesCount a : attributesThatExceededMaxValuesCount) {
        if (a.getAttributeName().equalsIgnoreCase(name)) {
            // if the changes included adding specific values for the attribute.
            throw new ChangeLogEntryAttributeExceededMaxValuesException(ERR_CHANGELOG_EXCEEDED_AFTER_VALUE_COUNT.get(name, getTargetDN(), a.getAfterCount()), a);
        }
    }
    if (includeVirtual) {
        for (final ChangeLogEntryAttributeExceededMaxValuesCount a : virtualAttributesThatExceededMaxValuesCount) {
            if (a.getAttributeName().equalsIgnoreCase(name)) {
                // attribute.
                throw new ChangeLogEntryAttributeExceededMaxValuesException(ERR_CHANGELOG_EXCEEDED_VIRTUAL_AFTER_VALUE_COUNT.get(name, getTargetDN(), a.getAfterCount()), a);
            }
        }
    }
    final List<Attribute> addAttrs = getAddAttributes(includeVirtual);
    if (addAttrs != null) {
        for (final Attribute a : addAttrs) {
            if (a.getName().equalsIgnoreCase(name)) {
                return a;
            }
        }
    }
    final List<Modification> mods = getModifications();
    if (mods != null) {
        for (final Modification m : mods) {
            if (m.getAttributeName().equalsIgnoreCase(name)) {
                final byte[][] values = m.getValueByteArrays();
                if ((m.getModificationType() == ModificationType.REPLACE) && (values.length > 0)) {
                    return new Attribute(name, values);
                }
            }
        }
    }
    return null;
}
Also used : Modification(com.unboundid.ldap.sdk.Modification) Attribute(com.unboundid.ldap.sdk.Attribute) Nullable(com.unboundid.util.Nullable)

Example 29 with Nullable

use of com.unboundid.util.Nullable 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 30 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class LDAPPasswordModify method getCurrentPassword.

/**
 * Retrieves the bytes that comprise the current password for the user, if one
 * should be provided in the password update request.
 *
 * @return  The bytes that comprise the current password for the user, or
 *          {@code null} if none should be provided in the password update
 *          request.
 *
 * @throws  LDAPException  If a problem occurs while trying to obtain the
 *                         current password.
 */
@Nullable()
private byte[] getCurrentPassword() throws LDAPException {
    if (currentPassword.isPresent()) {
        return StaticUtils.getBytes(currentPassword.getValue());
    } else if (currentPasswordFile.isPresent()) {
        final File f = currentPasswordFile.getValue();
        try {
            final char[] currentPasswordChars = getPasswordFileReader().readPassword(f);
            return StaticUtils.getBytes(new String(currentPasswordChars));
        } catch (final LDAPException e) {
            Debug.debugException(e);
            throw new LDAPException(e.getResultCode(), ERR_PWMOD_CANNOT_READ_CURRENT_PW_FILE.get(f.getAbsolutePath(), e.getMessage()), e);
        } catch (final Exception e) {
            Debug.debugException(e);
            throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_PWMOD_CANNOT_READ_CURRENT_PW_FILE.get(f.getAbsolutePath(), StaticUtils.getExceptionMessage(e)), e);
        }
    } else if (promptForCurrentPassword.isPresent()) {
        while (true) {
            getOut().print(INFO_PWMOD_PROMPT_CURRENT_PW.get());
            try {
                final byte[] pwBytes = PasswordReader.readPassword();
                if ((pwBytes == null) || (pwBytes.length == 0)) {
                    err();
                    wrapErr(0, WRAP_COLUMN, ERR_PWMOD_PW_EMPTY.get());
                    err();
                    continue;
                }
                return pwBytes;
            } catch (final Exception e) {
                throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_PWMOD_CANNOT_PROMPT_FOR_CURRENT_PW.get(StaticUtils.getExceptionMessage(e)), e);
            }
        }
    } else {
        return null;
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) File(java.io.File) ArgumentException(com.unboundid.util.args.ArgumentException) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPExtendedOperationException(com.unboundid.ldap.sdk.LDAPExtendedOperationException) Nullable(com.unboundid.util.Nullable)

Aggregations

Nullable (com.unboundid.util.Nullable)149 ArrayList (java.util.ArrayList)47 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)42 Entry (com.unboundid.ldap.sdk.Entry)30 LDAPException (com.unboundid.ldap.sdk.LDAPException)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)21 Attribute (com.unboundid.ldap.sdk.Attribute)21 ASN1Element (com.unboundid.asn1.ASN1Element)20 Filter (com.unboundid.ldap.sdk.Filter)20 SearchResult (com.unboundid.ldap.sdk.SearchResult)18 IOException (java.io.IOException)16 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)14 File (java.io.File)14 DN (com.unboundid.ldap.sdk.DN)12 ArgumentException (com.unboundid.util.args.ArgumentException)10 RDN (com.unboundid.ldap.sdk.RDN)9 LDIFException (com.unboundid.ldif.LDIFException)8 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)7 Modification (com.unboundid.ldap.sdk.Modification)7 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)7