本文整理汇总了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();
}
示例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));
}
示例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;
}
示例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();
}
示例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);
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例11: safe1
import javax.naming.directory.SearchControls; //导入依赖的package包/类
public void safe1() {
new SearchControls(scope,
countLimit, timeLimit,
attributes,
false, //OK
deref);
}
示例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);
}
示例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;
}
示例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));
}
});
}
示例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;
}