Package org.springframework.ldap.query
Class LdapQueryBuilder
java.lang.Object
org.springframework.ldap.query.LdapQueryBuilder
- All Implemented Interfaces:
LdapQuery
Builder of LdapQueries. Start with a call to
query()
, proceed with specifying
the basic search configuration (e.g. search base, time limit, etc.), finally specify
the actual query. Example: import static org.springframework.ldap.query.LdapQueryBuilder.query; ... LdapQuery query = query() .base("dc=261consulting, dc=com") .searchScope(SearchScope.ONELEVEL) .timeLimit(200) .countLimit(221) .where("objectclass").is("person").and("cn").is("John Doe");
Default configuration is that base path is
LdapUtils.emptyLdapName()
. All other
parameters are undefined, meaning that (in the case of base search parameters), the
LdapTemplate defaults will be used. Filter conditions must always be specified.
- Since:
- 2.0
- See Also:
-
SearchControls
LdapOperations.search(LdapQuery, org.springframework.ldap.core.AttributesMapper)
LdapOperations.search(LdapQuery, org.springframework.ldap.core.ContextMapper)
LdapOperations.searchForObject(LdapQuery, org.springframework.ldap.core.ContextMapper)
LdapOperations.searchForContext(LdapQuery)
-
Method Summary
Modifier and TypeMethodDescriptionString[]
Get the attributes to return.attributes
(String... attributesToReturn) base()
Get the search base.Set the base search path for the query.Set the base search path for the query.Get the count limit.countLimit
(int countLimit) Set the count limit for the query.filter()
Get the filter.Specify a hardcoded filter.Specify a hardcoded filter using the specified parameters.Specify the filter to use.static LdapQueryBuilder
Construct a newLdapQueryBuilder
based on an existingLdapQuery
All fields are copied, including giving the query a default filter.static LdapQueryBuilder
query()
Construct a new LdapQueryBuilder.Get the search scope.searchScope
(SearchScope searchScope) Set the search scope for the query.Get the time limit.timeLimit
(int timeLimit) Set the time limit for the query.Start specifying the filter conditions in this query.
-
Method Details
-
query
Construct a new LdapQueryBuilder.- Returns:
- a new instance.
-
fromQuery
Construct a newLdapQueryBuilder
based on an existingLdapQuery
All fields are copied, including giving the query a default filter.Note that all filter invariants are still enforced; an application cannot specify any non-filter values after it specifies a filter.
- Returns:
- a new instance.
- Since:
- 3.0
-
base
Set the base search path for the query. Default isLdapUtils.emptyLdapName()
.- Parameters:
baseDn
- the base search path.- Returns:
- this instance.
-
base
Set the base search path for the query. Default isLdapUtils.emptyLdapName()
.- Parameters:
baseDn
- the base search path.- Returns:
- this instance.
-
searchScope
Set the search scope for the query. Default isSearchScope.SUBTREE
.- Parameters:
searchScope
- the search scope.- Returns:
- this instance.
-
countLimit
Set the count limit for the query. Default is 0 (no limit).- Parameters:
countLimit
- the count limit.- Returns:
- this instance.
-
attributes
-
timeLimit
Set the time limit for the query. Default is 0 (no limit).- Parameters:
timeLimit
- the time limit.- Returns:
- this instance.
-
where
Start specifying the filter conditions in this query.- Parameters:
attribute
- The attribute that the first part of the filter should test against.- Returns:
- A ConditionCriteria instance for specifying the compare operation.
- Throws:
IllegalStateException
- if a filter has already been specified.
-
filter
Specify a hardcoded filter. Please note that using this method, the filter string will not be validated or escaped in any way. Never use direct user input and use it concatenating strings to use as LDAP filters. Doing so opens up for "LDAP injection", where malicious user may inject specifically constructed data to form filters at their convenience. When user input is used consider usingwhere(String)
,filter(String, Object...)
, orfilter(Filter)
instead.- Parameters:
hardcodedFilter
- The hardcoded filter string to use in the search.- Returns:
- this instance.
- Throws:
IllegalStateException
- if a filter has already been specified.
-
filter
Specify the filter to use.- Parameters:
filter
- The filter to use in the search.- Returns:
- this instance.
- Throws:
IllegalStateException
- if a filter has already been specified.
-
filter
Specify a hardcoded filter using the specified parameters. The parameters will be properly encoded usingLdapEncoder.filterEncode(String)
to make sure no malicious data gets through. ThefilterFormat
String should be formatted for input toMessageFormat.format(String, Object...)
.- Parameters:
filterFormat
- the filter format string, formatted for input toMessageFormat.format(String, Object...)
.params
- the parameters that will be used for building the final filter. All parameters will be properly encoded.- Returns:
- this instance.
- Throws:
IllegalStateException
- if a filter has already been specified.
-
base
Description copied from interface:LdapQuery
Get the search base. Default isLdapUtils.emptyLdapName()
. -
searchScope
Description copied from interface:LdapQuery
Get the search scope. Default isnull
, indicating that the LdapTemplate default should be used.- Specified by:
searchScope
in interfaceLdapQuery
- Returns:
- the search scope.
-
countLimit
Description copied from interface:LdapQuery
Get the count limit. Default isnull
, indicating that the LdapTemplate default should be used.- Specified by:
countLimit
in interfaceLdapQuery
- Returns:
- the count limit.
-
timeLimit
Description copied from interface:LdapQuery
Get the time limit. Default isnull
, indicating that the LdapTemplate default should be used. -
attributes
Description copied from interface:LdapQuery
Get the attributes to return. Default isnull
, indicating that all attributes should be returned.- Specified by:
attributes
in interfaceLdapQuery
- Returns:
- the attributes to return.
-
filter
Description copied from interface:LdapQuery
Get the filter.
-