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


Java SearchControls.setSearchScope方法代码示例

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


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

示例1: dnFromUser

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
private static String dnFromUser(String username) throws NamingException {
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    props.put(Context.PROVIDER_URL, "ldap://ldap.example.com");
    props.put(Context.REFERRAL, "ignore");

    InitialDirContext context = new InitialDirContext(props);

    SearchControls ctrls = new SearchControls();
    ctrls.setReturningAttributes(new String[]{"givenName", "sn"});
    ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    NamingEnumeration<SearchResult> answers = context.search("dc=People,dc=example,dc=com", "(uid=" + username + ")", ctrls);
    SearchResult result = answers.next();

    return result.getNameInNamespace();
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:18,代码来源:JndiLdap.java

示例2: ldapInjectionSunApi

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
public void ldapInjectionSunApi(String input) throws NamingException {
    //Stub instances
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    props.put(Context.PROVIDER_URL, "ldap://ldap.example.com");
    props.put(Context.REFERRAL, "ignore");

    SearchControls ctrls = new SearchControls();
    ctrls.setReturningAttributes(new String[]{"givenName", "sn"});
    ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    //Two context instances mostly usable with sun specific API
    LdapCtx            context5 = null;
    EventDirContext    context6 = null; //LdapCtx is the only known class to implements to this interface

    NamingEnumeration<SearchResult> answers;
    answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);

    answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:27,代码来源:JndiLdapAdditionalSignature.java

示例3: findUserDn

import javax.naming.directory.SearchControls; //导入方法依赖的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

示例4: search

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
/**
 * @return null if there are zero results
 */
private NamingEnumeration<SearchResult> search(DirContext ctx, Name base, String[] returnAttributes, Filter filter,
	boolean recurse)
{
	SearchControls ctls = new SearchControls();
	ctls.setCountLimit(filter.getLimit());
	ctls.setReturningAttributes(returnAttributes);
	ctls.setSearchScope(recurse ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE);

	try
	{
		// Search for objects using the filter
		String query = filter.toFilter();
		if( LOGGER.isDebugEnabled() )
		{
			LOGGER.debug("Query:" + query + " Base:" + base);
		}
		NamingEnumeration<SearchResult> ne = ctx.search(base, query, ctls);
		if( ne.hasMore() )
		{
			return ne;
		}
	}
	catch( PartialResultException pre )
	{
		LOGGER.info(pre);
	}
	catch( SizeLimitExceededException slee )
	{
		LOGGER.info(slee);
	}
	catch( Exception e )
	{
		LOGGER.warn(e);
	}

	return null;
}
 
开发者ID:equella,项目名称:Equella,代码行数:41,代码来源:LDAP.java

示例5: NotifierArgs

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
NotifierArgs(String name, int scope, NamingListener l) {
    this(name, "(objectclass=*)", null, l);

    // if scope is not default, create search ctl and set it
    if (scope != EventContext.ONELEVEL_SCOPE) {
        controls = new SearchControls();
        controls.setSearchScope(scope);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:NotifierArgs.java

示例6: searchChildren

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
/**
    * @param dn
    * @param filter
    * @return
    * @throws NamingException
    */
   public NamingEnumeration searchChildren(String dn, String filter) throws NamingException 
{
       SearchControls constraints = new SearchControls();
       constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
       return m_ctx.search(dn, filter, constraints);
   }
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:13,代码来源:LdapUtil.java

示例7: searchOne

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
/**
    * @param dn
    * @param filter
    * @return
    * @throws NamingException
    */
   public NamingEnumeration searchOne(String dn, String filter) throws NamingException 
{
       SearchControls constraints = new SearchControls();
       constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
       return m_ctx.search(dn, filter, constraints);
   }
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:13,代码来源:LdapUtil.java

示例8: searchSubtree

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
/**
    * @param dn
    * @param filter
    * @return
    * @throws NamingException
    */
   public NamingEnumeration searchSubtree(String dn, String filter)
{
       SearchControls constraints = new SearchControls();
       constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
       try
	{
		return m_ctx.search(dn, filter, constraints);
	}
	catch (NamingException e)
	{
		e.printStackTrace();
		return null ;
	}
   }
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:21,代码来源:LdapUtil.java

示例9: ldapApiQuery

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
private List<SearchResult> ldapApiQuery(String action, String name, String filter) {

        String logMsg = action + " " + filter;
        List<SearchResult> result = new ArrayList<SearchResult>();
        try {
            initLdapContext(action);
            LdapContext ldapCtx = ldapContexts.get(action);

            SearchControls constraints = new SearchControls();
            constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<SearchResult> en = ldapCtx.search(name, filter, constraints);

            // means all nodes
            if (en == null) {
                loggerInfo("LDAP信息", "获取", "结果为空", logMsg);
                return Collections.emptyList();
            }
            if (!en.hasMoreElements()) {
                loggerInfo("LDAP信息", "获取", "结果为空", logMsg);
                return Collections.emptyList();
            }

            while (en != null && en.hasMoreElements()) {// maybe more than one element
                Object obj = en.nextElement();
                if (obj instanceof SearchResult) {
                    SearchResult si = (SearchResult) obj;
                    result.add(si);
                }
            }
        }
        catch (Exception e) {
            loggerError("LDAP用户信息获取", logMsg, e);
            clearLdapContext(action);
        }

        if (!result.isEmpty()) {
            loggerInfo("LDAP信息", "获取", "成功", logMsg);
        }
        return result;
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:41,代码来源:GUISSOLdapClient.java

示例10: search

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
public NamingEnumeration<SearchResult> search(final String baseDN, final String filter) throws NamingException {
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    LdapContext ctx = new InitialLdapContext(env, null);
    NamingEnumeration<SearchResult> result = ctx.search(baseDN, filter, searchControls);
    ctx.close();

    return result;
}
 
开发者ID:klenkes74,项目名称:openshift-ldapsync,代码行数:11,代码来源:LdapServer.java

示例11: getLDAPInformation

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
private NamingEnumeration<SearchResult> getLDAPInformation(InitialDirContext context, String login) throws NamingException {
	SearchControls cons = new SearchControls();
	cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
	cons.setDerefLinkFlag(false);
	return context.search(ldapValue.getUserSearchBase(), MessageFormat.format(ldapValue.getUserSearchFilter(), login), cons);
}
 
开发者ID:adessoAG,项目名称:JenkinsHue,代码行数:7,代码来源:LDAPManager.java

示例12: searchByLimit

import javax.naming.directory.SearchControls; //导入方法依赖的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

示例13: getRolesRecursive

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
/**
 * Add roles to a user and search for other roles containing them themselves.
 * We search recursively with a limited depth.
 * By default the depth is 0, and we only use direct roles.
 * The search needs to use the distinguished role names,
 * but to return the role names.
 *
 * @param depth Recursion depth, starting at zero
 * @param context The directory context we are searching
 * @param recursiveMap The cumulative result map of role names and DNs.
 * @param recursiveSet The cumulative result set of role names.
 * @param groupName The role name to add to the list.
 * @param groupDName The distinguished name of the role.
 *
 * @exception NamingException if a directory server error occurs
 */
private void getRolesRecursive(int depth, DirContext context, Map<String, String> recursiveMap, Set<String> recursiveSet,
                                 String groupName, String groupDName) throws NamingException {
    if (containerLog.isTraceEnabled())
        containerLog.trace("Recursive search depth " + depth + " for group '" + groupDName + " (" + groupName + ")'");
    // Adding the given group to the result set if not already found
    if (!recursiveSet.contains(groupDName)) {
        recursiveSet.add(groupDName);
        recursiveMap.put(groupDName, groupName);
        if (depth >= roleRecursionLimit) {
            if (roleRecursionLimit > 0)
                containerLog.warn("Terminating recursive role search because of recursion limit " +
                                  roleRecursionLimit + ", results might be incomplete");
            return;
        }
        // Prepare the parameters for searching groups
        String filter = roleFormat.format(new String[] { groupDName });
        SearchControls controls = new SearchControls();
        controls.setSearchScope(roleSubtree ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE);
        controls.setReturningAttributes(new String[] { roleName });
        if (containerLog.isTraceEnabled()) {
            containerLog.trace("Recursive search in role base '" + roleBase + "' for attribute '" + roleName + "'" +
                               " with filter expression '" + filter + "'");
        }
        // Searching groups that assign the given group
        NamingEnumeration results = context.search(roleBase, filter, controls);
        if (results != null) {
            // Iterate over the resulting groups
            try {
                while (results.hasMore()) {
                    SearchResult result = (SearchResult) results.next();
                    Attributes attrs = result.getAttributes();
                    if (attrs == null)
                        continue;
                    String dname = getDistinguishedName(context, roleBase, result);
                    String name = getAttributeValue(roleName, attrs);
                    if (name != null && dname != null) {
                       getRolesRecursive(depth+1, context, recursiveMap, recursiveSet, name, dname);
                    }
                }
            } catch (PartialResultException ex) {
                if (!adCompat)
                    throw ex;
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:63,代码来源:JNDIRealm.java

示例14: moreLdapInjections

import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
public static void moreLdapInjections(String input) throws NamingException {
    //Stub instances
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    props.put(Context.PROVIDER_URL, "ldap://ldap.example.com");
    props.put(Context.REFERRAL, "ignore");

    SearchControls ctrls = new SearchControls();
    ctrls.setReturningAttributes(new String[]{"givenName", "sn"});
    ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    //Various context instance store in various type (class or interface)
    DirContext         context1 = new InitialDirContext(props);
    InitialDirContext  context2 = new InitialDirContext(props);
    InitialLdapContext context3 = new InitialLdapContext();
    LdapContext        context4 = new InitialLdapContext();

    NamingEnumeration<SearchResult> answers;
    answers = context1.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context1.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context1.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context1.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);

    answers = context2.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context2.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context2.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context2.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);

    answers = context3.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context3.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context3.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context3.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);

    answers = context4.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context4.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context4.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context4.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);


    //False positive
    answers = context1.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=bob)", ctrls);
    answers = context1.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=bob)", new Object[0], ctrls);
    answers = context1.search("dc=People,dc=example,dc=com", "(uid=bob)", ctrls);
    answers = context1.search("dc=People,dc=example,dc=com", "(uid=bob)", new Object[0], ctrls);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:46,代码来源:JndiLdapAdditionalSignature.java


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