Search in sources :

Example 36 with Nullable

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

the class AuditLogMessage method decodeOperationPurposeRequestControl.

/**
 * Decodes the operation purpose request control, if any, from the provided
 * set of name-value pairs.
 *
 * @param  nameValuePairs  The map containing the header properties as
 *                         name-value pairs.  It must not be {@code null}.
 *
 * @return  The operation purpose request control retrieved and decoded from
 *          the provided set of name-value pairs, or {@code null} if no
 *          valid operation purpose request control was included.
 */
@Nullable()
private static OperationPurposeRequestControl decodeOperationPurposeRequestControl(@NotNull final Map<String, String> nameValuePairs) {
    final String valueString = nameValuePairs.get("operationPurpose");
    if (valueString == null) {
        return null;
    }
    try {
        final JSONObject o = new JSONObject(valueString);
        final String applicationName = o.getFieldAsString("applicationName");
        final String applicationVersion = o.getFieldAsString("applicationVersion");
        final String codeLocation = o.getFieldAsString("codeLocation");
        final String requestPurpose = o.getFieldAsString("requestPurpose");
        return new OperationPurposeRequestControl(false, applicationName, applicationVersion, codeLocation, requestPurpose);
    } catch (final Exception e) {
        Debug.debugException(e);
        return null;
    }
}
Also used : OperationPurposeRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl) JSONObject(com.unboundid.util.json.JSONObject) ParseException(java.text.ParseException) Nullable(com.unboundid.util.Nullable)

Example 37 with Nullable

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

the class LDIFReader method readLDIFRecordResultAsync.

/**
 * Reads the next LDIF record, which was read and parsed asynchronously by
 * separate threads.
 *
 * @return  The next LDIF record or {@code null} if there are no more records.
 *
 * @throws  IOException  If a problem occurs while attempting to read from the
 *                       LDIF source.
 *
 * @throws  LDIFException  If the data read could not be parsed as an entry.
 */
@Nullable()
private Result<UnparsedLDIFRecord, LDIFRecord> readLDIFRecordResultAsync() throws IOException, LDIFException {
    Result<UnparsedLDIFRecord, LDIFRecord> result = null;
    // isn't a record there, then return null (EOF) right away.
    if (asyncParsingComplete.get()) {
        result = asyncParsedRecords.poll();
    } else {
        try {
            // (like shutdown).
            while ((result == null) && (!asyncParsingComplete.get())) {
                result = asyncParsedRecords.poll(1, TimeUnit.SECONDS);
            }
            // There's a very small chance that we missed the value, so double-check
            if (result == null) {
                result = asyncParsedRecords.poll();
            }
        } catch (final InterruptedException e) {
            Debug.debugException(e);
            Thread.currentThread().interrupt();
            throw new IOException(e);
        }
    }
    if (result == null) {
        return null;
    }
    rethrow(result.getFailureCause());
    // Check if we reached the end of the input
    final UnparsedLDIFRecord unparsedRecord = result.getInput();
    if (unparsedRecord.isEOF()) {
        // This might have been set already by the LineReaderThread, but
        // just in case it hasn't gotten to it yet, do so here.
        asyncParsingComplete.set(true);
        // class.
        try {
            asyncParsedRecords.put(result);
        } catch (final InterruptedException e) {
            // We shouldn't ever get interrupted because the put won't ever block.
            // Once we are done reading, this is the only item left in the queue,
            // so we should always be able to re-enqueue it.
            Debug.debugException(e);
            Thread.currentThread().interrupt();
        }
        return null;
    }
    return result;
}
Also used : IOException(java.io.IOException) Nullable(com.unboundid.util.Nullable)

Example 38 with Nullable

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

the class LDIFDiff method pareEntry.

/**
 * Creates a pared-down copy of the provided entry based on the requested
 * set of options.
 *
 * @param  entry         The entry to be pared down.  It must not be
 *                       {@code null}.
 * @param  schema        The schema to use during processing.  It must not be
 *                       {@ocde null}.
 * @param  includeAttrs  A set containing all names and OIDs for all attribute
 *                       types that should be included in the entry.  It must
 *                       not be {@ocde null} but may be empty.  All values
 *                       must be formatted entirely in lowercase.
 * @param  excludeAttrs  A set containing all names and OIDs for all attribute
 *                       types that should be excluded from the entry.  It
 *                       must not be {@code null} but may be empty.  All
 *                       values must be formatted entirely in lowercase.
 *
 * @return  A pared-down copy of the provided entry, or {@code null} if the
 *          pared-down entry would not include any attributes.
 */
@Nullable()
private Entry pareEntry(@NotNull final Entry entry, @NotNull final Schema schema, @NotNull final Set<String> includeAttrs, @NotNull final Set<String> excludeAttrs) {
    final List<Attribute> paredAttributeList = new ArrayList<>();
    for (final Attribute a : entry.getAttributes()) {
        final String baseName = StaticUtils.toLowerCase(a.getBaseName());
        if (excludeAttrs.contains(baseName)) {
            continue;
        }
        if ((!includeAttrs.isEmpty()) && (!includeAttrs.contains(baseName))) {
            continue;
        }
        final AttributeTypeDefinition at = schema.getAttributeType(baseName);
        if ((at != null) && at.isOperational()) {
            if (!includeOperationalAttributes.isPresent()) {
                continue;
            }
            if (at.isNoUserModification() && excludeNoUserModificationAttributes.isPresent()) {
                continue;
            }
        }
        paredAttributeList.add(a);
    }
    if (paredAttributeList.isEmpty()) {
        return null;
    }
    return new Entry(entry.getDN(), paredAttributeList);
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) Entry(com.unboundid.ldap.sdk.Entry) Attribute(com.unboundid.ldap.sdk.Attribute) ArrayList(java.util.ArrayList) Nullable(com.unboundid.util.Nullable)

Example 39 with Nullable

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

the class LDIFReader method readEntryInternal.

/**
 * Reads an entry from the LDIF source.
 *
 * @return The entry read from the LDIF source, or {@code null} if there are
 *         no more entries to be read.
 *
 * @throws IOException   If a problem occurs while attempting to read from the
 *                       LDIF source.
 * @throws LDIFException If the data read could not be parsed as an entry.
 */
@Nullable()
private Entry readEntryInternal() throws IOException, LDIFException {
    Entry e = null;
    while (e == null) {
        final UnparsedLDIFRecord unparsedRecord = readUnparsedRecord();
        if (unparsedRecord.isEOF()) {
            return null;
        }
        e = decodeEntry(unparsedRecord, relativeBasePath);
        Debug.debugLDIFRead(e);
        if (entryTranslator != null) {
            e = entryTranslator.translate(e, unparsedRecord.getFirstLineNumber());
        }
    }
    return e;
}
Also used : Entry(com.unboundid.ldap.sdk.Entry) Nullable(com.unboundid.util.Nullable)

Example 40 with Nullable

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

the class ChangeLogEntry method parseDeletedAttributeList.

/**
 * Parses the list of deleted attributes from a changelog entry representing a
 * delete operation.  The attribute is optional, so it may not be present at
 * all, and there are two different encodings that we need to handle.  One
 * encoding is the same as is used for the add attribute list, and the second
 * is similar to the encoding used for the list of changes, except that it
 * ends with a NULL byte (0x00).
 *
 * @param  entry     The entry containing the data to parse.
 * @param  targetDN  The DN of the target entry.
 *
 * @return  The parsed deleted attribute list, or {@code null} if the
 *          changelog entry does not include a deleted attribute list.
 *
 * @throws  LDAPException  If an error occurs while parsing the deleted
 *                         attribute list.
 */
@Nullable()
private static List<Attribute> parseDeletedAttributeList(@NotNull final Entry entry, @NotNull final String targetDN) throws LDAPException {
    Attribute deletedEntryAttrs = entry.getAttribute(ATTR_DELETED_ENTRY_ATTRS);
    if ((deletedEntryAttrs == null) || (!deletedEntryAttrs.hasValue())) {
        deletedEntryAttrs = entry.getAttribute(ATTR_ALTERNATIVE_DELETED_ENTRY_ATTRS_INCLUDED_ATTRIBUTES);
        if ((deletedEntryAttrs == null) || (!deletedEntryAttrs.hasValue())) {
            return null;
        }
    }
    final byte[] valueBytes = deletedEntryAttrs.getValueByteArray();
    if ((valueBytes.length > 0) && (valueBytes[valueBytes.length - 1] == 0x00)) {
        final String valueStr = new String(valueBytes, 0, valueBytes.length - 2, StandardCharsets.UTF_8);
        final ArrayList<String> ldifLines = new ArrayList<>(20);
        ldifLines.add("dn: " + targetDN);
        ldifLines.add("changetype: modify");
        final StringTokenizer tokenizer = new StringTokenizer(valueStr, "\r\n");
        while (tokenizer.hasMoreTokens()) {
            ldifLines.add(tokenizer.nextToken());
        }
        final String[] lineArray = new String[ldifLines.size()];
        ldifLines.toArray(lineArray);
        try {
            final LDIFModifyChangeRecord changeRecord = (LDIFModifyChangeRecord) LDIFReader.decodeChangeRecord(lineArray);
            final Modification[] mods = changeRecord.getModifications();
            final ArrayList<Attribute> attrs = new ArrayList<>(mods.length);
            for (final Modification m : mods) {
                if (!m.getModificationType().equals(ModificationType.DELETE)) {
                    throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CHANGELOG_INVALID_DELENTRYATTRS_MOD_TYPE.get(ATTR_DELETED_ENTRY_ATTRS));
                }
                attrs.add(m.getAttribute());
            }
            return Collections.unmodifiableList(attrs);
        } catch (final LDIFException le) {
            Debug.debugException(le);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CHANGELOG_INVALID_DELENTRYATTRS_MODS.get(ATTR_DELETED_ENTRY_ATTRS, StaticUtils.getExceptionMessage(le)), le);
        }
    } else {
        final ArrayList<String> ldifLines = new ArrayList<>(20);
        ldifLines.add("dn: " + targetDN);
        final StringTokenizer tokenizer = new StringTokenizer(deletedEntryAttrs.getValue(), "\r\n");
        while (tokenizer.hasMoreTokens()) {
            ldifLines.add(tokenizer.nextToken());
        }
        final String[] lineArray = new String[ldifLines.size()];
        ldifLines.toArray(lineArray);
        try {
            final Entry e = LDIFReader.decodeEntry(true, TrailingSpaceBehavior.RETAIN, null, lineArray);
            return Collections.unmodifiableList(new ArrayList<>(e.getAttributes()));
        } catch (final LDIFException le) {
            Debug.debugException(le);
            throw new LDAPException(ResultCode.DECODING_ERROR, ERR_CHANGELOG_CANNOT_PARSE_DELENTRYATTRS.get(ATTR_DELETED_ENTRY_ATTRS, StaticUtils.getExceptionMessage(le)), le);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) LDIFModifyChangeRecord(com.unboundid.ldif.LDIFModifyChangeRecord) StringTokenizer(java.util.StringTokenizer) LDIFException(com.unboundid.ldif.LDIFException) 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