public LdapName getUsersBaseDN( String username )
    {
        if ( userDNCache != null )
        {
            // Return a cache entry if one exists.
            final CacheableOptional<DNCacheEntry> dnCacheEntry = userDNCache.get( username );
            if ( dnCacheEntry != null )
            {
                if (dnCacheEntry.isAbsent()) {
                    Log.debug( "An earlier UserNotFoundException occurred while tyring to get the user baseDn for {} (negative lookup cache result)", username );
                    return null;
                } else {
                    return dnCacheEntry.get().getBaseDN();
                }
            }
        }

        // No cache entry. Query for the value, and add that to the cache.
        try
        {
            final Rdn[] userRDN = findUserRDN( username, baseDN );
            if ( userDNCache != null )
            {
                userDNCache.put( username, CacheableOptional.of( new DNCacheEntry( userRDN, baseDN ) ) );
            }
            return baseDN;
        }
        catch ( Exception e )
        {
            try
            {
                if ( alternateBaseDN != null )
                {
                    final Rdn[] userRDN = findUserRDN( username, alternateBaseDN );
                    if ( userDNCache != null )
                    {
                        userDNCache.put( username, CacheableOptional.of(new DNCacheEntry( userRDN, alternateBaseDN ) ) );
                    }
                    return alternateBaseDN;
                }
            }
            catch ( UserNotFoundException ex ) {
                Log.debug( "An exception occurred while tyring to get the user baseDn for {}", username, ex );

                if (userDNCache != null) {
                    // Cache the 'not found' event to prevent incurring costs for future lookups (that will be equally unsuccessful). OF-2170
                    userDNCache.put(username, CacheableOptional.of(null));
                }
            }
            catch ( Exception ex )
            {
                Log.debug( "An exception occurred while tyring to get the user baseDn for {}", username, ex );
            }
        }

        return null;
    }
Returns the BaseDN for the given username.

@param username username to return its base DN.
@return the BaseDN for the given username. If no baseDN is found,
        this method will return {@code null}.
xmppserver/src/main/java/org/jivesoftware/openfire/ldap/LdapManager.java