当前位置: 首页>>代码示例>>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;未经允许,请勿转载。