@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class PasswordExpiredControl extends Control implements DecodeableControl
// Send a simple bind request to the directory server. BindRequest bindRequest = new SimpleBindRequest("uid=test.user,ou=People,dc=example,dc=com", "password"); BindResult bindResult; boolean bindSuccessful; boolean passwordExpired; boolean passwordAboutToExpire; try { bindResult = connection.bind(bindRequest); // If we got here, the bind was successful and we know the password was // not expired. However, we shouldn't ignore the result because the // password might be about to expire. To determine whether that is the // case, we should see if the bind result included a password expiring // control. bindSuccessful = true; passwordExpired = false; PasswordExpiringControl expiringControl = PasswordExpiringControl.get(bindResult); if (expiringControl != null) { passwordAboutToExpire = true; int secondsToExpiration = expiringControl.getSecondsUntilExpiration(); } else { passwordAboutToExpire = false; } } catch (LDAPException le) { // If we got here, then the bind failed. The failure may or may not have // been due to an expired password. To determine that, we should see if // the bind result included a password expired control. bindSuccessful = false; passwordAboutToExpire = false; bindResult = new BindResult(le.toLDAPResult()); ResultCode resultCode = le.getResultCode(); String errorMessageFromServer = le.getDiagnosticMessage(); PasswordExpiredControl expiredControl = PasswordExpiredControl.get(le); if (expiredControl != null) { passwordExpired = true; } else { passwordExpired = false; } }
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PASSWORD_EXPIRED_OID
The OID (2.16.840.1.113730.3.4.4) for the password expired response
control.
|
Constructor and Description |
---|
PasswordExpiredControl()
Creates a new password expired control.
|
PasswordExpiredControl(java.lang.String oid,
boolean isCritical,
ASN1OctetString value)
Creates a new password expired control with the provided information.
|
Modifier and Type | Method and Description |
---|---|
PasswordExpiredControl |
decodeControl(java.lang.String oid,
boolean isCritical,
ASN1OctetString value)
Creates a new instance of this decodeable control from the provided
information.
|
static PasswordExpiredControl |
decodeJSONControl(JSONObject controlObject,
boolean strict)
Attempts to decode the provided object as a JSON representation of a
password expired control.
|
static PasswordExpiredControl |
get(LDAPException exception)
Extracts a password expired control from the provided exception.
|
static PasswordExpiredControl |
get(LDAPResult result)
Extracts a password expired control from the provided result.
|
java.lang.String |
getControlName()
Retrieves the user-friendly name for this control, if available.
|
JSONObject |
toJSONControl()
Retrieves a representation of this password expired control as a JSON
object.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP control to the provided
buffer.
|
decode, decode, decodeControls, decodeJSONControl, deregisterDecodeableControl, encode, encodeControls, equals, getOID, getValue, hashCode, hasValue, isCritical, readFrom, registerDecodeableControl, registerDecodeableControl, toString, writeTo
@NotNull public static final java.lang.String PASSWORD_EXPIRED_OID
public PasswordExpiredControl()
public PasswordExpiredControl(@NotNull java.lang.String oid, boolean isCritical, @Nullable ASN1OctetString value) throws LDAPException
oid
- The OID for the control.isCritical
- Indicates whether the control should be marked
critical.value
- The encoded value for the control. This may be
null
if no value was provided.LDAPException
- If the provided control cannot be decoded as a
password expired response control.@NotNull public PasswordExpiredControl decodeControl(@NotNull java.lang.String oid, boolean isCritical, @Nullable ASN1OctetString value) throws LDAPException
decodeControl
in interface DecodeableControl
oid
- The OID for the control.isCritical
- Indicates whether the control should be marked
critical.value
- The encoded value for the control. This may be
null
if no value was provided.LDAPException
- If the provided information cannot be decoded as a
valid instance of this decodeable control.@Nullable public static PasswordExpiredControl get(@NotNull LDAPResult result) throws LDAPException
result
- The result from which to retrieve the password expired
control.null
if the result did not contain a password expired
control.LDAPException
- If a problem is encountered while attempting to
decode the password expired control contained in
the provided result.@Nullable public static PasswordExpiredControl get(@NotNull LDAPException exception) throws LDAPException
exception
- The exception from which to retrieve the password
expired control.null
if the exception did not contain a password
expired control.LDAPException
- If a problem is encountered while attempting to
decode the password expired control contained in
the provided exception.@NotNull public java.lang.String getControlName()
getControlName
in class Control
@NotNull public JSONObject toJSONControl()
value-base64
nor value-json
fields may be present):
oid
-- A mandatory string field whose value is the object
identifier for this control. For the password expired control, the OID
is "2.16.840.1.113730.3.4.4".
control-name
-- An optional string field whose value is a
human-readable name for this control. This field is only intended for
descriptive purposes, and when decoding a control, the oid
field should be used to identify the type of control.
criticality
-- A mandatory Boolean field used to indicate
whether this control is considered critical.
toJSONControl
in class Control
@NotNull public static PasswordExpiredControl decodeJSONControl(@NotNull JSONObject controlObject, boolean strict) throws LDAPException
controlObject
- The JSON object to be decoded. It must not be
null
.strict
- Indicates whether to use strict mode when decoding
the provided JSON object. If this is true
,
then this method will throw an exception if the
provided JSON object contains any unrecognized
fields. If this is false
, then unrecognized
fields will be ignored.LDAPException
- If the provided JSON object cannot be parsed as a
valid password expired control.