com.unboundid.ldap.sdk.extensions
Class PasswordModifyExtendedRequest

java.lang.Object
  extended by com.unboundid.ldap.sdk.LDAPRequest
      extended by com.unboundid.ldap.sdk.ExtendedRequest
          extended by com.unboundid.ldap.sdk.extensions.PasswordModifyExtendedRequest
All Implemented Interfaces:
ProtocolOp, ReadOnlyLDAPRequest, java.io.Serializable

@NotMutable
@ThreadSafety(level=NOT_THREADSAFE)
public final class PasswordModifyExtendedRequest
extends ExtendedRequest

This class provides an implementation of the LDAP password modify extended request as defined in RFC 3062. It may be used to change the password for a user in the directory, and provides the ability to specify the current password for verification. It also offers the ability to request that the server generate a new password for the user.

The elements of a password modify extended request include:

Example

The following example demonstrates the use of the password modify extended operation to change the password for user "uid=test.user,ou=People,dc=example,dc=com". Neither the current password nor a new password will be provided, so the server will generate a new password for the user.
 PasswordModifyExtendedRequest passwordModifyRequest =
      new PasswordModifyExtendedRequest(
           "uid=test.user,ou=People,dc=example,dc=com", // The user to update
           (String) null, // The current password for the user.
           (String) null); // The new password.  null = server will generate

 PasswordModifyExtendedResult passwordModifyResult;
 try
 {
   passwordModifyResult = (PasswordModifyExtendedResult)
        connection.processExtendedOperation(passwordModifyRequest);
   // This doesn't necessarily mean that the operation was successful, since
   // some kinds of extended operations return non-success results under
   // normal conditions.
 }
 catch (LDAPException le)
 {
   // For an extended operation, this generally means that a problem was
   // encountered while trying to send the request or read the result.
   passwordModifyResult = new PasswordModifyExtendedResult(
        new ExtendedResult(le));
 }

 LDAPTestUtils.assertResultCodeEquals(passwordModifyResult,
      ResultCode.SUCCESS);
 String serverGeneratedNewPassword =
      passwordModifyResult.getGeneratedPassword();
 

See Also:
Serialized Form

Field Summary
static java.lang.String PASSWORD_MODIFY_REQUEST_OID
          The OID (1.3.6.1.4.1.4203.1.11.1) for the password modify extended request.
 
Fields inherited from class com.unboundid.ldap.sdk.ExtendedRequest
TYPE_EXTENDED_REQUEST_OID, TYPE_EXTENDED_REQUEST_VALUE
 
Constructor Summary
PasswordModifyExtendedRequest(byte[] newPassword)
          Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.
PasswordModifyExtendedRequest(byte[] oldPassword, byte[] newPassword)
          Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.
PasswordModifyExtendedRequest(ExtendedRequest extendedRequest)
          Creates a new password modify extended request from the provided generic extended request.
PasswordModifyExtendedRequest(java.lang.String newPassword)
          Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.
PasswordModifyExtendedRequest(java.lang.String userIdentity, byte[] oldPassword, byte[] newPassword)
          Creates a new password modify extended request that will attempt to change the password for the specified user.
PasswordModifyExtendedRequest(java.lang.String userIdentity, byte[] oldPassword, byte[] newPassword, Control[] controls)
          Creates a new password modify extended request that will attempt to change the password for the specified user.
PasswordModifyExtendedRequest(java.lang.String oldPassword, java.lang.String newPassword)
          Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.
PasswordModifyExtendedRequest(java.lang.String userIdentity, java.lang.String oldPassword, java.lang.String newPassword)
          Creates a new password modify extended request that will attempt to change the password for the specified user.
PasswordModifyExtendedRequest(java.lang.String userIdentity, java.lang.String oldPassword, java.lang.String newPassword, Control[] controls)
          Creates a new password modify extended request that will attempt to change the password for the specified user.
 
Method Summary
 PasswordModifyExtendedRequest duplicate()
          Creates a new instance of this LDAP request that may be modified without impacting this request.
 PasswordModifyExtendedRequest duplicate(Control[] controls)
          Creates a new instance of this LDAP request that may be modified without impacting this request.
 java.lang.String getExtendedRequestName()
          Retrieves the user-friendly name for the extended request, if available.
 java.lang.String getNewPassword()
          Retrieves the string representation of the new password for this request, if available.
 byte[] getNewPasswordBytes()
          Retrieves the binary representation of the new password for this request, if available.
 java.lang.String getOldPassword()
          Retrieves the string representation of the old password for this request, if available.
 byte[] getOldPasswordBytes()
          Retrieves the binary representation of the old password for this request, if available.
 ASN1OctetString getRawNewPassword()
          Retrieves the raw new password for this request, if available.
 ASN1OctetString getRawOldPassword()
          Retrieves the raw old password for this request, if available.
 java.lang.String getUserIdentity()
          Retrieves the user identity for this request, if available.
 PasswordModifyExtendedResult process(LDAPConnection connection, int depth)
          Sends this extended request to the directory server over the provided connection and returns the associated response.
 void toString(java.lang.StringBuilder buffer)
          Appends a string representation of this request to the provided buffer.
 
Methods inherited from class com.unboundid.ldap.sdk.ExtendedRequest
encodeProtocolOp, getLastMessageID, getOID, getOperationType, getProtocolOpType, getValue, hasValue, responseReceived, toCode, writeTo
 
Methods inherited from class com.unboundid.ldap.sdk.LDAPRequest
followReferrals, getControl, getControlList, getControls, getIntermediateResponseListener, getResponseTimeoutMillis, hasControl, hasControl, setFollowReferrals, setIntermediateResponseListener, setResponseTimeoutMillis, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PASSWORD_MODIFY_REQUEST_OID

public static final java.lang.String PASSWORD_MODIFY_REQUEST_OID
The OID (1.3.6.1.4.1.4203.1.11.1) for the password modify extended request.

See Also:
Constant Field Values
Constructor Detail

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(java.lang.String newPassword)
Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.

Parameters:
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(byte[] newPassword)
Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.

Parameters:
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(java.lang.String oldPassword,
                                     java.lang.String newPassword)
Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.

Parameters:
oldPassword - The current password for the user. It may be null if the directory server does not require the user's current password for self changes.
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(byte[] oldPassword,
                                     byte[] newPassword)
Creates a new password modify extended request that will attempt to change the password of the currently-authenticated user.

Parameters:
oldPassword - The current password for the user. It may be null if the directory server does not require the user's current password for self changes.
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(java.lang.String userIdentity,
                                     java.lang.String oldPassword,
                                     java.lang.String newPassword)
Creates a new password modify extended request that will attempt to change the password for the specified user.

Parameters:
userIdentity - The string that identifies the user whose password should be changed. It may or may not be a DN, but if it is not a DN, then the directory server must be able to identify the appropriate user from the provided identifier. It may be null to indicate that the password change should be for the currently-authenticated user.
oldPassword - The current password for the user. It may be null if the directory server does not require the user's current password for self changes.
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(java.lang.String userIdentity,
                                     byte[] oldPassword,
                                     byte[] newPassword)
Creates a new password modify extended request that will attempt to change the password for the specified user.

Parameters:
userIdentity - The string that identifies the user whose password should be changed. It may or may not be a DN, but if it is not a DN, then the directory server must be able to identify the appropriate user from the provided identifier. It may be null to indicate that the password change should be for the currently-authenticated user.
oldPassword - The current password for the user. It may be null if the directory server does not require the user's current password for self changes.
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(java.lang.String userIdentity,
                                     java.lang.String oldPassword,
                                     java.lang.String newPassword,
                                     Control[] controls)
Creates a new password modify extended request that will attempt to change the password for the specified user.

Parameters:
userIdentity - The string that identifies the user whose password should be changed. It may or may not be a DN, but if it is not a DN, then the directory server must be able to identify the appropriate user from the provided identifier. It may be null to indicate that the password change should be for the currently-authenticated user.
oldPassword - The current password for the user. It may be null if the directory server does not require the user's current password for self changes.
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.
controls - The set of controls to include in the request.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(java.lang.String userIdentity,
                                     byte[] oldPassword,
                                     byte[] newPassword,
                                     Control[] controls)
Creates a new password modify extended request that will attempt to change the password for the specified user.

Parameters:
userIdentity - The string that identifies the user whose password should be changed. It may or may not be a DN, but if it is not a DN, then the directory server must be able to identify the appropriate user from the provided identifier. It may be null to indicate that the password change should be for the currently-authenticated user.
oldPassword - The current password for the user. It may be null if the directory server does not require the user's current password for self changes.
newPassword - The new password for the user. It may be null if the new password should be generated by the directory server.
controls - The set of controls to include in the request.

PasswordModifyExtendedRequest

public PasswordModifyExtendedRequest(ExtendedRequest extendedRequest)
                              throws LDAPException
Creates a new password modify extended request from the provided generic extended request.

Parameters:
extendedRequest - The generic extended request to use to create this password modify extended request.
Throws:
LDAPException - If a problem occurs while decoding the request.
Method Detail

getUserIdentity

public java.lang.String getUserIdentity()
Retrieves the user identity for this request, if available.

Returns:
The user identity for this request, or null if the password change should target the currently-authenticated user.

getOldPassword

public java.lang.String getOldPassword()
Retrieves the string representation of the old password for this request, if available.

Returns:
The string representation of the old password for this request, or null if it was not provided.

getOldPasswordBytes

public byte[] getOldPasswordBytes()
Retrieves the binary representation of the old password for this request, if available.

Returns:
The binary representation of the old password for this request, or null if it was not provided.

getRawOldPassword

public ASN1OctetString getRawOldPassword()
Retrieves the raw old password for this request, if available.

Returns:
The raw old password for this request, or null if it was not provided.

getNewPassword

public java.lang.String getNewPassword()
Retrieves the string representation of the new password for this request, if available.

Returns:
The string representation of the new password for this request, or null if it was not provided.

getNewPasswordBytes

public byte[] getNewPasswordBytes()
Retrieves the binary representation of the new password for this request, if available.

Returns:
The binary representation of the new password for this request, or null if it was not provided.

getRawNewPassword

public ASN1OctetString getRawNewPassword()
Retrieves the raw new password for this request, if available.

Returns:
The raw new password for this request, or null if it was not provided.

process

public PasswordModifyExtendedResult process(LDAPConnection connection,
                                            int depth)
                                     throws LDAPException
Sends this extended request to the directory server over the provided connection and returns the associated response.

Overrides:
process in class ExtendedRequest
Parameters:
connection - The connection to use to communicate with the directory server.
depth - The current referral depth for this request. It should always be one for the initial request, and should only be incremented when following referrals.
Returns:
An LDAP result object that provides information about the result of the extended operation processing.
Throws:
LDAPException - If a problem occurs while sending the request or reading the response.

duplicate

public PasswordModifyExtendedRequest duplicate()
Creates a new instance of this LDAP request that may be modified without impacting this request.. Subclasses should override this method to return a duplicate of the appropriate type.

Specified by:
duplicate in interface ReadOnlyLDAPRequest
Overrides:
duplicate in class ExtendedRequest
Returns:
A new instance of this LDAP request that may be modified without impacting this request.

duplicate

public PasswordModifyExtendedRequest duplicate(Control[] controls)
Creates a new instance of this LDAP request that may be modified without impacting this request. The provided controls will be used for the new request instead of duplicating the controls from this request.. Subclasses should override this method to return a duplicate of the appropriate type.

Specified by:
duplicate in interface ReadOnlyLDAPRequest
Overrides:
duplicate in class ExtendedRequest
Parameters:
controls - The set of controls to include in the duplicate request.
Returns:
A new instance of this LDAP request that may be modified without impacting this request.

getExtendedRequestName

public java.lang.String getExtendedRequestName()
Retrieves the user-friendly name for the extended request, if available. If no user-friendly name has been defined, then the OID will be returned.

Overrides:
getExtendedRequestName in class ExtendedRequest
Returns:
The user-friendly name for this extended request, or the OID if no user-friendly name is available.

toString

public void toString(java.lang.StringBuilder buffer)
Appends a string representation of this request to the provided buffer.

Specified by:
toString in interface ProtocolOp
Specified by:
toString in interface ReadOnlyLDAPRequest
Overrides:
toString in class ExtendedRequest
Parameters:
buffer - The buffer to which to append a string representation of this request.