use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.
the class SearchCalendarResources method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, Integer.MAX_VALUE);
if (limit == 0)
limit = Integer.MAX_VALUE;
int offset = (int) request.getAttributeLong(AdminConstants.A_OFFSET, 0);
String domain = request.getAttribute(AdminConstants.A_DOMAIN, null);
boolean applyCos = request.getAttributeBool(AdminConstants.A_APPLY_COS, true);
String sortBy = request.getAttribute(AdminConstants.A_SORT_BY, null);
boolean sortAscending = request.getAttributeBool(AdminConstants.A_SORT_ASCENDING, true);
String attrsStr = request.getAttribute(AdminConstants.A_ATTRS, null);
String[] attrs = attrsStr == null ? null : attrsStr.split(",");
EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
// Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager
if (isDomainAdminOnly(zsc)) {
if (domain == null) {
domain = getAuthTokenAccountDomain(zsc).getName();
} else {
checkDomainRight(zsc, domain, AdminRight.PR_ALWAYS_ALLOW);
}
}
Domain d = null;
if (domain != null) {
d = prov.get(Key.DomainBy.name, domain);
if (d == null)
throw AccountServiceException.NO_SUCH_DOMAIN(domain);
}
AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
AdminAccessControl.SearchDirectoryRightChecker rightChecker = new AdminAccessControl.SearchDirectoryRightChecker(aac, prov, null);
// filter is not RFC 2254 escaped
// query is RFC 2254 escaped
String query = LdapEntrySearchFilter.toLdapCalendarResourcesFilter(filter);
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setDomain(d);
options.setTypes(SearchDirectoryOptions.ObjectType.resources);
options.setFilterString(FilterId.ADMIN_SEARCH, query);
options.setReturnAttrs(attrs);
options.setSortOpt(sortAscending ? SortOpt.SORT_ASCENDING : SortOpt.SORT_DESCENDING);
options.setSortAttr(sortBy);
options.setConvertIDNToAscii(true);
List<NamedEntry> resources;
int limitMax = offset + limit;
AdminSession session = (AdminSession) getSession(zsc, Session.Type.ADMIN);
if (session != null) {
resources = session.searchDirectory(options, offset, rightChecker);
} else {
resources = prov.searchDirectory(options);
resources = rightChecker.getAllowed(resources, limitMax);
}
Element response = zsc.createElement(AdminConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
int numEntries;
for (numEntries = offset; numEntries < limitMax && numEntries < resources.size(); numEntries++) {
NamedEntry entry = resources.get(numEntries);
ToXML.encodeCalendarResource(response, (CalendarResource) entry, applyCos, null, aac.getAttrRightChecker(entry));
}
response.addAttribute(AdminConstants.A_MORE, numEntries < resources.size());
response.addAttribute(AdminConstants.A_SEARCH_TOTAL, resources.size());
return response;
}
use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.
the class SearchGal method searchGal.
private static Element searchGal(ZimbraSoapContext zsc, Account account, Element request) throws ServiceException {
// if searhc by ref is requested, honor it
String ref = request.getAttribute(AccountConstants.A_REF, null);
// otherwise require a query
String name = null;
if (ref == null) {
name = request.getAttribute(AccountConstants.E_NAME);
}
EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
String typeStr = request.getAttribute(AccountConstants.A_TYPE, "all");
GalSearchType type = GalSearchType.fromString(typeStr);
boolean needCanExpand = request.getAttributeBool(AccountConstants.A_NEED_EXP, false);
boolean needIsOwner = request.getAttributeBool(AccountConstants.A_NEED_IS_OWNER, false);
MemberOfSelector needIsMember = MemberOfSelector.fromString(request.getAttribute(AccountConstants.A_NEED_IS_MEMBER, MemberOfSelector.none.name()));
// internal attr, for proxied GSA search from GetSMIMEPublicCerts only
boolean needSMIMECerts = request.getAttributeBool(AccountConstants.A_NEED_SMIME_CERTS, false);
String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
GalSearchParams params = new GalSearchParams(account, zsc);
if (ref == null) {
params.setQuery(name);
} else {
// search GAL by ref, which is a dn
params.setSearchEntryByDn(ref);
}
params.setType(type);
params.setRequest(request);
params.setNeedCanExpand(needCanExpand);
params.setNeedIsOwner(needIsOwner);
params.setNeedIsMember(needIsMember);
params.setNeedSMIMECerts(needSMIMECerts);
params.setResponseName(AccountConstants.SEARCH_GAL_RESPONSE);
if (galAcctId != null) {
params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
}
if (filter != null) {
params.setExtraQueryCallback(new SearchGalExtraQueryCallback(filter));
}
// also note that mailbox search has a hard limit of 1000
if (request.getAttribute(MailConstants.A_QUERY_LIMIT, null) == null) {
request.addAttribute(MailConstants.A_QUERY_LIMIT, 100);
}
/* do not support specified attrs yet
String attrsStr = request.getAttribute(AccountConstants.A_ATTRS, null);
String[] attrs = attrsStr == null ? null : attrsStr.split(",");
Set<String> attrsSet = attrs == null ? null : new HashSet<String>(Arrays.asList(attrs));
*/
params.setResultCallback(new SearchGalResultCallback(params, filter, null));
GalSearchControl gal = new GalSearchControl(params);
gal.search();
return params.getResultCallback().getResponse();
}
use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.
the class LdapEntrySearchFilter method toLdapIDNFilter.
/**
* Takes a RFC 2254 filter and converts assertions value from unicode to ACE
* for IDN attributes. IDN attributes are those storing the ACE representation
* of the unicode. For non-IDN attributes, assertion values are just passed through.
*
* e.g.
* (zimbraMailDeliveryAddress=*@test.中文.com) will be converted to
* (zimbraMailDeliveryAddress=*@test.xn--fiq228c.com)
* because zimbraMailDeliveryAddress is an IDN attribute.
*
* (zimbraDomainName=*中文*) will remain the same because zimbraDomainName
* is not an IDN attribute.
*
* @param filterStr a RFC 2254 filter (assertion values must be already RFC 2254 escaped)
* @return
*/
public static String toLdapIDNFilter(String filterStr) {
String asciiQuery;
try {
Term term = LdapFilterParser.parse(filterStr);
EntrySearchFilter filter = new EntrySearchFilter(term);
asciiQuery = toLdapIDNFilter(filter);
ZimbraLog.account.debug("original query=[" + filterStr + "], converted ascii query=[" + asciiQuery + "]");
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to convert query to ascii, using original query: " + filterStr, e);
asciiQuery = filterStr;
}
return asciiQuery;
}
use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.
the class SearchCalendarResources method searchGal.
private static Element searchGal(ZimbraSoapContext zsc, Account account, Element request) throws ServiceException {
Element name = request.getOptionalElement(AccountConstants.E_NAME);
EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
GalSearchParams params = new GalSearchParams(account, zsc);
params.setQuery(name == null ? null : name.getText());
if (filter != null) {
params.setExtraQueryCallback(new CalendarResourceExtraQueryCallback(filter));
}
params.setType(GalSearchType.resource);
params.setRequest(request);
params.setResponseName(AccountConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
// also note that mailbox search has a hard limit of 1000
if (request.getAttribute(MailConstants.A_QUERY_LIMIT, null) == null)
request.addAttribute(MailConstants.A_QUERY_LIMIT, 100);
// set limit for the LDAP search
// paging is not supported for LDAP search, set a high limit
params.setLimit(LC.calendar_resource_ldap_search_maxsize.intValue());
String attrsStr = request.getAttribute(AccountConstants.A_ATTRS, null);
String[] attrs = attrsStr == null ? null : attrsStr.split(",");
Set<String> attrsSet = attrs == null ? null : new HashSet<String>(Arrays.asList(attrs));
params.setResultCallback(new CalendarResourceGalSearchResultCallback(params, filter, attrsSet));
GalSearchControl gal = new GalSearchControl(params);
gal.search();
return params.getResultCallback().getResponse();
}
use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.
the class GalExtraSearchFilter method parseSearchFilter.
public static EntrySearchFilter parseSearchFilter(Element request) throws ServiceException {
Element filterElem = request.getOptionalElement(AccountConstants.E_ENTRY_SEARCH_FILTER);
if (filterElem == null) {
return null;
}
Element termElem = filterElem.getOptionalElement(AccountConstants.E_ENTRY_SEARCH_FILTER_MULTICOND);
if (termElem == null)
termElem = filterElem.getElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
Term term = GalExtraSearchFilter.parseFilterTermElem(termElem);
EntrySearchFilter filter = new EntrySearchFilter(term);
return filter;
}
Aggregations