當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。