Dn userDn = new Dn( "cn=UserXY,ou=system" );
userConnection = getNetworkConnectionAs( ldapServer, userDn.toString(), "secret3" );
PasswordPolicyDecorator passwordPolicyRequestControl =
new PasswordPolicyDecorator( LdapApiServiceFactory.getSingleton(), new PasswordPolicyImpl() );
PasswordModifyRequest selfPwdModifyRequest = new PasswordModifyRequestImpl();
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
PasswordModifyResponse pwdModifyResponse = ( PasswordModifyResponse ) userConnection.extended( selfPwdModifyRequest );
// passwordTooShort is a constraint 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" );
PasswordModifyRequest pwdModifyRequest = new PasswordModifyRequestImpl();
pwdModifyRequest.setUserIdentity( Dn.getBytes( otherUserDn ) );
pwdModifyRequest.setOldPassword( Strings.getBytesUtf8( "secret4" ) );
pwdModifyRequest.setNewPassword( Strings.getBytesUtf8( "1234567" ) );
pwdModifyResponse = ( PasswordModifyResponse ) userConnection.extended( pwdModifyRequest );
assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, pwdModifyResponse.getLdapResult().getResultCode() );
}
finally
{