String principal;
if ( ! ctx.getEnvironment().containsKey( Context.SECURITY_PRINCIPAL ) )
{
throw new LdapAuthenticationException();
}
else
{
principal = ( String ) ctx.getEnvironment().get( Context.SECURITY_PRINCIPAL );
if ( principal == null )
{
throw new LdapAuthenticationException();
}
}
// ---- lookup the principal entry's userPassword attribute
LdapName principalDn = new LdapName( principal );
PartitionNexus rootNexus = getAuthenticatorContext().getPartitionNexus();
Attributes userEntry = rootNexus.lookup( principalDn );
if ( userEntry == null )
{
throw new LdapNameNotFoundException();
}
Object userPassword;
Attribute userPasswordAttr = userEntry.get( "userPassword" );
// ---- assert that credentials match
if ( userPasswordAttr == null )
{
userPassword = ArrayUtils.EMPTY_BYTE_ARRAY;
}
else
{
userPassword = userPasswordAttr.get();
if ( userPassword instanceof String )
{
userPassword = ( ( String ) userPassword ).getBytes();
}
}
if ( ! ArrayUtils.isEquals( creds, userPassword ) )
{
throw new LdapAuthenticationException();
}
return new LdapPrincipal( principalDn );
}