Search in sources :

Example 6 with ASN1Boolean

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

the class UnboundIDExternallyProcessedAuthenticationBindRequest method getEncodedCredentials.

/**
 * Retrieves an encoded representation of the SASL credentials for this bind
 * request.
 *
 * @return  An encoded representation of the SASL credentials for this bind
 *          request.
 */
@NotNull()
public ASN1OctetString getEncodedCredentials() {
    if (encodedCredentials == null) {
        final ArrayList<ASN1Element> credElements = new ArrayList<>(8);
        credElements.add(new ASN1OctetString(TYPE_AUTHENTICATION_ID, authenticationID));
        credElements.add(new ASN1OctetString(TYPE_EXTERNAL_MECHANISM_NAME, externalMechanismName));
        credElements.add(new ASN1Boolean(TYPE_EXTERNAL_AUTH_WAS_SUCCESSFUL, externalAuthWasSuccessful));
        if (externalAuthFailureReason != null) {
            credElements.add(new ASN1OctetString(TYPE_EXTERNAL_AUTH_FAILURE_REASON, externalAuthFailureReason));
        }
        if (!externalAuthWasPasswordBased) {
            credElements.add(new ASN1Boolean(TYPE_EXTERNAL_AUTH_WAS_PASSWORD_BASED, false));
        }
        if (externalAuthWasSecure) {
            credElements.add(new ASN1Boolean(TYPE_EXTERNAL_AUTH_WAS_SECURE, true));
        }
        if (endClientIPAddress != null) {
            credElements.add(new ASN1OctetString(TYPE_END_CLIENT_IP_ADDRESS, endClientIPAddress));
        }
        if (!additionalAccessLogProperties.isEmpty()) {
            final ArrayList<ASN1Element> logElements = new ArrayList<>(additionalAccessLogProperties.size());
            for (final Map.Entry<String, String> e : additionalAccessLogProperties.entrySet()) {
                logElements.add(new ASN1Sequence(new ASN1OctetString(e.getKey()), new ASN1OctetString(e.getValue())));
            }
            credElements.add(new ASN1Sequence(TYPE_ADDITIONAL_ACCESS_LOG_PROPERTIES, logElements));
        }
        final ASN1Sequence credSequence = new ASN1Sequence(credElements);
        encodedCredentials = new ASN1OctetString(credSequence.encode());
    }
    return encodedCredentials;
}
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) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NotNull(com.unboundid.util.NotNull)

Example 7 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean 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 8 with ASN1Boolean

use of com.github.zhenwei.core.asn1.ASN1Boolean 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 9 with ASN1Boolean

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

the class InteractiveTransactionSpecificationRequestControl method encodeValue.

/**
 * Encodes the provided information into an ASN.1 octet string suitable for
 * use as the value of this control.
 *
 * @param  transactionID   The transaction ID for the associated transaction,
 *                         as obtained from the start interactive transaction
 *                         extended operation.  It must not be {@code null}.
 * @param  abortOnFailure  Indicates whether the transaction should be aborted
 *                         if the associated operation does not complete
 *                         successfully.
 * @param  writeLock       Indicates whether the server should attempt to
 *                         obtain a write lock on the target entry.  This
 *                         should only be {@code false} if the associated
 *                         operation is a search or compare and it is known
 *                         that the target entry will not be updated later in
 *                         the transaction.
 *
 * @return  The ASN.1 octet string containing the encoded value for this
 *          control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString transactionID, final boolean abortOnFailure, final boolean writeLock) {
    Validator.ensureNotNull(transactionID);
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(new ASN1OctetString(TYPE_TXN_ID, transactionID.getValue()));
    if (abortOnFailure) {
        elements.add(new ASN1Boolean(TYPE_ABORT_ON_FAILURE, abortOnFailure));
    }
    if (!writeLock) {
        elements.add(new ASN1Boolean(TYPE_WRITE_LOCK, writeLock));
    }
    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 10 with ASN1Boolean

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

the class PersistentSearchRequestControl method encodeValue.

/**
 * Encodes the provided information into an octet string that can be used as
 * the value for this control.
 *
 * @param  changeTypes  The set of change types for which to register.  It
 *                      must not be {@code null} or empty.
 * @param  changesOnly  Indicates whether the search should only return search
 *                      result entries for changes made to entries matching
 *                      the search criteria, or if existing matching entries
 *                      in the server should be returned as well.
 * @param  returnECs    Indicates whether the search result entries returned
 *                      as part of this persistent search should include the
 *                      entry change notification control.
 *
 * @return  An ASN.1 octet string that can be used as the value for this
 *          control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final Set<PersistentSearchChangeType> changeTypes, final boolean changesOnly, final boolean returnECs) {
    Validator.ensureNotNull(changeTypes);
    Validator.ensureFalse(changeTypes.isEmpty(), "PersistentSearchRequestControl.changeTypes must not be empty.");
    final ASN1Element[] elements = { new ASN1Integer(PersistentSearchChangeType.encodeChangeTypes(changeTypes)), new ASN1Boolean(changesOnly), new ASN1Boolean(returnECs) };
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Integer(com.unboundid.asn1.ASN1Integer) 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