use of com.unboundid.asn1.ASN1Long 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());
}
use of com.unboundid.asn1.ASN1Long in project ldapsdk by pingidentity.
the class GetChangelogBatchExtendedRequest method encodeValue.
/**
* Encodes the value for this extended request using the provided information.
*
* @param startingPoint An object which indicates the
* starting point for the batch of
* changes to retrieve. It must not
* be {@code null}.
* @param maxChanges The maximum number of changes that
* should be retrieved before the
* server should return the
* corresponding extended result. A
* value less than or equal to zero
* may be used to indicate that the
* server should not return any
* entries but should just return a
* result containing a token which
* represents the starting point.
* @param maxWaitTimeMillis The maximum length of time in
* milliseconds to wait for changes.
* A value less than or equal to zero
* indicates that there should not be
* any wait and the result should be
* returned as soon as all
* immediately-available changes (up
* to the specified maximum count)
* have been returned.
* @param waitForMaxChanges Indicates whether the server should
* wait for up to the maximum length
* of time for up to the maximum
* number of changes to be returned.
* If this is {@code false}, then the
* result will be returned as soon as
* any changes are available (after
* sending those changes), even if the
* number of available changes is less
* than {@code maxChanges}.
* Otherwise, the result will not be
* returned until either the maximum
* number of changes have been
* returned or the maximum wait time
* has elapsed.
* @param includeBaseDNs A list of base DNs for entries to
* include in the set of changes to be
* returned.
* @param excludeBaseDNs A list of base DNs for entries to
* exclude from the set of changes to
* be returned.
* @param changeTypes The types of changes that should be
* returned. If this is {@code null}
* or empty, then all change types
* will be included.
* @param continueOnMissingChanges Indicates whether the server should
* make a best-effort attempt to
* return changes even if the starting
* point represents a point that is
* before the first available change
* in the changelog and therefore the
* results returned may be missing
* changes.
* @param pareEntriesForUserDN The DN of a user for whom to pare
* down the contents of changelog
* entries based on the access control
* and sensitive attribute
* restrictions defined for that user.
* It may be {@code null} if changelog
* entries should not be pared down
* for any user, an empty string if
* changelog entries should be pared
* down to what is available to
* anonymous users, or a user DN to
* pare down entries for the specified
* user.
* @param changeSelectionCriteria The optional criteria to use to
* pare down the changelog entries
* that should be returned. It may be
* {@code null} if all changelog
* entries should be returned.
* @param includeSoftDeletedEntryMods Indicates whether to include
* changelog entries that represent
* changes to soft-deleted entries.
* @param includeSoftDeletedEntryDeletes Indicates whether to include
* changelog entries that represent
* deletes of soft-deleted entries.
*
* @return The value for the extended request.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ChangelogBatchStartingPoint startingPoint, final int maxChanges, final long maxWaitTimeMillis, final boolean waitForMaxChanges, @Nullable final List<String> includeBaseDNs, @Nullable final List<String> excludeBaseDNs, @Nullable final Set<ChangeType> changeTypes, final boolean continueOnMissingChanges, @Nullable final String pareEntriesForUserDN, @Nullable final ChangelogBatchChangeSelectionCriteria changeSelectionCriteria, final boolean includeSoftDeletedEntryMods, final boolean includeSoftDeletedEntryDeletes) {
Validator.ensureNotNull(startingPoint);
final ArrayList<ASN1Element> elements = new ArrayList<>(12);
elements.add(startingPoint.encode());
if (maxChanges > 0) {
elements.add(new ASN1Integer(maxChanges));
} else {
elements.add(new ASN1Integer(0));
}
if (maxWaitTimeMillis > 0L) {
elements.add(new ASN1Long(TYPE_MAX_TIME, maxWaitTimeMillis));
}
if (waitForMaxChanges) {
elements.add(new ASN1Boolean(TYPE_WAIT_FOR_MAX_CHANGES, true));
}
if ((includeBaseDNs != null) && (!includeBaseDNs.isEmpty())) {
final ArrayList<ASN1Element> l = new ArrayList<>(includeBaseDNs.size());
for (final String s : includeBaseDNs) {
l.add(new ASN1OctetString(s));
}
elements.add(new ASN1Sequence(TYPE_INCLUDE_BASE, l));
}
if ((excludeBaseDNs != null) && (!excludeBaseDNs.isEmpty())) {
final ArrayList<ASN1Element> l = new ArrayList<>(excludeBaseDNs.size());
for (final String s : excludeBaseDNs) {
l.add(new ASN1OctetString(s));
}
elements.add(new ASN1Sequence(TYPE_EXCLUDE_BASE, l));
}
if ((changeTypes != null) && (!changeTypes.isEmpty()) && (!changeTypes.equals(EnumSet.allOf(ChangeType.class)))) {
final ArrayList<ASN1Element> l = new ArrayList<>(changeTypes.size());
for (final ChangeType t : changeTypes) {
switch(t) {
case ADD:
l.add(new ASN1Enumerated(CHANGE_TYPE_ADD));
break;
case DELETE:
l.add(new ASN1Enumerated(CHANGE_TYPE_DELETE));
break;
case MODIFY:
l.add(new ASN1Enumerated(CHANGE_TYPE_MODIFY));
break;
case MODIFY_DN:
l.add(new ASN1Enumerated(CHANGE_TYPE_MODIFY_DN));
break;
}
}
elements.add(new ASN1Set(TYPE_CHANGE_TYPES, l));
}
if (continueOnMissingChanges) {
elements.add(new ASN1Boolean(TYPE_CONTINUE_ON_MISSING_CHANGES, true));
}
if (pareEntriesForUserDN != null) {
elements.add(new ASN1OctetString(TYPE_PARE_ENTRIES_FOR_USER_DN, pareEntriesForUserDN));
}
if (changeSelectionCriteria != null) {
elements.add(changeSelectionCriteria.encode());
}
if (includeSoftDeletedEntryMods) {
elements.add(new ASN1Boolean(TYPE_INCLUDE_SOFT_DELETED_ENTRY_MODS, true));
}
if (includeSoftDeletedEntryDeletes) {
elements.add(new ASN1Boolean(TYPE_INCLUDE_SOFT_DELETED_ENTRY_DELETES, true));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Aggregations