protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/sasl/cramMD5/CramMd5CallbackHandler.java [69:136]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        super( adminSession.getDirectoryService(), bindRequest );
        this.ldapSession = ldapSession;
        this.adminSession = adminSession;
        schemaManager = adminSession.getDirectoryService().getSchemaManager();
    }


    protected Attribute lookupPassword( String username, String realm )
    {
        try
        {
            ExprNode filter = FilterParser.parse( schemaManager, "(uid=" + username + ")" );

            bindDn = ( String ) ldapSession.getSaslProperty( SaslConstants.SASL_USER_BASE_DN );

            Dn baseDn = new Dn( bindDn );

            Cursor<Entry> cursor = adminSession.search(
                baseDn,
                SearchScope.SUBTREE,
                filter,
                AliasDerefMode.DEREF_ALWAYS,
                SchemaConstants.USER_PASSWORD_AT );

            cursor.beforeFirst();

            Entry entry = null;

            while ( cursor.next() )
            {
                entry = cursor.get();
                LdapPrincipal ldapPrincipal = new LdapPrincipal(
                    schemaManager,
                    entry.getDn(),
                    AuthenticationLevel.STRONG,
                    entry.get( SchemaConstants.USER_PASSWORD_AT ).getBytes() );
                ldapSession.putSaslProperty( SaslConstants.SASL_AUTHENT_USER, ldapPrincipal );
            }

            cursor.close();

            if ( entry != null )
            {
                return entry.get( SchemaConstants.USER_PASSWORD_AT );
            }
            else
            {
                return null;
            }
        }
        catch ( Exception e )
        {
            return null;
        }
    }


    protected void authorize( AuthorizeCallback authorizeCB )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( "Converted username {} to Dn {}", getUsername(), bindDn );
        }

        ldapSession.putSaslProperty( Context.SECURITY_PRINCIPAL, bindDn );

        authorizeCB.setAuthorizedID( bindDn );
        authorizeCB.setAuthorized( true );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/sasl/digestMD5/DigestMd5CallbackHandler.java [69:136]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        super( adminSession.getDirectoryService(), bindRequest );
        this.ldapSession = ldapSession;
        this.adminSession = adminSession;
        schemaManager = adminSession.getDirectoryService().getSchemaManager();
    }


    // TODO - should return not be a byte[]
    protected Attribute lookupPassword( String username, String realm )
    {
        try
        {
            ExprNode filter = FilterParser.parse( schemaManager, "(uid=" + username + ")" );
            bindDn = ( String ) ldapSession.getSaslProperty( SaslConstants.SASL_USER_BASE_DN );

            Dn baseDn = new Dn( bindDn );

            Cursor<Entry> cursor = adminSession.search(
                baseDn,
                SearchScope.SUBTREE,
                filter,
                AliasDerefMode.DEREF_ALWAYS,
                SchemaConstants.USER_PASSWORD_AT );

            cursor.beforeFirst();

            Entry entry = null;

            while ( cursor.next() )
            {
                entry = cursor.get();
                LdapPrincipal ldapPrincipal = new LdapPrincipal(
                    schemaManager,
                    entry.getDn(),
                    AuthenticationLevel.STRONG,
                    entry.get( SchemaConstants.USER_PASSWORD_AT ).getBytes() );
                ldapSession.putSaslProperty( SaslConstants.SASL_AUTHENT_USER, ldapPrincipal );
            }

            cursor.close();

            if ( entry != null )
            {
                return entry.get( SchemaConstants.USER_PASSWORD_AT );
            }
            else
            {
                return null;
            }
        }
        catch ( Exception e )
        {
            return null;
        }
    }


    protected void authorize( AuthorizeCallback authorizeCB )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( "Converted username {} to Dn {}", getUsername(), bindDn );
        }

        ldapSession.putSaslProperty( Context.SECURITY_PRINCIPAL, bindDn );

        authorizeCB.setAuthorizedID( bindDn );
        authorizeCB.setAuthorized( true );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



