Dn userDn = new Dn( "cn=UserXY,ou=system" );
userConnection = getNetworkConnectionAs( ldapServer, userDn.toString(), "secret3" );
PasswordPolicyDecorator passwordPolicyRequestControl =
new PasswordPolicyDecorator( LdapApiServiceFactory.getSingleton(), new PasswordPolicyImpl() );
PwdModifyRequestImpl selfPwdModifyRequest = new PwdModifyRequestImpl();
selfPwdModifyRequest.setUserIdentity( Dn.getBytes( userDn ) );
selfPwdModifyRequest.setOldPassword( Strings.getBytesUtf8( "secret3" ) );
selfPwdModifyRequest.setNewPassword( Strings.getBytesUtf8( "1234567" ) );
selfPwdModifyRequest.addControl( passwordPolicyRequestControl );
// Send the request to update own password
PwdModifyResponse pwdModifyResponse = ( PwdModifyResponse ) userConnection.extended( selfPwdModifyRequest );
// passwordTooShort is a contstraint violation
assertEquals( ResultCodeEnum.CONSTRAINT_VIOLATION, pwdModifyResponse.getLdapResult().getResultCode() );
Control passwordPolicyResponseControl = pwdModifyResponse.getControl( passwordPolicyRequestControl.getOid() );
assertNotNull( passwordPolicyResponseControl );
assertEquals( PasswordPolicyErrorEnum.PASSWORD_TOO_YOUNG,
((PasswordPolicyDecorator)passwordPolicyResponseControl)
.getDecorated().getResponse().getPasswordPolicyError() );
addUser( adminConnection, "UserZZ", "secret4" );
Dn otherUserDn = new Dn( "cn=UserZZ,ou=system" );
PwdModifyRequestImpl pwdModifyRequest = new PwdModifyRequestImpl();
pwdModifyRequest.setUserIdentity( Dn.getBytes( otherUserDn ) );
pwdModifyRequest.setOldPassword( Strings.getBytesUtf8( "secret4" ) );
pwdModifyRequest.setNewPassword( Strings.getBytesUtf8( "1234567" ) );
pwdModifyResponse = ( PwdModifyResponse ) userConnection.extended( pwdModifyRequest );
assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, pwdModifyResponse.getLdapResult().getResultCode() );
}
finally
{