Search in sources :

Example 21 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class IdentifyBackupCompatibilityProblemsExtendedRequest method encodeValue.

/**
 * Encodes the provided information into a format suitable for use as the
 * value of this extended request.
 *
 * @param  sourceDescriptor  The backup compatibility descriptor obtained from
 *                           the source server, or from a backup to be
 *                           restored.  It must not be {@code null}.
 * @param  targetDescriptor  The backup compatibility descriptor obtained from
 *                           the target server.  It must not be {@code null}.
 *
 * @return  The ASN.1 octet string containing the encoded representation of
 *          the provided information.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString sourceDescriptor, @NotNull final ASN1OctetString targetDescriptor) {
    Validator.ensureNotNull(sourceDescriptor);
    Validator.ensureNotNull(targetDescriptor);
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString(TYPE_SOURCE_DESCRIPTOR, sourceDescriptor.getValue()), new ASN1OctetString(TYPE_TARGET_DESCRIPTOR, targetDescriptor.getValue()));
    return new ASN1OctetString(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) NotNull(com.unboundid.util.NotNull)

Example 22 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString 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 23 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString 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 24 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString 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 25 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString 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)

Aggregations

ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1173 Test (org.testng.annotations.Test)852 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)382 Control (com.unboundid.ldap.sdk.Control)310 ASN1Element (com.unboundid.asn1.ASN1Element)237 ArrayList (java.util.ArrayList)204 NotNull (com.unboundid.util.NotNull)191 LDAPException (com.unboundid.ldap.sdk.LDAPException)142 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)133 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)99 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)92 IOException (java.io.IOException)88 ASN1Integer (com.unboundid.asn1.ASN1Integer)80 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)69 DN (com.unboundid.ldap.sdk.DN)65 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)64 ByteArrayInputStream (java.io.ByteArrayInputStream)56 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)53 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)52 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)49