當前位置: 首頁>>代碼示例>>Java>>正文


Java InitialDirContext.close方法代碼示例

本文整理匯總了Java中javax.naming.directory.InitialDirContext.close方法的典型用法代碼示例。如果您正苦於以下問題:Java InitialDirContext.close方法的具體用法?Java InitialDirContext.close怎麽用?Java InitialDirContext.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.naming.directory.InitialDirContext的用法示例。


在下文中一共展示了InitialDirContext.close方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUserForLoginName

import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public User getUserForLoginName(String login) {
	try {
		InitialDirContext ctx = createContext();

		User user = new User();
		SearchResult next = getLDAPInformation(ctx, login.toLowerCase()).nextElement();
		user.setLogin(login.toLowerCase());
		user.setSurname(next.getAttributes().get("sn").get().toString());
		user.setForename(next.getAttributes().get("givenName").get().toString());
		user.setEmail(next.getAttributes().get("mail").get().toString().toLowerCase());

		ctx.close();
		return user;
	} catch (Exception e) {
		log.info("Login " + login + " nicht gefunden!");
	}
	return null;
}
 
開發者ID:adessoAG,項目名稱:JenkinsHue,代碼行數:19,代碼來源:LDAPManager.java

示例2: closeDirectoryContext

import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public static void closeDirectoryContext(InitialDirContext initialDirContext) {
    try {
        initialDirContext.close();
    } catch (NamingException e) {
        LOGGER.warn("Could not close InitialDirContext correctly!", e);
    }
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:8,代碼來源:LDAPConnectionUtil.java

示例3: authenticateUser

import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public boolean authenticateUser(String username, String password) {

        if (ldapAuth) {
            String[] domainArr = ldapDomain.split(",");
            for (String domain : domainArr) {
                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                env.put(Context.PROVIDER_URL, ldapUrl);
                env.put(Context.SECURITY_AUTHENTICATION, "simple");
                env.put(Context.SECURITY_PRINCIPAL, domain + "\\" + username);
                env.put(Context.SECURITY_CREDENTIALS, password);
                try {
                    ctx = new InitialDirContext(env);
                    return true;
                } catch (NamingException e) {

                } finally {
                    if (ctx != null) {
                        try {
                            ctx.close();
                        } catch (NamingException ex) {
                            LOGGER.warn(ex.getMessage());
                        }
                    }
                }
            }
            return false;
        } else {
            //DB authentication
            EcUser user = uDao.findByUsernameAndPassword(username, password);
            if (user == null) {
                return false;
            } else {
                return true;
            }
        }

    }
 
開發者ID:DeemOpen,項目名稱:excord,代碼行數:39,代碼來源:LdapAuth.java

示例4: authenticateUser

import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
public boolean authenticateUser(String ldapUrl, String username, String password, String domains) {

        String[] domainArr = domains.split(",");
        for (String domain : domainArr) {
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
            env.put(Context.PROVIDER_URL, ldapUrl);
            env.put(Context.SECURITY_AUTHENTICATION, "simple");
            env.put(Context.SECURITY_PRINCIPAL, domain + "\\" + username);
            env.put(Context.SECURITY_CREDENTIALS, password);
            try {
                ctx = new InitialDirContext(env);
                return true;
            } catch (NamingException e) {

            } finally {
                if (ctx != null) {
                    try {
                        ctx.close();
                    } catch (NamingException ex) {
                        logger.warn(ex.getMessage());
                    }
                }
            }
        }
        return false;

    }
 
開發者ID:zhoushineyoung,項目名稱:zookeeper-edit,代碼行數:29,代碼來源:LdapAuth.java

示例5: start

import javax.naming.directory.InitialDirContext; //導入方法依賴的package包/類
/**
 * start the connector
 */
public void start() throws Exception {
    LOG.info("connecting...");
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    this.ldapURI = getUri();
    LOG.debug("    URI [{}]", this.ldapURI);
    env.put(Context.PROVIDER_URL, this.ldapURI.toString());
    if (anonymousAuthentication) {
        LOG.debug("    login credentials [anonymous]");
        env.put(Context.SECURITY_AUTHENTICATION, "none");
    } else {
        LOG.debug("    login credentials [{}:******]", user);
        env.put(Context.SECURITY_PRINCIPAL, user);
        env.put(Context.SECURITY_CREDENTIALS, password);
    }
    boolean isConnected = false;
    while (!isConnected) {
        try {
            context = new InitialDirContext(env);
            isConnected = true;
        } catch (CommunicationException err) {
            if (failover) {
                this.ldapURI = getUri();
                LOG.error("connection error [{}], failover connection to [{}]", env.get(Context.PROVIDER_URL), this.ldapURI.toString());
                env.put(Context.PROVIDER_URL, this.ldapURI.toString());
                Thread.sleep(curReconnectDelay);
                curReconnectDelay = Math.min(curReconnectDelay * 2, maxReconnectDelay);
            } else {
                throw err;
            }
        }
    }

    // add connectors from search results
    LOG.info("searching for network connectors...");
    LOG.debug("    base   [{}]", base);
    LOG.debug("    filter [{}]", searchFilter);
    LOG.debug("    scope  [{}]", searchControls.getSearchScope());
    NamingEnumeration<SearchResult> results = context.search(base, searchFilter, searchControls);
    while (results.hasMore()) {
        addConnector(results.next());
    }

    // register persistent search event listener
    if (searchEventListener) {
        LOG.info("registering persistent search listener...");
        EventDirContext eventContext = (EventDirContext) context.lookup("");
        eventContext.addNamingListener(base, searchFilter, searchControls, this);
    } else { // otherwise close context (i.e. connection as it is no longer needed)
        context.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:56,代碼來源:LdapNetworkConnector.java


注:本文中的javax.naming.directory.InitialDirContext.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。