当前位置: 首页>>代码示例>>Java>>正文


Java NamingEnumeration.close方法代码示例

本文整理汇总了Java中javax.naming.NamingEnumeration.close方法的典型用法代码示例。如果您正苦于以下问题:Java NamingEnumeration.close方法的具体用法?Java NamingEnumeration.close怎么用?Java NamingEnumeration.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.NamingEnumeration的用法示例。


在下文中一共展示了NamingEnumeration.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findUserDn

import javax.naming.NamingEnumeration; //导入方法依赖的package包/类
/**
 * Finds a distinguished name(DN) of a user by querying the active directory LDAP context for the
 * specified username.
 */
protected String findUserDn(LdapContextFactory ldapContextFactory, String username) throws NamingException {
    LdapContext ctx = null;
    try {
        // Binds using the system username and password.
        ctx = ldapContextFactory.getSystemLdapContext();

        final SearchControls ctrl = new SearchControls();
        ctrl.setCountLimit(1);
        ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
        ctrl.setTimeLimit(searchTimeoutMillis);

        final String filter =
                searchFilter != null ? USERNAME_PLACEHOLDER.matcher(searchFilter)
                                                           .replaceAll(username)
                                     : username;
        final NamingEnumeration<SearchResult> result = ctx.search(searchBase, filter, ctrl);
        try {
            if (!result.hasMore()) {
                throw new AuthenticationException("No username: " + username);
            }
            return result.next().getNameInNamespace();
        } finally {
            result.close();
        }
    } finally {
        LdapUtils.closeContext(ctx);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:33,代码来源:SearchFirstActiveDirectoryRealm.java

示例2: addAttributeValues

import javax.naming.NamingEnumeration; //导入方法依赖的package包/类
/**
 * Add values of a specified attribute to a list
 *
 * @param attrId Attribute name
 * @param attrs Attributes containing the new values
 * @param values ArrayList containing values found so far
 *
 * @exception NamingException if a directory server error occurs
 */
private ArrayList<String> addAttributeValues(String attrId,
                                     Attributes attrs,
                                     ArrayList<String> values)
    throws NamingException{

    if (containerLog.isTraceEnabled())
        containerLog.trace("  retrieving values for attribute " + attrId);
    if (attrId == null || attrs == null)
        return values;
    if (values == null)
        values = new ArrayList<String>();
    Attribute attr = attrs.get(attrId);
    if (attr == null)
        return values;
    NamingEnumeration<?> e = attr.getAll();
    try {
        while(e.hasMore()) {
            String value = (String)e.next();
            values.add(value);
        }
    } catch (PartialResultException ex) {
        if (!adCompat)
            throw ex;
    } finally {
        e.close();
    }
    return values;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:38,代码来源:JNDIRealm.java

示例3: searchFirstResult

import javax.naming.NamingEnumeration; //导入方法依赖的package包/类
public <T> T searchFirstResult(DirContext ctx, Name base, Filter filter, HitsCollector<T> collector,
	boolean recurse) throws NamingException
{
	collector.setup(ctx, this);

	NamingEnumeration<SearchResult> ne = search(ctx, base, collector.getReturnAttributes(), filter, recurse);
	// The above returns null if there are no results, so assume if not null
	// that there is a first result
	if( ne != null )
	{
		try
		{
			collector.addResult(ne.next(), base);
			return collector.getResults().get(0);
		}
		finally
		{
			// Because we're not going all the way to the end of the
			// enumeration, we have to manually close it.
			ne.close();
		}
	}
	return null;
}
 
开发者ID:equella,项目名称:Equella,代码行数:25,代码来源:LDAP.java

示例4: addAttributeValues

import javax.naming.NamingEnumeration; //导入方法依赖的package包/类
/**
 * Add values of a specified attribute to a list
 *
 * @param attrId
 *            Attribute name
 * @param attrs
 *            Attributes containing the new values
 * @param values
 *            ArrayList containing values found so far
 *
 * @exception NamingException
 *                if a directory server error occurs
 */
private ArrayList<String> addAttributeValues(String attrId, Attributes attrs, ArrayList<String> values)
		throws NamingException {

	if (containerLog.isTraceEnabled())
		containerLog.trace("  retrieving values for attribute " + attrId);
	if (attrId == null || attrs == null)
		return values;
	if (values == null)
		values = new ArrayList<String>();
	Attribute attr = attrs.get(attrId);
	if (attr == null)
		return values;
	NamingEnumeration<?> e = attr.getAll();
	try {
		while (e.hasMore()) {
			String value = (String) e.next();
			values.add(value);
		}
	} catch (PartialResultException ex) {
		if (!adCompat)
			throw ex;
	} finally {
		e.close();
	}
	return values;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:40,代码来源:JNDIRealm.java

示例5: searchByLimit

import javax.naming.NamingEnumeration; //导入方法依赖的package包/类
private <T> List<T> searchByLimit(Properties properties, String baseDN,
        String filter, ILdapResultMapper<T> mapper, boolean checkAttribute,
        int searchLimit) throws NamingException {
    List<T> list = new ArrayList<T>();
    NamingEnumeration<SearchResult> namingEnum = null;

    DirContext ctx = getDirContext(properties);

    SearchControls ctls = new SearchControls();
    String[] attrIds = mapper.getAttributes();
    ctls.setReturningAttributes(attrIds);
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ctls.setCountLimit(searchLimit);

    try {
        namingEnum = ctx.search(baseDN, escapeLDAPSearchFilter(filter),
                ctls);
        int count = 0;
        while (count++ < searchLimit && hasMoreEnum(namingEnum)) {
            SearchResult res = namingEnum.next();
            Attributes ldapAttributes = res.getAttributes();
            String[] values = new String[attrIds.length];
            for (int i = 0; i < values.length; i++) {
                Attribute ldapAttr = ldapAttributes
                        .get(escapeLDAPSearchFilter(attrIds[i]));
                if (checkAttribute && ldapAttr == null) {
                    NamingException e = new NamingException(
                            "Unknown LDAP attribute " + attrIds[i]);
                    throw e;
                }
                if (ldapAttr != null && ldapAttr.get() != null) {
                    values[i] = ldapAttr.get().toString();
                }
            }
            T t = mapper.map(values);
            if (t != null) {
                list.add(t);
            }
        }
    } finally {
        if (namingEnum != null) {
            try {
                namingEnum.close();
            } finally {
                closeContext(ctx);
            }
        }
        closeContext(ctx);
    }
    return list;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:52,代码来源:LdapAccessServiceBean.java


注:本文中的javax.naming.NamingEnumeration.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。