use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class GeneratedPassword method encode.
/**
* Encodes this generated password to a sequence suitable for inclusion in the
* value of a {@link GeneratePasswordExtendedResult}.
*
* @return An ASN.1 sequence containing an encoded representation of this
* generated password object.
*/
@NotNull()
public ASN1Sequence encode() {
final List<ASN1Element> elements = new ArrayList<>(3);
elements.add(password);
elements.add(new ASN1Boolean(validationAttempted));
if (!validationErrors.isEmpty()) {
final List<ASN1Element> validationErrorElements = new ArrayList<>(validationErrors.size());
for (final String error : validationErrors) {
validationErrorElements.add(new ASN1OctetString(error));
}
elements.add(new ASN1Sequence(TYPE_VALIDATION_ERRORS, validationErrorElements));
}
return new ASN1Sequence(elements);
}
use of com.github.zhenwei.core.asn1.ASN1Boolean 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());
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class GetChangelogBatchExtendedResult method encodeValue.
/**
* Encodes the provided information in a form suitable for use as the value of
* this extended result.
*
* @param resumeToken A token which may be used to resume
* retrieving changes at the point
* immediately after the last change
* returned. It may be {@code null} only
* if this result represents an error that
* prevented the operation from being
* successfully processed.
* @param moreChangesAvailable Indicates whether there may be more
* changes immediately available to
* retrieve from the server.
* @param estimatedChangesRemaining An estimate of the number of changes
* remaining to be retrieved. A value less
* than zero will be interpreted as
* "unknown".
* @param changesAlreadyPurged Indicates whether the server may have
* already purged changes after the
* starting point referenced by the
* associated request.
* @param additionalInfo A message with additional information
* about the status of the processing. It
* may be {@code null} if no additional
* message is available.
*
* @return The ASN.1 octet string to use as the result, or {@code null} if
* there should be no value.
*/
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final ASN1OctetString resumeToken, final boolean moreChangesAvailable, final int estimatedChangesRemaining, final boolean changesAlreadyPurged, @Nullable final String additionalInfo) {
final ArrayList<ASN1Element> elements = new ArrayList<>(5);
if (resumeToken != null) {
elements.add(new ASN1OctetString(TYPE_RESUME_TOKEN, resumeToken.getValue()));
}
elements.add(new ASN1Boolean(TYPE_MORE_CHANGES_AVAILABLE, moreChangesAvailable));
if (estimatedChangesRemaining >= 0) {
elements.add(new ASN1Integer(TYPE_ESTIMATED_CHANGES_REMAINING, estimatedChangesRemaining));
}
if (changesAlreadyPurged) {
elements.add(new ASN1Boolean(TYPE_CHANGES_ALREADY_PURGED, changesAlreadyPurged));
}
if (additionalInfo != null) {
elements.add(new ASN1OctetString(TYPE_ADDITIONAL_INFO, additionalInfo));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class ReplaceListenerCertificateExtendedRequest method encodeValue.
/**
* Encodes the provided information into an ASN.1 octet string suitable for
* use as the encoded value for a replace listener certificate extended
* request.
*
* @param keyStoreContent
* An object with information about how the server should obtain
* the new listener certificate data. It must not be
* {@code null}.
* @param keyManagerProvider
* The name of the file-based key manager provider with
* information about the key store in which the new listener
* certificate should be stored. It must not be {@code null}.
* @param trustBehavior
* An object with information about how the server should handle
* updating trust information for the new listener certificate.
* It must not be {@code null}.
* @param targetCertificateAlias
* The alias that should be used for the new listener certificate
* in the target key store. It may be {@code null} if the server
* should use a default alias.
* @param reloadHTTPConnectionHandlerCertificates
* Indicates whether to trigger a certificate reload in any
* configured HTTP connection handlers after updating the
* listener certificate information. While LDAP and JMX
* connection handlers will automatically start using the new
* listener certificate when negotiating new TLS sessions, HTTP
* connection handlers will only do so if they are explicitly
* told to reload certificate data. However, there is a chance
* that this could potentially cause issues with resuming TLS
* sessions for HTTPS clients that were negotiated before the
* listener certificate was updated.
* @param skipCertificateValidation
* Indicates whether to skip validation for the new certificate
* chain.
*
* @return An ASN.1 octet string containing the encoded request value.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final ReplaceCertificateKeyStoreContent keyStoreContent, @NotNull final String keyManagerProvider, @NotNull final ReplaceCertificateTrustBehavior trustBehavior, @Nullable final String targetCertificateAlias, final boolean reloadHTTPConnectionHandlerCertificates, final boolean skipCertificateValidation) {
Validator.ensureNotNullWithMessage(keyStoreContent, "ReplaceListenerCertificateExtendedRequest.keyStoreContent must not " + "be null.");
Validator.ensureNotNullOrEmpty(keyManagerProvider, "ReplaceListenerCertificateExtendedRequest.keyManagerProvider must " + "not be null or empty.");
Validator.ensureNotNullWithMessage(trustBehavior, "ReplaceListenerCertificateExtendedRequest.trustBehavior must not " + "be null.");
final List<ASN1Element> valueElements = new ArrayList<>(6);
valueElements.add(keyStoreContent.encode());
valueElements.add(new ASN1OctetString(TYPE_KEY_MANAGER_PROVIDER, keyManagerProvider));
valueElements.add(trustBehavior.encode());
if (targetCertificateAlias != null) {
valueElements.add(new ASN1OctetString(TYPE_TARGET_CERT_ALIAS, targetCertificateAlias));
}
if (reloadHTTPConnectionHandlerCertificates) {
valueElements.add(new ASN1Boolean(TYPE_RELOAD_HTTP_CONNECTION_HANDLER_CERTS, true));
}
if (skipCertificateValidation) {
valueElements.add(new ASN1Boolean(TYPE_SKIP_CERT_VALIDATION, true));
}
return new ASN1OctetString(new ASN1Sequence(valueElements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class StreamDirectoryValuesExtendedRequest method encodeValue.
/**
* Encodes the provided information into a form suitable for use as the value
* of this extended request.
*
* @param baseDN The base DN which indicates the portion of the
* DIT to target.
* @param scope The scope for which to return information about
* entry DNs in the specified portion of the DIT.
* This may be {@code null} if information about
* entry DNs should not be returned.
* @param relativeDNs Indicates whether DNs returned should be
* relative to the base DN rather than full DNs.
* @param attributes The names of the attributes for which to
* retrieve the values. This may be {@code null}
* or empty if only entry DNs should be retrieved.
* @param valuesPerResponse The maximum number of values to include per
* response. A value less than or equal to zero
* indicates that the server should choose an
* appropriate value.
*
* @return The ASN.1 octet string containing the encoded value to use for
* this extended request.
*/
@NotNull()
private static ASN1OctetString encodeValue(@NotNull final String baseDN, @Nullable final SearchScope scope, final boolean relativeDNs, @Nullable final List<String> attributes, final int valuesPerResponse) {
Validator.ensureNotNull(baseDN);
final ArrayList<ASN1Element> svElements = new ArrayList<>(4);
svElements.add(new ASN1OctetString(TYPE_BASE_DN, baseDN));
if (scope != null) {
final ArrayList<ASN1Element> idElements = new ArrayList<>(2);
idElements.add(new ASN1Enumerated(TYPE_SCOPE, scope.intValue()));
if (!relativeDNs) {
idElements.add(new ASN1Boolean(TYPE_RELATIVE, relativeDNs));
}
svElements.add(new ASN1Sequence(TYPE_INCLUDE_DNS, idElements));
}
if ((attributes != null) && (!attributes.isEmpty())) {
final ArrayList<ASN1Element> attrElements = new ArrayList<>(attributes.size());
for (final String s : attributes) {
attrElements.add(new ASN1OctetString(s));
}
svElements.add(new ASN1Sequence(TYPE_ATTRIBUTES, attrElements));
}
if (valuesPerResponse > 0) {
svElements.add(new ASN1Integer(TYPE_VALUES_PER_RESPONSE, valuesPerResponse));
}
return new ASN1OctetString(new ASN1Sequence(svElements).encode());
}
Aggregations