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


Java SearchControls类代码示例

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


SearchControls类属于javax.naming.directory包,在下文中一共展示了SearchControls类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: doTestGetGroups

import javax.naming.directory.SearchControls; //导入依赖的package包/类
private void doTestGetGroups(List<String> expectedGroups, int searchTimes) throws IOException, NamingException {  
  Configuration conf = new Configuration();
  // Set this, so we don't throw an exception
  conf.set(LdapGroupsMapping.LDAP_URL_KEY, "ldap://test");
  
  mappingSpy.setConf(conf);
  // Username is arbitrary, since the spy is mocked to respond the same,
  // regardless of input
  List<String> groups = mappingSpy.getGroups("some_user");
  
  Assert.assertEquals(expectedGroups, groups);
  
  // We should have searched for a user, and then two groups
  verify(mockContext, times(searchTimes)).search(anyString(),
                                       anyString(),
                                       any(Object[].class),
                                       any(SearchControls.class));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:TestLdapGroupsMapping.java

示例3: toSearchParams

import javax.naming.directory.SearchControls; //导入依赖的package包/类
/**
 * Creates a {@link SearchParams} from JNDI search controls.
 *
 * @param searchControls the search controls
 * @param aliasDerefMode the alias deref mode
 * @return the search params
 */
public static SearchParams toSearchParams( SearchControls searchControls, AliasDerefMode aliasDerefMode )
{
    SearchParams searchParams = new SearchParams();

    searchParams.setAliasDerefMode( aliasDerefMode );
    searchParams.setTimeLimit( searchControls.getTimeLimit() );
    searchParams.setSizeLimit( searchControls.getCountLimit() );
    searchParams.setScope( SearchScope.getSearchScope( searchControls.getSearchScope() ) );
    searchParams.setTypesOnly( searchControls.getReturningObjFlag() );

    if ( searchControls.getReturningAttributes() != null )
    {
        for ( String returningAttribute : searchControls.getReturningAttributes() )
        {
            searchParams.addReturningAttributes( returningAttribute );
        }
    }

    return searchParams;
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:28,代码来源:SearchParams.java

示例4: ContextEnumerator

import javax.naming.directory.SearchControls; //导入依赖的package包/类
protected ContextEnumerator(Context context, int scope, String contextName,
                         boolean returnSelf)
    throws NamingException {
    if(context == null) {
        throw new IllegalArgumentException("null context passed");
    }

    root = context;

    // No need to list children if we're only searching object
    if (scope != SearchControls.OBJECT_SCOPE) {
        children = getImmediateChildren(context);
    }
    this.scope = scope;
    this.contextName = contextName;
    // pretend root is processed, if we're not supposed to return ourself
    rootProcessed = !returnSelf;
    prepNextChild();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:ContextEnumerator.java

示例5: setup

import javax.naming.directory.SearchControls; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
    bean = spy(new LdapAccessServiceBean());
    dcMock = mock(DirContext.class);
    neMock = mock(NamingEnumeration.class);
    srMock = mock(SearchResult.class);
    aMock = mock(Attributes.class);

    doReturn(new Integer(5)).when(bean).getSearchLimit();
    doReturn(dcMock).when(bean).getDirContext(any(Properties.class));

    when(dcMock.search(anyString(), anyString(), any(SearchControls.class)))
            .thenReturn(neMock);

    when(Boolean.valueOf(neMock.hasMore())).thenReturn(Boolean.TRUE,
            Boolean.FALSE);
    when(neMock.next()).thenReturn(srMock);
    when(srMock.getAttributes()).thenReturn(aMock);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:LdapAccessServiceBeanTest.java

示例6: queryVulnerableToInjection

import javax.naming.directory.SearchControls; //导入依赖的package包/类
public void queryVulnerableToInjection(LdapTemplate template, String jndiInjectMe, SearchControls searchControls, DirContextProcessor dirContextProcessor) throws NamingException {
    template.list(jndiInjectMe);
    template.list(jndiInjectMe, new DefaultNameClassPairMapper());
    template.list(jndiInjectMe, new CountNameClassPairCallbackHandler());

    template.lookup(jndiInjectMe);
    template.lookup(jndiInjectMe, new DefaultIncrementalAttributesMapper());
    template.lookup(jndiInjectMe, new LdapEntryIdentificationContextMapper());

    template.search(jndiInjectMe,"dn=1",searchControls,new CountNameClassPairCallbackHandler());
    template.search(jndiInjectMe,"dn=1",searchControls,new DefaultIncrementalAttributesMapper(), dirContextProcessor);
    template.search(jndiInjectMe,"dn=1",searchControls,new LdapEntryIdentificationContextMapper(),dirContextProcessor);
    template.search(jndiInjectMe,"dn=1",searchControls,new CountNameClassPairCallbackHandler(),dirContextProcessor);
    template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,true,new CountNameClassPairCallbackHandler());
    template.search(jndiInjectMe,"dn=1",new CountNameClassPairCallbackHandler());
    template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new String[0],new DefaultIncrementalAttributesMapper());
    template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new DefaultIncrementalAttributesMapper());
    template.search(jndiInjectMe,"dn=1",new DefaultIncrementalAttributesMapper());
    template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new String[0],new LdapEntryIdentificationContextMapper());
    template.search(jndiInjectMe,"dn=1",SearchControls.OBJECT_SCOPE,new LdapEntryIdentificationContextMapper());
    template.search(jndiInjectMe,"dn=1",new LdapEntryIdentificationContextMapper());
    template.search(jndiInjectMe,"dn=1",searchControls,new LdapEntryIdentificationContextMapper());
    template.search(jndiInjectMe,"dn=1",searchControls, new DefaultIncrementalAttributesMapper());
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:25,代码来源:SpringLdap.java

示例7: addNamingListener

import javax.naming.directory.SearchControls; //导入依赖的package包/类
/**
 * Adds {@code l} to list of listeners interested in {@code nm}
 * and filter.
 */
synchronized void addNamingListener(String nm, String filter,
    SearchControls ctls, NamingListener l) throws NamingException {

    if (l instanceof ObjectChangeListener ||
        l instanceof NamespaceChangeListener) {
        NotifierArgs args = new NotifierArgs(nm, filter, ctls, l);

        NamingEventNotifier notifier = notifiers.get(args);
        if (notifier == null) {
            notifier = new NamingEventNotifier(this, ctx, args, l);
            notifiers.put(args, notifier);
        } else {
            notifier.addNamingListener(l);
        }
    }
    if (l instanceof UnsolicitedNotificationListener) {
        // Add listener to this's list of unsolicited notifiers
        if (unsolicited == null) {
            unsolicited = new Vector<>(3);
        }
        unsolicited.addElement((UnsolicitedNotificationListener)l);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:EventSupport.java

示例8: addNamingListener

import javax.naming.directory.SearchControls; //导入依赖的package包/类
/**
 * Adds <tt>l</tt> to list of listeners interested in <tt>nm</tt>
 * and filter.
 */
synchronized void addNamingListener(String nm, String filter,
    SearchControls ctls, NamingListener l) throws NamingException {

    if (l instanceof ObjectChangeListener ||
        l instanceof NamespaceChangeListener) {
        NotifierArgs args = new NotifierArgs(nm, filter, ctls, l);

        NamingEventNotifier notifier = notifiers.get(args);
        if (notifier == null) {
            notifier = new NamingEventNotifier(this, ctx, args, l);
            notifiers.put(args, notifier);
        } else {
            notifier.addNamingListener(l);
        }
    }
    if (l instanceof UnsolicitedNotificationListener) {
        // Add listener to this's list of unsolicited notifiers
        if (unsolicited == null) {
            unsolicited = new Vector<>(3);
        }
        unsolicited.addElement((UnsolicitedNotificationListener)l);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:EventSupport.java

示例9: testGetGroups

import javax.naming.directory.SearchControls; //导入依赖的package包/类
@Test
public void testGetGroups() throws IOException, NamingException {
  // The search functionality of the mock context is reused, so we will
  // return the user NamingEnumeration first, and then the group
  when(mockContext.search(anyString(), anyString(), any(Object[].class),
      any(SearchControls.class)))
      .thenReturn(mockUserNamingEnum, mockGroupNamingEnum);
  
  doTestGetGroups(Arrays.asList(testGroups), 2);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:11,代码来源:TestLdapGroupsMapping.java

示例10: 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

示例11: safe1

import javax.naming.directory.SearchControls; //导入依赖的package包/类
public void safe1() {
    new SearchControls(scope,
            countLimit, timeLimit,
            attributes,
            false, //OK
            deref);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:8,代码来源:LdapEntryPoisoning.java

示例12: search

import javax.naming.directory.SearchControls; //导入依赖的package包/类
public NamingEnumeration<SearchResult> search(String name,
                            String filterExpr,
                            Object[] args,
                            SearchControls cons)
throws NamingException {
    DirContextStringPair res = getTargetContext(name);
    return res.getDirContext().search(res.getString(), filterExpr, args,
                                     cons);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:ContinuationDirContext.java

示例13: mockDirContext

import javax.naming.directory.SearchControls; //导入依赖的package包/类
private DirContext mockDirContext(NamingEnumeration<SearchResult> namingEnumeration)
        throws NamingException {
    DirContext dirContext = EasyMock.createNiceMock(InitialDirContext.class);
    EasyMock.expect(dirContext.search(EasyMock.anyString(), EasyMock.anyString(),
                    EasyMock.anyObject(SearchControls.class)))
            .andReturn(namingEnumeration)
            .times(2);
    EasyMock.expect(dirContext.getNameParser(""))
            .andReturn(new NameParserImpl()).times(2);
    EasyMock.expect(dirContext.getNameInNamespace())
            .andReturn("ANY NAME")
            .times(2);
    EasyMock.replay(dirContext);
    return dirContext;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:TestJNDIRealm.java

示例14: search

import javax.naming.directory.SearchControls; //导入依赖的package包/类
@Override
public List<SearchResult> search(LDAPSettings settings, final String base, final String filter,
	final SearchControls ctls)
{
	return new LDAP(settings, encryptionService).doAsAdmin(new InContext<List<SearchResult>>()
	{
		@Override
		public List<SearchResult> execute(DirContext ctx) throws NamingException
		{
			return Collections.list(ctx.search(base, filter, ctls));
		}
	});
}
 
开发者ID:equella,项目名称:Equella,代码行数:14,代码来源:LDAPServiceImpl.java

示例15: 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


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