Search in sources :

Example 51 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class UniquenessResponseControl method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value of this control.
 *
 * @param  uniquenessID                The uniqueness ID that may be used to
 *                                     correlate this uniqueness response
 *                                     control with the corresponding request
 *                                     control.  This must not be
 *                                     {@code null}.
 * @param  preCommitValidationPassed   Indicates whether the pre-commit
 *                                     validation was successful.  This may be
 *                                     {@code null} if no pre-commit
 *                                     validation was attempted.
 * @param  postCommitValidationPassed  Indicates whether the post-commit
 *                                     validation was successful.  This may be
 *                                     {@code null} if no post-commit
 *                                     validation was attempted.
 * @param  validationMessage           A message with additional information
 *                                     about the validation processing.  This
 *                                     may be {@code null} if no validation
 *                                     message is needed.
 *
 * @return  The encoded control value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String uniquenessID, @Nullable final Boolean preCommitValidationPassed, @Nullable final Boolean postCommitValidationPassed, @Nullable final String validationMessage) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(4);
    elements.add(new ASN1OctetString(TYPE_UNIQUENESS_ID, uniquenessID));
    if (preCommitValidationPassed != null) {
        elements.add(new ASN1Boolean(TYPE_PRE_COMMIT_VALIDATION_PASSED, preCommitValidationPassed));
    }
    if (postCommitValidationPassed != null) {
        elements.add(new ASN1Boolean(TYPE_POST_COMMIT_VALIDATION_PASSED, postCommitValidationPassed));
    }
    if (validationMessage != null) {
        elements.add(new ASN1OctetString(TYPE_VALIDATION_MESSAGE, validationMessage));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).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) NotNull(com.unboundid.util.NotNull)

Example 52 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class DeliverSingleUseTokenExtendedRequest method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value of the extended request.
 *
 * @param  userDN                       The DN of the user for whom the token
 *                                      should be generated and delivered.  It
 *                                      must not be {@code null}.
 * @param  tokenID                      An identifier for the token, which can
 *                                      differentiate between separate uses of
 *                                      this extended operation for different
 *                                      purposes.  This token ID should be
 *                                      provided in the request to consume the
 *                                      token that has been delivered.  It
 *                                      must not be {@code null}.
 * @param  validityDurationMillis       The maximum length of time in
 *                                      milliseconds that the generated token
 *                                      should be considered valid.  It may be
 *                                      {@code null} if the server should
 *                                      determine the token validity duration.
 *                                      If it is non-{@code null}, then the
 *                                      value must be greater than zero.
 * @param  messageSubject               The text (if any) that should be used
 *                                      as the message subject if the delivery
 *                                      mechanism accepts a subject.  This may
 *                                      be {@code null} if no subject is
 *                                      required or a subject should be
 *                                      automatically generated.
 * @param  fullTextBeforeToken          The text (if any) that should appear
 *                                      before the generated single-use token
 *                                      in the message delivered to the user
 *                                      via a delivery mechanism that does not
 *                                      impose significant constraints on
 *                                      message size.  This may be
 *                                      {@code null} if no text is required
 *                                      before the token.
 * @param  fullTextAfterToken           The text (if any) that should appear
 *                                      after the generated single-use token
 *                                      in the message delivered to the user
 *                                      via a delivery mechanism that does not
 *                                      impose significant constraints on
 *                                      message size.  This may be
 *                                      {@code null} if no text is required
 *                                      after the token.
 * @param  compactTextBeforeToken       The text (if any) that should appear
 *                                      before the generated single-use token
 *                                      in the message delivered to the user
 *                                      via a delivery mechanism that imposes
 *                                      significant constraints on message
 *                                      size.  This may be {@code null} if no
 *                                      text is required before the token.
 * @param  compactTextAfterToken        The text (if any) that should appear
 *                                      after the generated single-use token
 *                                      in the message delivered to the user
 *                                      via a delivery mechanism that imposes
 *                                      significant constraints on message
 *                                      size.  This may be {@code null} if no
 *                                      text is required after the token.
 * @param  preferredDeliveryMechanisms  An optional list of the preferred
 *                                      delivery mechanisms that should be
 *                                      used to convey the token to the target
 *                                      user.  It may be {@code null} or empty
 *                                      if the server should determine the
 *                                      delivery mechanisms to attempt.  If
 *                                      a list of preferred delivery
 *                                      mechanisms is provided, the server
 *                                      will only attempt to deliver the token
 *                                      through these mechanisms, with
 *                                      attempts made in the order specified
 *                                      in this list.
 * @param  deliverIfPasswordExpired     Indicates whether to generate and
 *                                      deliver a token if the target user's
 *                                      password is expired.
 * @param  deliverIfAccountLocked       Indicates whether to generate and
 *                                      deliver a token if the target user's
 *                                      account is locked for some reason
 *                                      (e.g., too many failed authentication
 *                                      attempts, the account has been idle
 *                                      for too long, the user failed to
 *                                      change his/her password in a timely
 *                                      manner after an administrative reset,
 *                                      etc.).
 * @param  deliverIfAccountDisabled     Indicates whether to generate and
 *                                      deliver a token if the target user's
 *                                      account has been disabled by an
 *                                      administrator.
 * @param  deliverIfAccountExpired      Indicates whether to generate and
 *                                      deliver a token if the target user's
 *                                      account has expired.
 *
 * @return  An ASN.1 octet string containing the encoded value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String userDN, @NotNull final String tokenID, @Nullable final Long validityDurationMillis, @Nullable final String messageSubject, @Nullable final String fullTextBeforeToken, @Nullable final String fullTextAfterToken, @Nullable final String compactTextBeforeToken, @Nullable final String compactTextAfterToken, @Nullable final List<ObjectPair<String, String>> preferredDeliveryMechanisms, final boolean deliverIfPasswordExpired, final boolean deliverIfAccountLocked, final boolean deliverIfAccountDisabled, final boolean deliverIfAccountExpired) {
    Validator.ensureNotNull(userDN);
    Validator.ensureNotNull(tokenID);
    if (validityDurationMillis != null) {
        Validator.ensureTrue(validityDurationMillis > 0L);
    }
    final ArrayList<ASN1Element> elements = new ArrayList<>(13);
    elements.add(new ASN1OctetString(userDN));
    elements.add(new ASN1OctetString(tokenID));
    if (validityDurationMillis != null) {
        elements.add(new ASN1Long(VALIDITY_DURATION_MILLIS_BER_TYPE, validityDurationMillis));
    }
    if (messageSubject != null) {
        elements.add(new ASN1OctetString(MESSAGE_SUBJECT_BER_TYPE, messageSubject));
    }
    if (fullTextBeforeToken != null) {
        elements.add(new ASN1OctetString(FULL_TEXT_BEFORE_TOKEN_BER_TYPE, fullTextBeforeToken));
    }
    if (fullTextAfterToken != null) {
        elements.add(new ASN1OctetString(FULL_TEXT_AFTER_TOKEN_BER_TYPE, fullTextAfterToken));
    }
    if (compactTextBeforeToken != null) {
        elements.add(new ASN1OctetString(COMPACT_TEXT_BEFORE_TOKEN_BER_TYPE, compactTextBeforeToken));
    }
    if (compactTextAfterToken != null) {
        elements.add(new ASN1OctetString(COMPACT_TEXT_AFTER_TOKEN_BER_TYPE, compactTextAfterToken));
    }
    if ((preferredDeliveryMechanisms != null) && (!preferredDeliveryMechanisms.isEmpty())) {
        final ArrayList<ASN1Element> pdmElements = new ArrayList<>(preferredDeliveryMechanisms.size());
        for (final ObjectPair<String, String> p : preferredDeliveryMechanisms) {
            final ArrayList<ASN1Element> l = new ArrayList<>(2);
            l.add(new ASN1OctetString(p.getFirst()));
            if (p.getSecond() != null) {
                l.add(new ASN1OctetString(p.getSecond()));
            }
            pdmElements.add(new ASN1Sequence(l));
        }
        elements.add(new ASN1Sequence(PREFERRED_DELIVERY_MECHANISM_BER_TYPE, pdmElements));
    }
    if (deliverIfPasswordExpired) {
        elements.add(new ASN1Boolean(DELIVER_IF_PASSWORD_EXPIRED_TYPE, true));
    }
    if (deliverIfAccountLocked) {
        elements.add(new ASN1Boolean(DELIVER_IF_ACCOUNT_LOCKED_TYPE, true));
    }
    if (deliverIfAccountDisabled) {
        elements.add(new ASN1Boolean(DELIVER_IF_ACCOUNT_DISABLED_TYPE, true));
    }
    if (deliverIfAccountExpired) {
        elements.add(new ASN1Boolean(DELIVER_IF_ACCOUNT_EXPIRED_TYPE, true));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Long(com.unboundid.asn1.ASN1Long) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 53 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class CollectSupportDataExtendedRequest method encodeValue.

/**
 * Constructs an ASN.1 octet string suitable for use as the value of this
 * collect support data extended request from the given set of properties.
 *
 * @param  properties  The properties that should be used to construct the
 *                     extended request value.  It must not be {@code null}.
 *
 * @return  the ASN.1 octet string that was created.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final CollectSupportDataExtendedRequestProperties properties) {
    final List<ASN1Element> elements = new ArrayList<>(20);
    final String archiveFileName = properties.getArchiveFileName();
    if (archiveFileName != null) {
        elements.add(new ASN1OctetString(TYPE_ARCHIVE_FILE_NAME, archiveFileName));
    }
    final ASN1OctetString encryptionPassphrase = properties.getEncryptionPassphrase();
    if (encryptionPassphrase != null) {
        elements.add(encryptionPassphrase);
    }
    final Boolean includeExpensiveData = properties.getIncludeExpensiveData();
    if (includeExpensiveData != null) {
        elements.add(new ASN1Boolean(TYPE_INCLUDE_EXPENSIVE_DATA, includeExpensiveData));
    }
    final Boolean includeReplicationStateDump = properties.getIncludeReplicationStateDump();
    if (includeReplicationStateDump != null) {
        elements.add(new ASN1Boolean(TYPE_INCLUDE_REPLICATION_STATE_DUMP, includeReplicationStateDump));
    }
    final Boolean includeBinaryFiles = properties.getIncludeBinaryFiles();
    if (includeBinaryFiles != null) {
        elements.add(new ASN1Boolean(TYPE_INCLUDE_BINARY_FILES, includeBinaryFiles));
    }
    final Boolean includeExtensionSource = properties.getIncludeExtensionSource();
    if (includeExtensionSource != null) {
        elements.add(new ASN1Boolean(TYPE_INCLUDE_EXTENSION_SOURCE, includeExtensionSource));
    }
    final Boolean useSequentialMode = properties.getUseSequentialMode();
    if (useSequentialMode != null) {
        elements.add(new ASN1Boolean(TYPE_USE_SEQUENTIAL_MODE, useSequentialMode));
    }
    final CollectSupportDataSecurityLevel securityLevel = properties.getSecurityLevel();
    if (securityLevel != null) {
        final int securityLevelIntValue;
        switch(securityLevel) {
            case NONE:
                securityLevelIntValue = SECURITY_LEVEL_VALUE_NONE;
                break;
            case OBSCURE_SECRETS:
                securityLevelIntValue = SECURITY_LEVEL_VALUE_OBSCURE_SECRETS;
                break;
            case MAXIMUM:
                securityLevelIntValue = SECURITY_LEVEL_VALUE_MAXIMUM;
                break;
            default:
                throw new LDAPRuntimeException(new LDAPException(ResultCode.LOCAL_ERROR, ERR_CSD_REQUEST_UNSUPPORTED_SECURITY_LEVEL.get(securityLevel.getName())));
        }
        elements.add(new ASN1Enumerated(TYPE_SECURITY_LEVEL, securityLevelIntValue));
    }
    final Integer jstackCount = properties.getJStackCount();
    if (jstackCount != null) {
        elements.add(new ASN1Integer(TYPE_JSTACK_COUNT, jstackCount));
    }
    final Integer reportCount = properties.getReportCount();
    if (reportCount != null) {
        elements.add(new ASN1Integer(TYPE_REPORT_COUNT, reportCount));
    }
    final Integer reportIntervalSeconds = properties.getReportIntervalSeconds();
    if (reportIntervalSeconds != null) {
        elements.add(new ASN1Integer(TYPE_REPORT_INTERVAL_SECONDS, reportIntervalSeconds));
    }
    final CollectSupportDataLogCaptureWindow logCaptureWindow = properties.getLogCaptureWindow();
    if (logCaptureWindow != null) {
        elements.add(new ASN1Element(TYPE_LOG_CAPTURE_WINDOW, logCaptureWindow.encode().encode()));
    }
    final String comment = properties.getComment();
    if (comment != null) {
        elements.add(new ASN1OctetString(TYPE_COMMENT, comment));
    }
    final String proxyToServerAddress = properties.getProxyToServerAddress();
    if (proxyToServerAddress != null) {
        elements.add(new ASN1Sequence(TYPE_PROXY_TO_SERVER, new ASN1OctetString(proxyToServerAddress), new ASN1Integer(properties.getProxyToServerPort())));
    }
    final Integer maximumFragmentSizeBytes = properties.getMaximumFragmentSizeBytes();
    if (maximumFragmentSizeBytes != null) {
        elements.add(new ASN1Integer(TYPE_MAXIMUM_FRAGMENT_SIZE_BYTES, maximumFragmentSizeBytes));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Integer(com.unboundid.asn1.ASN1Integer) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) ASN1Integer(com.unboundid.asn1.ASN1Integer) CollectSupportDataSecurityLevel(com.unboundid.ldap.sdk.unboundidds.tasks.CollectSupportDataSecurityLevel) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) LDAPException(com.unboundid.ldap.sdk.LDAPException) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 54 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class SoftDeleteRequestControl method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value of a soft delete request control.
 *
 * @param  returnSoftDeleteResponse  Indicates whether to return a soft delete
 *                                   response control in the delete response
 *                                   to the client.
 *
 * @return  An ASN.1 octet string with an encoding suitable for use as the
 *          value of a soft delete request control, or {@code null} if no
 *          value is needed for the control.
 */
@Nullable()
private static ASN1OctetString encodeValue(final boolean returnSoftDeleteResponse) {
    if (returnSoftDeleteResponse) {
        return null;
    }
    final ArrayList<ASN1Element> elements = new ArrayList<>(1);
    elements.add(new ASN1Boolean(TYPE_RETURN_SOFT_DELETE_RESPONSE, false));
    return new ASN1OctetString(new ASN1Sequence(elements).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) Nullable(com.unboundid.util.Nullable)

Example 55 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.

the class PasswordQualityRequirementValidationResult method encode.

/**
 * Encodes this password quality requirement validation result object to an
 * ASN.1 element.
 *
 * @return  The ASN.1 element that provides an encoded representation of this
 *          object.
 */
@NotNull()
public ASN1Element encode() {
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(passwordRequirement.encode());
    elements.add(new ASN1Boolean(requirementSatisfied));
    if (additionalInfo != null) {
        elements.add(new ASN1OctetString(TYPE_ADDITIONAL_INFO, additionalInfo));
    }
    return new ASN1Sequence(elements);
}
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) NotNull(com.unboundid.util.NotNull)

Aggregations

ASN1Boolean (com.unboundid.asn1.ASN1Boolean)51 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)51 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)51 ASN1Element (com.unboundid.asn1.ASN1Element)38 NotNull (com.unboundid.util.NotNull)32 ArrayList (java.util.ArrayList)32 ASN1Integer (com.unboundid.asn1.ASN1Integer)15 Test (org.testng.annotations.Test)14 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)12 ASN1Boolean (com.github.zhenwei.core.asn1.ASN1Boolean)5 Nullable (com.unboundid.util.Nullable)5 IOException (java.io.IOException)5 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)4 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)4 ASN1TaggedObject (com.github.zhenwei.core.asn1.ASN1TaggedObject)4 ASN1Set (com.unboundid.asn1.ASN1Set)4 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)3 ASN1Long (com.unboundid.asn1.ASN1Long)3 Control (com.unboundid.ldap.sdk.Control)3 ASN1Boolean (org.bouncycastle.asn1.ASN1Boolean)3