creds = ( ( String ) creds ).getBytes();
creds = StringTools.getBytesUtf8( ( String ) creds );
    public LdapPrincipal authenticate( LdapDN principalDn, ServerContext ctx ) throws NamingException    {        // ---- extract password from JNDI environment        Object creds = ctx.getEnvironment().get( Context.SECURITY_CREDENTIALS );        if ( creds == null )        {            creds = ArrayUtils.EMPTY_BYTE_ARRAY;        }        else if ( creds instanceof String )        {            creds = ( ( String ) creds ).getBytes();        }        byte[] userPassword = null;        if ( credentialCache.containsKey( principalDn.getNormName() ) )        {            userPassword = ( byte[] ) credentialCache.get( principalDn.getNormName() );        }        else        {            userPassword = lookupUserPassword( principalDn );        }        boolean credentialsMatch = false;        // Check if password is stored as a message digest, i.e. one-way        // encrypted        if ( this.isPasswordOneWayEncrypted( userPassword ) )        {            try            {                // create a corresponding digested password from creds                String algorithm = this.getAlgorithmForHashedPassword( userPassword );                String digestedCredits = this.createDigestedPassword( algorithm, creds );                credentialsMatch = ArrayUtils.isEquals( digestedCredits.getBytes(), userPassword );            }            catch ( NoSuchAlgorithmException nsae )            {                log.warn( "Password stored with unknown algorithm.", nsae );            }            catch ( IllegalArgumentException e )            {                log.warn( "Exception during authentication", e );            }        }        else        {            // password is not stored one-way encrypted            credentialsMatch = ArrayUtils.isEquals( creds, userPassword );        }        if ( credentialsMatch )        {            LdapPrincipal principal = new LdapPrincipal( principalDn, AuthenticationLevel.SIMPLE );            credentialCache.put( principalDn.getNormName(), userPassword );            return principal;        }        else        {            throw new LdapAuthenticationException();        }    }