本文整理汇总了Java中javax.naming.directory.SearchControls.setCountLimit方法的典型用法代码示例。如果您正苦于以下问题:Java SearchControls.setCountLimit方法的具体用法?Java SearchControls.setCountLimit怎么用?Java SearchControls.setCountLimit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.directory.SearchControls
的用法示例。
在下文中一共展示了SearchControls.setCountLimit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import javax.naming.directory.SearchControls; //导入方法依赖的package包/类
public List<LdapEntryVO> search(final Integer limit, String... filterArgs) {
SearchControls searchControls = new SearchControls();
Integer defaultLimit;
if (limit != null) {
if (limit >= 0) {
searchControls.setCountLimit(limit);
} else {
searchControls.setCountLimit(0l);
}
} else if ((defaultLimit = Settings.getIntNullable(SettingCodes.LDAP_ENTRIES_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
DefaultSettings.LDAP_ENTRIES_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT)) != null) {
if (defaultLimit >= 0) {
searchControls.setCountLimit(defaultLimit);
} else {
searchControls.setCountLimit(0l);
}
} else {
searchControls.setCountLimit(0l);
}
return ldapTemplate.search(getBase(), getSearchFilter(filterArgs), searchControls, getAttributeMapper());
}
示例2: 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);
}
}
示例3: 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;
}
示例4: 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;
}