Search in sources :

Example 11 with ASN1Boolean

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

the class EndBatchedTransactionExtendedRequest method encodeValue.

/**
 * Generates the value to include in this extended request.
 *
 * @param  transactionID  The transaction ID for the transaction to commit or
 *                        abort.  It must not be {@code null}.
 * @param  commit         {@code true} if the transaction should be committed,
 *                        or {@code false} if the transaction should be
 *                        aborted.
 *
 * @return  The ASN.1 octet string containing the encoded request value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString transactionID, final boolean commit) {
    Validator.ensureNotNull(transactionID);
    final ASN1Element[] valueElements;
    if (commit) {
        valueElements = new ASN1Element[] { transactionID };
    } else {
        valueElements = new ASN1Element[] { new ASN1Boolean(commit), transactionID };
    }
    return new ASN1OctetString(new ASN1Sequence(valueElements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 12 with ASN1Boolean

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

the class EndInteractiveTransactionExtendedRequest method encodeValue.

/**
 * Generates the value to include in this extended request.
 *
 * @param  transactionID  The transaction ID for the transaction to commit or
 *                        abort.  It must not be {@code null}.
 * @param  commit         {@code true} if the transaction should be committed,
 *                        or {@code false} if the transaction should be
 *                        aborted.
 *
 * @return  The ASN.1 octet string containing the encoded request value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString transactionID, final boolean commit) {
    Validator.ensureNotNull(transactionID);
    final ASN1Element[] valueElements;
    if (commit) {
        valueElements = new ASN1Element[] { new ASN1OctetString(TYPE_TXN_ID, transactionID.getValue()) };
    } else {
        valueElements = new ASN1Element[] { new ASN1OctetString(TYPE_TXN_ID, transactionID.getValue()), new ASN1Boolean(TYPE_COMMIT, commit) };
    }
    return new ASN1OctetString(new ASN1Sequence(valueElements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 13 with ASN1Boolean

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

the class UniquenessRequestControl method encodeValue.

/**
 * Encodes the provided information into an octet string that is suitable for
 * use as the value of this control.
 *
 * @param  uniquenessID  A value that will be used to correlate this request
 *                       control with its corresponding response control.  It
 *                       must not be {@code null}.
 * @param  properties    The set of properties for this control.  It must not
 *                       be {@code null}.
 *
 * @return  The encoded value that was created.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String uniquenessID, @NotNull final UniquenessRequestControlProperties properties) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(10);
    elements.add(new ASN1OctetString(TYPE_UNIQUENESS_ID, uniquenessID));
    final Set<String> attributeTypes = properties.getAttributeTypes();
    if (!attributeTypes.isEmpty()) {
        final ArrayList<ASN1Element> attributeTypeElements = new ArrayList<>(attributeTypes.size());
        for (final String attributeType : attributeTypes) {
            attributeTypeElements.add(new ASN1OctetString(attributeType));
        }
        elements.add(new ASN1Set(TYPE_ATTRIBUTE_TYPES, attributeTypeElements));
    }
    final UniquenessMultipleAttributeBehavior multipleAttributeBehavior = properties.getMultipleAttributeBehavior();
    if (multipleAttributeBehavior != UniquenessMultipleAttributeBehavior.UNIQUE_WITHIN_EACH_ATTRIBUTE) {
        elements.add(new ASN1Enumerated(TYPE_MULTIPLE_ATTRIBUTE_BEHAVIOR, multipleAttributeBehavior.intValue()));
    }
    final String baseDN = properties.getBaseDN();
    if (baseDN != null) {
        elements.add(new ASN1OctetString(TYPE_BASE_DN, baseDN));
    }
    final Filter filter = properties.getFilter();
    if (filter != null) {
        elements.add(new ASN1Element(TYPE_FILTER, filter.encode().encode()));
    }
    if (properties.preventConflictsWithSoftDeletedEntries()) {
        elements.add(new ASN1Boolean(TYPE_PREVENT_CONFLICTS_WITH_SOFT_DELETED_ENTRIES, true));
    }
    final UniquenessValidationLevel preCommitValidationLevel = properties.getPreCommitValidationLevel();
    if (preCommitValidationLevel != UniquenessValidationLevel.ALL_SUBTREE_VIEWS) {
        elements.add(new ASN1Enumerated(TYPE_PRE_COMMIT_VALIDATION_LEVEL, preCommitValidationLevel.intValue()));
    }
    final UniquenessValidationLevel postCommitValidationLevel = properties.getPostCommitValidationLevel();
    if (postCommitValidationLevel != UniquenessValidationLevel.ALL_SUBTREE_VIEWS) {
        elements.add(new ASN1Enumerated(TYPE_POST_COMMIT_VALIDATION_LEVEL, postCommitValidationLevel.intValue()));
    }
    if (!properties.alertOnPostCommitConflictDetection()) {
        elements.add(new ASN1Boolean(TYPE_ALERT_ON_POST_VALIDATION_CONFLICT_DETECTION, false));
    }
    if (properties.createConflictPreventionDetailsEntry()) {
        elements.add(new ASN1Boolean(TYPE_CREATE_CONFLICT_PREVENTION_DETAILS_ENTRY, true));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) Filter(com.unboundid.ldap.sdk.Filter) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Example 14 with ASN1Boolean

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

the class RouteToServerRequestControl method encodeValue.

/**
 * Encodes the provided information into a form suitable for use as the value
 * of this control.
 *
 * @param  serverID                 The server ID for the server to which the
 *                                  request should be sent.  It must not be
 *                                  {@code null}.
 * @param  allowAlternateServer     Indicates whether the request may be
 *                                  routed to an alternate server in the
 *                                  event that the target server is not known,
 *                                  is not available, or is otherwise unsuited
 *                                  for use.  If this has a value of
 *                                  {@code false} and the target server is
 *                                  unknown or unavailable, then the
 *                                  associated operation will be rejected.  If
 *                                  this has a value of {@code true}, then an
 *                                  intermediate Directory Proxy Server may be
 *                                  allowed to route the request to a
 *                                  different server if deemed desirable or
 *                                  necessary.
 * @param  preferLocalServer        Indicates whether the associated request
 *                                  may be routed to an alternate server if
 *                                  the target server is in a remote location
 *                                  and a suitable alternate server is
 *                                  available locally.  This will only be used
 *                                  if {@code allowAlternateServer} is
 *                                  {@code true}.
 * @param  preferNonDegradedServer  Indicates whether the associated request
 *                                  may be routed to an alternate server if
 *                                  the target server is in a degraded state
 *                                  and an alternate server is not in a
 *                                  degraded state.  This will only be used if
 *                                  {@code allowAlternateServer} is
 *                                  {@code true}.
 *
 * @return  The encoded value for this control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String serverID, final boolean allowAlternateServer, final boolean preferLocalServer, final boolean preferNonDegradedServer) {
    Validator.ensureNotNull(serverID);
    final ArrayList<ASN1Element> elements = new ArrayList<>(4);
    elements.add(new ASN1OctetString(TYPE_SERVER_ID, serverID));
    elements.add(new ASN1Boolean(TYPE_ALLOW_ALTERNATE_SERVER, allowAlternateServer));
    if (allowAlternateServer && (!preferLocalServer)) {
        elements.add(new ASN1Boolean(TYPE_PREFER_LOCAL_SERVER, false));
    }
    if (allowAlternateServer && (!preferNonDegradedServer)) {
        elements.add(new ASN1Boolean(TYPE_PREFER_NON_DEGRADED_SERVER, 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) NotNull(com.unboundid.util.NotNull)

Example 15 with ASN1Boolean

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

the class UnboundIDExternallyProcessedAuthenticationBindRequestTestCase method testDecodeValidMinimalCredentials.

/**
 * Tests the behavior when trying to decode an ASN.1 element that represents
 * a valid set of encoded credentials with a minimal encoding.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDecodeValidMinimalCredentials() throws Exception {
    final ASN1Sequence credSequence = new ASN1Sequence(new ASN1OctetString((byte) 0x80, "dn:uid=test.user,ou=People,dc=example,dc=com"), new ASN1OctetString((byte) 0x81, "TEST"), new ASN1Boolean((byte) 0x82, true));
    final UnboundIDExternallyProcessedAuthenticationBindRequest r = UnboundIDExternallyProcessedAuthenticationBindRequest.decodeSASLCredentials(new ASN1OctetString(credSequence.encode()));
    assertNotNull(r);
    assertNotNull(r.getSASLMechanismName());
    assertEquals(r.getSASLMechanismName(), "UNBOUNDID-EXTERNALLY-PROCESSED-AUTHENTICATION");
    assertNotNull(r.getAuthenticationID());
    assertEquals(r.getAuthenticationID(), "dn:uid=test.user,ou=People,dc=example,dc=com");
    assertNotNull(r.getExternalMechanismName());
    assertEquals(r.getExternalMechanismName(), "TEST");
    assertTrue(r.externalAuthenticationWasSuccessful());
    assertNull(r.getExternalAuthenticationFailureReason());
    assertTrue(r.externalAuthenticationWasPasswordBased());
    assertFalse(r.externalAuthenticationWasSecure());
    assertNull(r.getEndClientIPAddress());
    assertNotNull(r.getAdditionalAccessLogProperties());
    assertTrue(r.getAdditionalAccessLogProperties().isEmpty());
    assertNotNull(r.getControls());
    assertEquals(r.getControls().length, 0);
    assertNotNull(r.toString());
    final ArrayList<String> toCodeLineList = new ArrayList<String>(10);
    r.toCode(toCodeLineList, "testMinimalConstructorSuccess", 0, false);
    assertFalse(toCodeLineList.isEmpty());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

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