use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class GetAuthorizationEntryRequestControl method encodeValue.
/**
* Encodes the provided information as appropriate for use as the value of
* this control.
*
* @param includeAuthNEntry Indicates whether to include the authentication
* entry in the response.
* @param includeAuthZEntry Indicates whether to include the authorization
* entry in the response.
* @param attributes The attributes to include in the entries in the
* response. It may be empty or {@code null} to
* request all user attributes.
*
* @return An ASN.1 octet string appropriately encoded for use as the control
* value, or {@code null} if no value is needed.
*/
@Nullable()
private static ASN1OctetString encodeValue(final boolean includeAuthNEntry, final boolean includeAuthZEntry, @Nullable final List<String> attributes) {
if (includeAuthNEntry && includeAuthZEntry && ((attributes == null) || attributes.isEmpty())) {
return null;
}
final ArrayList<ASN1Element> elements = new ArrayList<>(3);
if (!includeAuthNEntry) {
elements.add(new ASN1Boolean(TYPE_INCLUDE_AUTHN_ENTRY, false));
}
if (!includeAuthZEntry) {
elements.add(new ASN1Boolean(TYPE_INCLUDE_AUTHZ_ENTRY, false));
}
if ((attributes != null) && (!attributes.isEmpty())) {
final ArrayList<ASN1Element> attrElements = new ArrayList<>(attributes.size());
for (final String s : attributes) {
attrElements.add(new ASN1OctetString(s));
}
elements.add(new ASN1Sequence(TYPE_ATTRIBUTES, attrElements));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class GetAuthorizationEntryResponseControl method encodeValue.
/**
* Encodes the provided information appropriately for use as the value of this
* control.
*
* @param isAuthenticated Indicates whether the client is authenticated.
* @param identitiesMatch Indicates whether the authentication identity is
* the same as the authorization identity.
* @param authNID The string that may be used to reference the
* authentication identity. It may be {@code null}
* if information about the authentication identity
* is not to be included, or if the identifier should
* be derived from the DN.
* @param authNEntry The entry for the authentication identity. It may
* be {@code null} if the information about the
* authentication identity is not to be included.
* @param authZID The string that may be used to reference the
* authorization identity. It may be {@code null}
* if information about the authentication identity
* is not to be included, if the identifier should
* be derived from the DN, or if the authentication
* and authorization identities are the same.
* @param authZEntry The entry for the authentication identity. It may
* be {@code null} if the information about the
* authentication identity is not to be included, or
* if the authentication and authorization identities
* are the same.
*
* @return The ASN.1 octet string suitable for use as the control value.
*/
@NotNull()
private static ASN1OctetString encodeValue(final boolean isAuthenticated, final boolean identitiesMatch, @Nullable final String authNID, @Nullable final ReadOnlyEntry authNEntry, @Nullable final String authZID, @Nullable final ReadOnlyEntry authZEntry) {
final ArrayList<ASN1Element> elements = new ArrayList<>(4);
elements.add(new ASN1Boolean(TYPE_IS_AUTHENTICATED, isAuthenticated));
elements.add(new ASN1Boolean(TYPE_IDENTITIES_MATCH, identitiesMatch));
if (authNEntry != null) {
elements.add(encodeAuthEntry(TYPE_AUTHN_ENTRY, authNID, authNEntry));
}
if (authZEntry != null) {
elements.add(encodeAuthEntry(TYPE_AUTHZ_ENTRY, authZID, authZEntry));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class AccountUsableResponseControl method encodeValue.
/**
* Creates an ASN.1 octet string that may be used of the value of an account
* usable response control if the account is not usable.
*
* @param isInactive Indicates whether the user account has been
* inactivated.
* @param mustChangePassword Indicates whether the user is required to
* change his/her password before any other
* operations will be allowed.
* @param passwordIsExpired Indicates whether the user's password has
* expired.
* @param remainingGraceLogins The number of remaining grace logins for the
* user.
* @param secondsUntilUnlock The length of time in seconds until the
* user's account will be automatically
* unlocked.
*
* @return The ASN.1 octet string that may be used as the control value.
*/
@NotNull()
private static ASN1OctetString encodeValue(final boolean isInactive, final boolean mustChangePassword, final boolean passwordIsExpired, final int remainingGraceLogins, final int secondsUntilUnlock) {
final ArrayList<ASN1Element> elements = new ArrayList<>(5);
if (isInactive) {
elements.add(new ASN1Boolean(TYPE_IS_INACTIVE, true));
}
if (mustChangePassword) {
elements.add(new ASN1Boolean(TYPE_MUST_CHANGE, true));
}
if (passwordIsExpired) {
elements.add(new ASN1Boolean(TYPE_IS_EXPIRED, true));
}
if (remainingGraceLogins >= 0) {
elements.add(new ASN1Integer(TYPE_REMAINING_GRACE_LOGINS, remainingGraceLogins));
}
if (secondsUntilUnlock >= 0) {
elements.add(new ASN1Integer(TYPE_SECONDS_UNTIL_UNLOCK, secondsUntilUnlock));
}
final ASN1Sequence valueSequence = new ASN1Sequence(TYPE_MORE_INFO, elements);
return new ASN1OctetString(valueSequence.encode());
}
use of com.github.zhenwei.core.asn1.ASN1Boolean in project ldapsdk by pingidentity.
the class InteractiveTransactionSpecificationResponseControl method encodeValue.
/**
* Encodes the provided information into an ASN.1 octet string suitable for
* use as the value of this control.
*
* @param transactionValid Indicates whether the associated transaction is
* still valid.
* @param baseDNs The set of base DNs that may be targeted over the
* course of the transaction. It may be
* {@code null} if there are no restrictions or the
* set of restrictions has not changed since the
* last response.
*
* @return The ASN1 octet string that may be used as the control value.
*/
@NotNull()
private static ASN1OctetString encodeValue(final boolean transactionValid, @Nullable final List<String> baseDNs) {
final ASN1Element[] elements;
if (baseDNs == null) {
elements = new ASN1Element[] { new ASN1Boolean(TYPE_TXN_VALID, transactionValid) };
} else {
final ASN1Element[] baseDNElements = new ASN1Element[baseDNs.size()];
for (int i = 0; i < baseDNElements.length; i++) {
baseDNElements[i] = new ASN1OctetString(baseDNs.get(i));
}
elements = new ASN1Element[] { new ASN1Boolean(TYPE_TXN_VALID, transactionValid), new ASN1Sequence(TYPE_BASE_DNS, baseDNElements) };
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of com.github.zhenwei.core.asn1.ASN1Boolean 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());
}
Aggregations