Search in sources :

Example 51 with ASN1Sequence

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

the class PasswordValidationDetailsResponseControl method encodeValue.

/**
 * Encodes the provided information to an ASN.1 element suitable for use as
 * the control value.
 *
 * @param  responseType            The response type for this password
 *                                 validation details response control.  This
 *                                 must not be {@code null}.
 * @param  validationResults       A list of the results obtained when
 *                                 validating the password against the
 *                                 password quality requirements.  This must
 *                                 be {@code null} or empty if the
 *                                 {@code responseType} element has a value
 *                                 other than {@code VALIDATION_DETAILS}.
 * @param  missingCurrentPassword  Indicates whether the associated operation
 *                                 is a self change that failed (or would have
 *                                 failed if not for additional validation
 *                                 failures) because the user did not provide
 *                                 his/her current password as required.
 * @param  mustChangePassword      Indicates whether the associated operation
 *                                 is an add or administrative reset that will
 *                                 require the user to change his/her password
 *                                 immediately after authenticating before
 *                                 allowing them to perform any other
 *                                 operation in the server.
 * @param  secondsUntilExpiration  The maximum length of time, in seconds,
 *                                 that the newly-set password will be
 *                                 considered valid.  This may be {@code null}
 *                                 if the new password will be considered
 *                                 valid indefinitely.
 *
 * @return  The encoded control value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final PasswordValidationDetailsResponseType responseType, @Nullable final Collection<PasswordQualityRequirementValidationResult> validationResults, final boolean missingCurrentPassword, final boolean mustChangePassword, @Nullable final Integer secondsUntilExpiration) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(4);
    switch(responseType) {
        case VALIDATION_DETAILS:
            if (validationResults == null) {
                elements.add(new ASN1Sequence(responseType.getBERType()));
            } else {
                final ArrayList<ASN1Element> resultElements = new ArrayList<>(validationResults.size());
                for (final PasswordQualityRequirementValidationResult r : validationResults) {
                    resultElements.add(r.encode());
                }
                elements.add(new ASN1Sequence(responseType.getBERType(), resultElements));
            }
            break;
        case NO_PASSWORD_PROVIDED:
        case MULTIPLE_PASSWORDS_PROVIDED:
        case NO_VALIDATION_ATTEMPTED:
            elements.add(new ASN1Null(responseType.getBERType()));
            break;
    }
    if (missingCurrentPassword) {
        elements.add(new ASN1Boolean(TYPE_MISSING_CURRENT_PASSWORD, missingCurrentPassword));
    }
    if (mustChangePassword) {
        elements.add(new ASN1Boolean(TYPE_MUST_CHANGE_PW, mustChangePassword));
    }
    if (secondsUntilExpiration != null) {
        elements.add(new ASN1Integer(TYPE_SECONDS_UNTIL_EXPIRATION, secondsUntilExpiration));
    }
    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) ASN1Integer(com.unboundid.asn1.ASN1Integer) ASN1Null(com.unboundid.asn1.ASN1Null) NotNull(com.unboundid.util.NotNull)

Example 52 with ASN1Sequence

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

the class AssuredReplicationResponseControl method encodeValue.

/**
 * Encodes the provided information to an ASN.1 octet string suitable for
 * use as an assured replication response control value.
 *
 * @param  localLevel                The local assurance level selected by the
 *                                   server for the associated operation.  It
 *                                   may be {@code null} if this is not
 *                                   available.
 * @param  localAssuranceSatisfied   Indicates whether the desired local level
 *                                   of assurance is known to have been
 *                                   satisfied.
 * @param  localAssuranceMessage     An optional message providing additional
 *                                   information about local assurance
 *                                   processing.  This may be {@code null} if
 *                                   no additional message is needed.
 * @param  remoteLevel               The remote assurance level selected by
 *                                   the server for the associated operation.
 *                                   It may be {@code null} if this is not
 *                                   available.
 * @param  remoteAssuranceSatisfied  Indicates whether the desired remote
 *                                   level of assurance is known to have been
 *                                   satisfied.
 * @param  remoteAssuranceMessage    An optional message providing additional
 *                                   information about remote assurance
 *                                   processing.  This may be {@code null} if
 *                                   no additional message is needed.
 * @param  csn                       The change sequence number (CSN) that has
 *                                   been assigned to the associated
 *                                   operation.  It may be {@code null} if no
 *                                   CSN is available.
 * @param  serverResults             The set of individual results from the
 *                                   local and/or remote replication servers
 *                                   and/or directory servers used in
 *                                   assurance processing.  This may be
 *                                   {@code null} or empty if no server
 *                                   results are available.
 *
 * @return  The ASN.1 octet string containing the encoded value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@Nullable final AssuredReplicationLocalLevel localLevel, final boolean localAssuranceSatisfied, @Nullable final String localAssuranceMessage, @Nullable final AssuredReplicationRemoteLevel remoteLevel, final boolean remoteAssuranceSatisfied, @Nullable final String remoteAssuranceMessage, @Nullable final String csn, @Nullable final Collection<AssuredReplicationServerResult> serverResults) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(8);
    if (localLevel != null) {
        elements.add(new ASN1Enumerated(TYPE_LOCAL_LEVEL, localLevel.intValue()));
    }
    elements.add(new ASN1Boolean(TYPE_LOCAL_SATISFIED, localAssuranceSatisfied));
    if (localAssuranceMessage != null) {
        elements.add(new ASN1OctetString(TYPE_LOCAL_MESSAGE, localAssuranceMessage));
    }
    if (remoteLevel != null) {
        elements.add(new ASN1Enumerated(TYPE_REMOTE_LEVEL, remoteLevel.intValue()));
    }
    elements.add(new ASN1Boolean(TYPE_REMOTE_SATISFIED, remoteAssuranceSatisfied));
    if (remoteAssuranceMessage != null) {
        elements.add(new ASN1OctetString(TYPE_REMOTE_MESSAGE, remoteAssuranceMessage));
    }
    if (csn != null) {
        elements.add(new ASN1OctetString(TYPE_CSN, csn));
    }
    if ((serverResults != null) && (!serverResults.isEmpty())) {
        final ArrayList<ASN1Element> srElements = new ArrayList<>(serverResults.size());
        for (final AssuredReplicationServerResult r : serverResults) {
            srElements.add(r.encode());
        }
        elements.add(new ASN1Sequence(TYPE_SERVER_RESULTS, srElements));
    }
    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) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 53 with ASN1Sequence

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

the class AssuredReplicationServerResult method encode.

/**
 * Encodes this assured replication server result to an ASN.1 element suitable
 * for use in a {@link AssuredReplicationResponseControl}.
 *
 * @return  The encoded representation of this assured replication server
 *          result.
 */
@NotNull()
ASN1Element encode() {
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(new ASN1Enumerated(TYPE_RESULT_CODE, resultCode.intValue()));
    if (replicationServerID != null) {
        elements.add(new ASN1Integer(TYPE_SERVER_ID, replicationServerID));
    }
    if (replicaID != null) {
        elements.add(new ASN1Integer(TYPE_REPLICA_ID, replicaID));
    }
    return new ASN1Sequence(elements);
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Integer(com.unboundid.asn1.ASN1Integer) NotNull(com.unboundid.util.NotNull)

Example 54 with ASN1Sequence

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

the class GetEffectiveRightsRequestControl method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value of this control.
 *
 * @param  authzID     The authorization ID of the user for whom the effective
 *                     rights should be calculated.  It must not be
 *                     {@code null}.
 * @param  attributes  The set of attributes for which to calculate the
 *                     effective rights.
 *
 * @return  An ASN.1 octet string containing the encoded control value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String authzID, @Nullable final String[] attributes) {
    Validator.ensureNotNull(authzID);
    final ASN1Element[] elements;
    if ((attributes == null) || (attributes.length == 0)) {
        elements = new ASN1Element[] { new ASN1OctetString(authzID), new ASN1Sequence() };
    } else {
        final ASN1Element[] attrElements = new ASN1Element[attributes.length];
        for (int i = 0; i < attributes.length; i++) {
            attrElements[i] = new ASN1OctetString(attributes[i]);
        }
        elements = new ASN1Element[] { new ASN1OctetString(authzID), new ASN1Sequence(attrElements) };
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) NotNull(com.unboundid.util.NotNull)

Example 55 with ASN1Sequence

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

the class OperationPurposeRequestControl method encodeValue.

/**
 * Encodes the provided information into a form suitable for use as the value
 * of this control.
 *
 * @param  applicationName     The name of the application generating the
 *                             associated request.  It may be {@code null} if
 *                             this should not be included in the control.
 * @param  applicationVersion  Information about the version of the
 *                             application generating the associated request.
 *                             It may be {@code null} if this should not be
 *                             included in the control.
 * @param  codeLocation        Information about the location in the
 *                             application code in which the associated
 *                             request is generated (e.g., the class and/or
 *                             method name, or any other useful identifier).
 *                             It may be {@code null} if this should not be
 *                             included in the control.
 * @param  requestPurpose      A string identifying the purpose of the
 *                             associated request.  It may be {@code null} if
 *                             this should not be included in the control.
 *
 * @return  The encoded value for this control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@Nullable final String applicationName, @Nullable final String applicationVersion, @Nullable final String codeLocation, @Nullable final String requestPurpose) {
    Validator.ensureFalse((applicationName == null) && (applicationVersion == null) && (codeLocation == null) && (requestPurpose == null));
    final ArrayList<ASN1Element> elements = new ArrayList<>(4);
    if (applicationName != null) {
        elements.add(new ASN1OctetString(TYPE_APP_NAME, applicationName));
    }
    if (applicationVersion != null) {
        elements.add(new ASN1OctetString(TYPE_APP_VERSION, applicationVersion));
    }
    if (codeLocation != null) {
        elements.add(new ASN1OctetString(TYPE_CODE_LOCATION, codeLocation));
    }
    if (requestPurpose != null) {
        elements.add(new ASN1OctetString(TYPE_REQUEST_PURPOSE, requestPurpose));
    }
    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) NotNull(com.unboundid.util.NotNull)

Aggregations

ASN1Sequence (com.unboundid.asn1.ASN1Sequence)455 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)397 Test (org.testng.annotations.Test)311 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)297 ASN1Element (com.unboundid.asn1.ASN1Element)231 ArrayList (java.util.ArrayList)184 IOException (java.io.IOException)141 NotNull (com.unboundid.util.NotNull)116 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)95 ASN1Integer (com.unboundid.asn1.ASN1Integer)94 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)76 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)73 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)69 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)64 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)57 Enumeration (java.util.Enumeration)54 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)53 X509Certificate (java.security.cert.X509Certificate)53 BigInteger (java.math.BigInteger)50