Search in sources :

Example 1 with ASN1Long

use of com.unboundid.asn1.ASN1Long in project ldapsdk by pingidentity.

the class GeneratePasswordResponseControl method encodeValue.

/**
 * Encodes the provided information appropriately for use as the value of this
 * control.
 *
 * @param  generatedPassword        The password generated by the server.  It
 *                                 must not be {@code null}.
 * @param  mustChangePassword      Indicates whether the user will be required
 *                                 to choose a new password the first time
 *                                 they authenticate.
 * @param  secondsUntilExpiration  The number of seconds until the new
 *                                 password will expire.  It may be
 *                                 {@code null} if the new password will not
 *                                 expire.
 *
 * @return  The ASN.1 octet string suitable for use as the control value.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ASN1OctetString generatedPassword, final boolean mustChangePassword, @Nullable final Long secondsUntilExpiration) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(3);
    elements.add(generatedPassword);
    elements.add(mustChangePassword ? ASN1Boolean.UNIVERSAL_BOOLEAN_TRUE_ELEMENT : ASN1Boolean.UNIVERSAL_BOOLEAN_FALSE_ELEMENT);
    if (secondsUntilExpiration != null) {
        elements.add(new ASN1Long(TYPE_SECONDS_UNTIL_EXPIRATION, secondsUntilExpiration));
    }
    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) NotNull(com.unboundid.util.NotNull)

Example 2 with ASN1Long

use of com.unboundid.asn1.ASN1Long in project ldapsdk by pingidentity.

the class DeliverSingleUseTokenExtendedRequestTestCase method testDecodeValueSequenceUnknownElement.

/**
 * Tests the behavior when trying to decode a request that has a value
 * sequence with an element that has an unknown type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeValueSequenceUnknownElement() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString("uid=test.user,dc=example,dc=com"), new ASN1OctetString("tokenID"), new ASN1Long(123456L), new ASN1OctetString((byte) 0x12, "What's this?"));
    new DeliverSingleUseTokenExtendedRequest(new ExtendedRequest("1.3.6.1.4.1.30221.2.6.49", new ASN1OctetString(valueSequence.encode())));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Long(com.unboundid.asn1.ASN1Long) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) Test(org.testng.annotations.Test)

Example 3 with ASN1Long

use of com.unboundid.asn1.ASN1Long in project ldapsdk by pingidentity.

the class EntryChangeNotificationControl method encodeValue.

/**
 * Encodes the provided information into an octet string that can be used as
 * the value for this control.
 *
 * @param  changeType    The change type for the change.  It must not be
 *                       {@code null}.
 * @param  previousDN    The previous DN of the entry, if applicable.
 * @param  changeNumber  The change number to include in this control, or
 *                       -1 if there should not be a change number.
 *
 * @return  An ASN.1 octet string that can be used as the value for this
 *          control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final PersistentSearchChangeType changeType, @Nullable final String previousDN, final long changeNumber) {
    Validator.ensureNotNull(changeType);
    final ArrayList<ASN1Element> elementList = new ArrayList<>(3);
    elementList.add(new ASN1Enumerated(changeType.intValue()));
    if (previousDN != null) {
        elementList.add(new ASN1OctetString(previousDN));
    }
    if (changeNumber > 0) {
        elementList.add(new ASN1Long(changeNumber));
    }
    return new ASN1OctetString(new ASN1Sequence(elementList).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Long(com.unboundid.asn1.ASN1Long) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) NotNull(com.unboundid.util.NotNull)

Example 4 with ASN1Long

use of com.unboundid.asn1.ASN1Long in project ldapsdk by pingidentity.

the class GetUserResourceLimitsResponseControl method encodeValue.

/**
 * Encodes the provided information into an octet string suitable for use as
 * the value of a get user resource limits response control.
 *
 * @param  sizeLimit                   The custom size limit for the user.
 *                                     It may be less than or equal to zero
 *                                     if no size limit should be enforced for
 *                                     the user.  It may be {@code null} if
 *                                     there is no custom size limit or it is
 *                                     not to be included in the control.
 * @param  timeLimitSeconds            The custom time limit for the user, in
 *                                     seconds.  It may be less than or equal
 *                                     to zero if no time limit should be
 *                                     enforced for the user.  It may be
 *                                     {@code null} if there is no custom time
 *                                     limit or it is not to be included in
 *                                     the control.
 * @param  idleTimeLimitSeconds        The custom idle time limit for the
 *                                     user, in seconds.  It may be less than
 *                                     or equal to zero if no idle time limit
 *                                     should be enforced for the user.  It
 *                                     may be {@code null} if there is no
 *                                     custom idle time limit or it is not to
 *                                     be included in the control.
 * @param  lookthroughLimit            The custom lookthrough limit for the
 *                                     user.  It may be less than or equal to
 *                                     zero if no lookthrough limit should
 *                                     be enforced for the user.  It may be
 *                                     {@code null} if there is no custom
 *                                     lookthrough limit for the user or it is
 *                                     not to be included in the control.
 * @param  equivalentAuthzUserDN       The DN of a user with equivalent
 *                                     authorization rights for use in servers
 *                                     in an entry-balancing environment in
 *                                     which the user's entry does not exist.
 * @param  clientConnectionPolicyName  The name of the client connection
 *                                     policy that has been assigned to the
 *                                     user, or {@code null} if the client
 *                                     connection policy name is not to be
 *                                     included in the control.
 * @param  groupDNs                    The DNs of the groups in which the user
 *                                     is a member.  It may be {@code null} if
 *                                     group membership is not known, or
 *                                     empty if the user isn't a member of any
 *                                     groups.
 * @param  privilegeNames              The names of the privileges assigned to
 *                                     the user.  It may be {@code null} if
 *                                     the privilege names are not known, or
 *                                     empty if the  user doesn't have any
 *                                     privileges.
 * @param  otherAttributes             A set of additional attributes from the
 *                                     user's entry.  It may be {@code null}
 *                                     or empty if no additional attributes
 *                                     are needed.
 *
 * @return  The octet string which may be used as the value of a get user
 *          resource limits response control
 */
@NotNull()
private static ASN1OctetString encodeValue(@Nullable final Long sizeLimit, @Nullable final Long timeLimitSeconds, @Nullable final Long idleTimeLimitSeconds, @Nullable final Long lookthroughLimit, @Nullable final String equivalentAuthzUserDN, @Nullable final String clientConnectionPolicyName, @Nullable final List<String> groupDNs, @Nullable final List<String> privilegeNames, @Nullable final List<Attribute> otherAttributes) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(10);
    if (sizeLimit != null) {
        if (sizeLimit > 0L) {
            elements.add(new ASN1Long(TYPE_SIZE_LIMIT, sizeLimit));
        } else {
            elements.add(new ASN1Long(TYPE_SIZE_LIMIT, -1L));
        }
    }
    if (timeLimitSeconds != null) {
        if (timeLimitSeconds > 0L) {
            elements.add(new ASN1Long(TYPE_TIME_LIMIT, timeLimitSeconds));
        } else {
            elements.add(new ASN1Long(TYPE_TIME_LIMIT, -1L));
        }
    }
    if (idleTimeLimitSeconds != null) {
        if (idleTimeLimitSeconds > 0L) {
            elements.add(new ASN1Long(TYPE_IDLE_TIME_LIMIT, idleTimeLimitSeconds));
        } else {
            elements.add(new ASN1Long(TYPE_IDLE_TIME_LIMIT, -1L));
        }
    }
    if (lookthroughLimit != null) {
        if (lookthroughLimit > 0L) {
            elements.add(new ASN1Long(TYPE_LOOKTHROUGH_LIMIT, lookthroughLimit));
        } else {
            elements.add(new ASN1Long(TYPE_LOOKTHROUGH_LIMIT, -1L));
        }
    }
    if (equivalentAuthzUserDN != null) {
        elements.add(new ASN1OctetString(TYPE_EQUIVALENT_AUTHZ_USER_DN, equivalentAuthzUserDN));
    }
    if (clientConnectionPolicyName != null) {
        elements.add(new ASN1OctetString(TYPE_CLIENT_CONNECTION_POLICY_NAME, clientConnectionPolicyName));
    }
    if (groupDNs != null) {
        final ArrayList<ASN1Element> dnElements = new ArrayList<>(groupDNs.size());
        for (final String s : groupDNs) {
            dnElements.add(new ASN1OctetString(s));
        }
        elements.add(new ASN1Set(TYPE_GROUP_DNS, dnElements));
    }
    if (privilegeNames != null) {
        final ArrayList<ASN1Element> privElements = new ArrayList<>(privilegeNames.size());
        for (final String s : privilegeNames) {
            privElements.add(new ASN1OctetString(s));
        }
        elements.add(new ASN1Set(TYPE_PRIVILEGE_NAMES, privElements));
    }
    if ((otherAttributes != null) && (!otherAttributes.isEmpty())) {
        final ArrayList<ASN1Element> attrElements = new ArrayList<>(otherAttributes.size());
        for (final Attribute a : otherAttributes) {
            attrElements.add(a.encode());
        }
        elements.add(new ASN1Sequence(TYPE_OTHER_ATTRIBUTES, attrElements));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Long(com.unboundid.asn1.ASN1Long) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Set(com.unboundid.asn1.ASN1Set) Attribute(com.unboundid.ldap.sdk.Attribute) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Example 5 with ASN1Long

use of com.unboundid.asn1.ASN1Long in project ldapsdk by pingidentity.

the class TransactionSettingsRequestControl method encodeValue.

/**
 * Encodes the provided information into a form suitable for use as the value
 * of this ASN.1 element.
 *
 * @param  transactionName           The name to use for the transaction.  It
 *                                   may be {@code null} if no
 *                                   client-specified transaction name is
 *                                   needed.  If a transaction name is
 *                                   provided, it will be used purely for
 *                                   informational and/or troubleshooting
 *                                   purposes.
 * @param  commitDurability          The durability level that should be used
 *                                   when committing the associated
 *                                   transaction.  It may be {@code null} if
 *                                   the server-default durability level
 *                                   should be used.
 * @param  backendLockBehavior       The behavior that should be used with
 *                                   regard to acquiring an exclusive lock for
 *                                   processing in the target backend.  It may
 *                                   be {@code null} if the server-default
 *                                   backend lock behavior should be used.
 * @param  backendLockTimeoutMillis  The maximum length of time in
 *                                   milliseconds to spend attempting to
 *                                   acquire an exclusive backend lock if it
 *                                   is needed during any part of the
 *                                   processing.  A value that of zero
 *                                   indicates that no timeout should be
 *                                   enforced.  It may be {@code null} if the
 *                                   server will determine the backend lock
 *                                   timeout that should be used.
 * @param  retryAttempts             The number of times to retry the
 *                                   associated operations in a new
 *                                   transaction if the initial attempt fails.
 *                                   If this is {@code null}, then the server
 *                                   will determine the number of retry
 *                                   attempts to make.  Note that depending on
 *                                   the backend lock behavior, the server may
 *                                   make one additional retry attempt if
 *                                   necessary after acquiring an exclusive
 *                                   backend lock.
 * @param  minTxnLockTimeoutMillis   The minimum database lock timeout that
 *                                   should be used for the associated
 *                                   transaction.  If this is specified, then
 *                                   the first attempt will use this lock
 *                                   timeout, and subsequent attempts will use
 *                                   a timeout value between this and the
 *                                   maximum database lock timeout (which must
 *                                   also be specified).  If this is
 *                                   {@code null}, then the server will
 *                                   determine the database lock timeout
 *                                   settings to use.
 * @param  maxTxnLockTimeoutMillis   The maximum database lock timeout that
 *                                   should be used for the associated
 *                                   transaction.  If this is specified, then
 *                                   the minimum database lock timeout must
 *                                   also be specified, and this value must be
 *                                   greater than or equal to the minimum lock
 *                                   timeout.  If this is {@code null}, then
 *                                   the server will determine the database
 *                                   lock timeout settings to use.
 * @param  returnResponseControl     Indicates whether to return a response
 *                                   control with transaction-related
 *                                   information collected over the course of
 *                                   processing the associated operation.
 *
 * @return  The encoded value to use for the control.
 */
@NotNull()
private static ASN1OctetString encodeValue(@Nullable final String transactionName, @Nullable final TransactionSettingsCommitDurability commitDurability, @Nullable final TransactionSettingsBackendLockBehavior backendLockBehavior, @Nullable final Long backendLockTimeoutMillis, @Nullable final Integer retryAttempts, @Nullable final Long minTxnLockTimeoutMillis, @Nullable final Long maxTxnLockTimeoutMillis, final boolean returnResponseControl) {
    final ArrayList<ASN1Element> elements = new ArrayList<>(7);
    if (transactionName != null) {
        elements.add(new ASN1OctetString(TYPE_TXN_NAME, transactionName));
    }
    if (commitDurability != null) {
        elements.add(new ASN1Enumerated(TYPE_COMMIT_DURABILITY, commitDurability.intValue()));
    }
    if (backendLockBehavior != null) {
        elements.add(new ASN1Enumerated(TYPE_BACKEND_LOCK_BEHAVIOR, backendLockBehavior.intValue()));
    }
    if (backendLockTimeoutMillis != null) {
        Validator.ensureTrue((backendLockTimeoutMillis >= 0L), "If a backend lock timeout is specified, then it must be greater " + "than or equal to zero.");
        elements.add(new ASN1Long(TYPE_BACKEND_LOCK_TIMEOUT, backendLockTimeoutMillis));
    }
    if (retryAttempts != null) {
        Validator.ensureTrue((retryAttempts >= 0), "If specified, the number of retry attempts must be greater than " + "or equal to zero.");
        elements.add(new ASN1Integer(TYPE_RETRY_ATTEMPTS, retryAttempts));
    }
    if (minTxnLockTimeoutMillis != null) {
        Validator.ensureTrue((maxTxnLockTimeoutMillis != null), "If a minimum transaction lock timeout is specified, then a " + "maximum transaction lock timeout must also be specified.");
        Validator.ensureTrue((minTxnLockTimeoutMillis > 0), "If a minimum transaction lock timeout is specified, then it must " + "be greater than zero.");
        Validator.ensureTrue((maxTxnLockTimeoutMillis >= minTxnLockTimeoutMillis), "If a minimum transaction lock timeout is specified, then it must " + "be less than or equal to the minimum transaction lock " + "timeout.");
        elements.add(new ASN1Sequence(TYPE_TXN_LOCK_TIMEOUT, new ASN1Long(minTxnLockTimeoutMillis), new ASN1Long(maxTxnLockTimeoutMillis)));
    } else {
        Validator.ensureTrue((maxTxnLockTimeoutMillis == null), "If a maximum transaction lock timeout is specified, then a " + "minimum transaction lock timeout must also be specified.");
    }
    if (returnResponseControl) {
        elements.add(new ASN1Boolean(TYPE_RETURN_RESPONSE_CONTROL, 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) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Integer(com.unboundid.asn1.ASN1Integer) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) NotNull(com.unboundid.util.NotNull)

Aggregations

ASN1Long (com.unboundid.asn1.ASN1Long)7 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)7 ASN1Element (com.unboundid.asn1.ASN1Element)6 NotNull (com.unboundid.util.NotNull)6 ArrayList (java.util.ArrayList)6 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)3 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)3 ASN1Integer (com.unboundid.asn1.ASN1Integer)2 ASN1Set (com.unboundid.asn1.ASN1Set)2 Attribute (com.unboundid.ldap.sdk.Attribute)1 ChangeType (com.unboundid.ldap.sdk.ChangeType)1 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)1 Test (org.testng.annotations.Test)1