Attribute userPasswordAttribute = entry.get( passwordAttribute );
if ( userPasswordAttribute != null )
{
BinaryValue userPassword = ( BinaryValue ) userPasswordAttribute.get();
try
{
check( addContext, entry, userPassword.getValue(), policyConfig );
}
catch ( PasswordPolicyException e )
{
if ( isPPolicyReqCtrlPresent )
{
PasswordPolicyDecorator responseControl =
new PasswordPolicyDecorator( directoryService.getLdapCodecService(), true );
responseControl.getResponse().setPasswordPolicyError(
PasswordPolicyErrorEnum.get( e.getErrorCode() ) );
addContext.addResponseControl( responseControl );
}
// throw exception if userPassword quality checks fail
throw new LdapOperationException( ResultCodeEnum.CONSTRAINT_VIOLATION, e.getMessage(), e );
}
String pwdChangedTime = DateUtils.getGeneralizedTime();
if ( ( policyConfig.getPwdMinAge() > 0 ) || ( policyConfig.getPwdMaxAge() > 0 ) )
{
Attribute pwdChangedTimeAt = new DefaultAttribute( AT_PWD_CHANGED_TIME );
pwdChangedTimeAt.add( pwdChangedTime );
entry.add( pwdChangedTimeAt );
}
if ( policyConfig.isPwdMustChange() && addContext.getSession().isAnAdministrator() )
{
Attribute pwdResetAt = new DefaultAttribute( AT_PWD_RESET );
pwdResetAt.add( "TRUE" );
entry.add( pwdResetAt );
}
if ( policyConfig.getPwdInHistory() > 0 )
{
Attribute pwdHistoryAt = new DefaultAttribute( AT_PWD_HISTORY );
byte[] pwdHistoryVal = new PasswordHistory( pwdChangedTime, userPassword.getValue() ).getHistoryValue();
pwdHistoryAt.add( pwdHistoryVal );
entry.add( pwdHistoryAt );
}
}