    public LdapContext getLdapContext(String username, String password) throws NamingException {
        if (searchBase == null) {
            throw new IllegalStateException("A search base must be specified.");
        }
        if (url == null) {
            throw new IllegalStateException("An LDAP URL must be specified of the form ldap://<hostname>:<port>");
        }
        if (principalSuffix != null) {
            username += principalSuffix;
        }
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.SECURITY_AUTHENTICATION, authentication);
        env.put(Context.SECURITY_PRINCIPAL, username);
        env.put(Context.SECURITY_CREDENTIALS, password);
        env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactoryClassName);
        env.put(Context.PROVIDER_URL, url);
        env.put(Context.REFERRAL, referral);
        if (usePooling && username.equals(systemUsername)) {
            env.put(SUN_CONNECTION_POOLING_PROPERTY, "true");
        }
        if (additionalEnvironment != null) {
            env.putAll(additionalEnvironment);
        }
        if (log.isDebugEnabled()) {
            log.debug("Initializing LDAP context using URL [" + url + "] and username [" + systemUsername + "] " +
                    "with pooling [" + (usePooling ? "enabled" : "disabled") + "]");
        }
        return new InitialLdapContext(env, null);
    }

    public LdapContext getLdapContext(String username, String password) throws NamingException {
        if (searchBase == null) {
            throw new IllegalStateException("A search base must be specified.");
        }
        if (url == null) {
            throw new IllegalStateException("An LDAP URL must be specified of the form ldap://<hostname>:<port>");
        }
        if (username != null && principalSuffix != null) {
            username += principalSuffix;
        }
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.SECURITY_AUTHENTICATION, authentication);
        if (username != null) {
            env.put(Context.SECURITY_PRINCIPAL, username);
        }
        if (password != null) {
            env.put(Context.SECURITY_CREDENTIALS, password);
        }
        env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactoryClassName);
        env.put(Context.PROVIDER_URL, url);
        env.put(Context.REFERRAL, referral);
        if (usePooling && username.equals(systemUsername)) {
            env.put(SUN_CONNECTION_POOLING_PROPERTY, "true");
        }
        if (additionalEnvironment != null) {
            env.putAll(additionalEnvironment);
        }
        if (log.isDebugEnabled()) {
            log.debug("Initializing LDAP context using URL [" + url + "] and username [" + systemUsername + "] " +
                    "with pooling [" + (usePooling ? "enabled" : "disabled") + "]");
        }
        return new InitialLdapContext(env, null);
    }
