Search in sources :

Example 6 with Nullable

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

the class GetConfigurationExtendedResult method encodeValue.

/**
 * Creates an ASN.1 octet string containing an encoded representation of the
 * value for a get configuration extended result with the provided
 * information.
 *
 * @param  configurationType  The type of configuration that has been
 *                            returned.
 * @param  fileName           The name of the configuration file that has been
 *                            returned.
 * @param  fileData           The raw data for the configuration file that has
 *                            been returned.
 *
 * @return  An ASN.1 octet string containing an encoded representation of the
 *          value for a get configuration extended result, or {@code null} if
 *          a result with the provided information should not have a value.
 */
@Nullable()
public static ASN1OctetString encodeValue(@Nullable final GetConfigurationType configurationType, @Nullable final String fileName, @Nullable final byte[] fileData) {
    if (configurationType == null) {
        Validator.ensureTrue((fileName == null), "The configuration file name must be null if the configuration " + "type is null.");
        Validator.ensureTrue((fileData == null), "The configuration file data must be null if the configuration " + "type is null.");
        return null;
    }
    Validator.ensureTrue((fileName != null), "The configuration file name must not be null if the configuration " + "type is not null.");
    Validator.ensureTrue((fileData != null), "The configuration file data must not be null if the configuration " + "type is not null.");
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated(TYPE_CONFIG_TYPE, configurationType.getIntValue()), new ASN1OctetString(TYPE_FILE_NAME, fileName), new ASN1OctetString(TYPE_FILE_DATA, fileData));
    return new ASN1OctetString(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) Nullable(com.unboundid.util.Nullable)

Example 7 with Nullable

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

the class GetPasswordQualityRequirementsExtendedResult method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value for this extended result, if appropriate.
 *
 * @param  resultCode               The result code for the response.  This
 *                                  must not be {@code null}.
 * @param  passwordRequirements     The password quality requirements for this
 *                                  result.  This must be {@code null} or
 *                                  empty if this result is for an operation
 *                                  that was not processed successfully.  It
 *                                  may be {@code null} or empty if the
 *                                  server will not enforce any password
 *                                  quality requirements for the target
 *                                  operation.
 * @param  currentPasswordRequired  Indicates whether the user will be
 *                                  required to provide his/her current
 *                                  password when performing a self change.
 *                                  This must be {@code null} if this result
 *                                  is for an operation that was not processed
 *                                  successfully or if the target operation is
 *                                  not a self change.
 * @param  mustChangePassword       Indicates whether the user will be
 *                                  required to change their password after
 *                                  the associated add or administrative
 *                                  reset before that user will be allowed to
 *                                  issue any other requests.  This must be
 *                                  {@code null} if this result is for an
 *                                  operation that was not processed
 *                                  successfully or if the target operation is
 *                                  not an add or an administrative reset.
 * @param  secondsUntilExpiration   Indicates the maximum length of time, in
 *                                  seconds, that the password set in the
 *                                  target operation will be valid.  If
 *                                  {@code mustChangePassword} is {@code true}
 *                                  then this will indicate the length of time
 *                                  that the user has to change his/her
 *                                  password after the add/reset.  If
 *                                  {@code mustChangePassword} is {@code null}
 *                                  or {@code false} then this will indicate
 *                                  the length of time until the password
 *                                  expires.  This must be {@code null} if
 *                                  this result is for an operation that was
 *                                  not processed successfully, or if the new
 *                                  password will be valid indefinitely.
 *
 * @return  The ASN.1 element with the encoded result value, or {@code null}
 *          if the result should not have a value.
 */
@Nullable()
private static ASN1OctetString encodeValue(@NotNull final ResultCode resultCode, @Nullable final Collection<PasswordQualityRequirement> passwordRequirements, @Nullable final Boolean currentPasswordRequired, @Nullable final Boolean mustChangePassword, @Nullable final Integer secondsUntilExpiration) {
    if (resultCode != ResultCode.SUCCESS) {
        Validator.ensureTrue((passwordRequirements == null) || passwordRequirements.isEmpty());
        Validator.ensureTrue(currentPasswordRequired == null);
        Validator.ensureTrue(mustChangePassword == null);
        Validator.ensureTrue(secondsUntilExpiration == null);
        return null;
    }
    final ArrayList<ASN1Element> valueSequence = new ArrayList<>(4);
    if (passwordRequirements == null) {
        valueSequence.add(new ASN1Sequence());
    } else {
        final ArrayList<ASN1Element> requirementElements = new ArrayList<>(passwordRequirements.size());
        for (final PasswordQualityRequirement r : passwordRequirements) {
            requirementElements.add(r.encode());
        }
        valueSequence.add(new ASN1Sequence(requirementElements));
    }
    if (currentPasswordRequired != null) {
        valueSequence.add(new ASN1Boolean(TYPE_CURRENT_PW_REQUIRED, currentPasswordRequired));
    }
    if (mustChangePassword != null) {
        valueSequence.add(new ASN1Boolean(TYPE_MUST_CHANGE_PW, mustChangePassword));
    }
    if (secondsUntilExpiration != null) {
        valueSequence.add(new ASN1Integer(TYPE_SECONDS_UNTIL_EXPIRATION, secondsUntilExpiration));
    }
    return new ASN1OctetString(new ASN1Sequence(valueSequence).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) ASN1Integer(com.unboundid.asn1.ASN1Integer) Nullable(com.unboundid.util.Nullable)

Example 8 with Nullable

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

the class GetSubtreeAccessibilityExtendedResult method encodeValue.

/**
 * Encodes the value for this extended result using the provided information.
 *
 * @param  restrictions  The set of subtree accessibility restrictions to
 *                       include in the response.  It may be {@code null} if
 *                       this represents an error response, or it may be empty
 *                       if there are no subtree accessibility restrictions
 *                       defined in the server.
 *
 * @return  An ASN.1 octet string containing the properly-encoded value, or
 *          {@code null} if there should be no value.
 */
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final Collection<SubtreeAccessibilityRestriction> restrictions) {
    if (restrictions == null) {
        return null;
    }
    final ArrayList<ASN1Element> elements = new ArrayList<>(restrictions.size());
    for (final SubtreeAccessibilityRestriction r : restrictions) {
        final ArrayList<ASN1Element> restrictionElements = new ArrayList<>(4);
        restrictionElements.add(new ASN1OctetString(TYPE_BASE_DN, r.getSubtreeBaseDN()));
        restrictionElements.add(new ASN1Enumerated(TYPE_STATE, r.getAccessibilityState().intValue()));
        if (r.getBypassUserDN() != null) {
            restrictionElements.add(new ASN1OctetString(TYPE_BYPASS_USER, r.getBypassUserDN()));
        }
        restrictionElements.add(new ASN1OctetString(TYPE_EFFECTIVE_TIME, StaticUtils.encodeGeneralizedTime(r.getEffectiveTime())));
        elements.add(new ASN1Sequence(restrictionElements));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) Nullable(com.unboundid.util.Nullable)

Example 9 with Nullable

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

the class ListConfigurationsExtendedResult method encodeValue.

/**
 * Creates an ASN.1 octet string containing an encoded representation of the
 * value for a list configurations extended result with the provided
 * information.
 *
 * @param  activeFileName     The name of the active configuration file, if
 *                            available.
 * @param  baselineFileNames  The names of the baseline configuration files
 *                            for current and former server versions, if
 *                            available.  It must be {@code null} or empty if
 *                            the active file name is {@code null}.
 * @param  archivedFileNames  The names of the archived configuration files,
 *                            if available.  It must be {@code null} or empty
 *                            if the active file name is {@code null}.
 *
 * @return  An ASN.1 octet string containing an encoded representation of the
 *          value for a list configurations extended result, or {@code null}
 *          if a result with the provided information should not have a value.
 */
@Nullable()
public static ASN1OctetString encodeValue(@Nullable final String activeFileName, @Nullable final Collection<String> baselineFileNames, @Nullable final Collection<String> archivedFileNames) {
    if (activeFileName == null) {
        Validator.ensureTrue(((baselineFileNames == null) || baselineFileNames.isEmpty()), "The baseline filename must be null if the active filename is null");
        Validator.ensureTrue(((archivedFileNames == null) || archivedFileNames.isEmpty()), "The archived filenames must be null or empty if the active " + "filename is null");
        return null;
    }
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(new ASN1OctetString(TYPE_ACTIVE_CONFIG_FILE_NAME, activeFileName));
    if ((baselineFileNames != null) && (!baselineFileNames.isEmpty())) {
        final TreeSet<String> sortedBaselineNames = new TreeSet<>(baselineFileNames);
        final ArrayList<ASN1Element> baselineNameElements = new ArrayList<>(sortedBaselineNames.size());
        for (final String s : sortedBaselineNames) {
            baselineNameElements.add(new ASN1OctetString(s));
        }
        elements.add(new ASN1Sequence(TYPE_BASELINE_CONFIG_FILE_NAMES, baselineNameElements));
    }
    if ((archivedFileNames != null) && (!archivedFileNames.isEmpty())) {
        final TreeSet<String> sortedArchivedNames = new TreeSet<>(archivedFileNames);
        final ArrayList<ASN1Element> archivedNameElements = new ArrayList<>(sortedArchivedNames.size());
        for (final String s : sortedArchivedNames) {
            archivedNameElements.add(new ASN1OctetString(s));
        }
        elements.add(new ASN1Sequence(TYPE_ARCHIVED_CONFIG_FILE_NAMES, archivedNameElements));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) TreeSet(java.util.TreeSet) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Nullable(com.unboundid.util.Nullable)

Example 10 with Nullable

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

the class ReplaceCertificateExtendedResult method encodeValue.

/**
 * Encodes a value for this extended result, if appropriate.
 *
 * @param  oid         The OID to use for the extended result.  It may be
 *                     {@code null} if no OID should be used.
 * @param  toolOutput  The output obtained from running the
 *                     {@code replace-certificate} tool.  It may be
 *                     {@code null} if request processing failed before
 *                     running the tool.
 *
 * @return  The encoded value for this extended result, or {@code null} if
 *          no value should be included.
 */
@Nullable()
public static ASN1OctetString encodeValue(@Nullable final String oid, @Nullable final String toolOutput) {
    if ((oid == null) && (toolOutput == null)) {
        return null;
    }
    final List<ASN1Element> valueElements = new ArrayList<>(1);
    if (toolOutput != null) {
        valueElements.add(new ASN1OctetString(TYPE_TOOL_OUTPUT, toolOutput));
    }
    final ASN1Sequence valueSequence = new ASN1Sequence(valueElements);
    return new ASN1OctetString(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) 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