use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.
the class AclReports method getMatchingResources.
private ArrayList<DavResource> getMatchingResources(DavContext ctxt, Element query) throws DavException, ServiceException {
// needs to be /principals/users, or apply-to-principal-collection-set is set.
ArrayList<DavResource> ret = new ArrayList<DavResource>();
boolean applyToPrincipalCollection = query.element(DavElements.E_APPLY_TO_PRINCIPAL_COLLECTION_SET) != null;
String path = ctxt.getUri();
if (!applyToPrincipalCollection && !path.startsWith(UrlNamespace.PRINCIPALS_PATH))
return ret;
// apple hack to do user / resource search
GalSearchType type = GalSearchType.all;
String queryType = query.attributeValue("type");
if (queryType != null) {
if (queryType.compareToIgnoreCase("INDIVIDUAL") == 0)
type = GalSearchType.account;
else if (queryType.compareToIgnoreCase("RESOURCE") == 0)
type = GalSearchType.resource;
}
@SuppressWarnings("unchecked") List propSearch = query.elements(DavElements.E_PROPERTY_SEARCH);
for (Object obj : propSearch) {
if (!(obj instanceof Element))
continue;
Element ps = (Element) obj;
Element prop = ps.element(DavElements.E_PROP);
Element match = ps.element(DavElements.E_MATCH);
if (prop != null && match != null) {
Element e = (Element) prop.elements().get(0);
ret.addAll(getMatchingPrincipals(ctxt, e.getQName(), match.getText(), type));
}
}
return ret;
}
use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.
the class AutoCompleteGal method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(getZimbraSoapContext(context));
if (!canAccessAccount(zsc, account))
throw ServiceException.PERM_DENIED("can not access account");
String name = request.getAttribute(AccountConstants.E_NAME);
String typeStr = request.getAttribute(AccountConstants.A_TYPE, "account");
GalSearchType type = GalSearchType.fromString(typeStr);
boolean needCanExpand = request.getAttributeBool(AccountConstants.A_NEED_EXP, false);
String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
GalSearchParams params = new GalSearchParams(account, zsc);
params.setType(type);
params.setRequest(request);
params.setQuery(name);
params.setLimit(account.getContactAutoCompleteMaxResults());
params.setNeedCanExpand(needCanExpand);
params.setResponseName(AccountConstants.AUTO_COMPLETE_GAL_RESPONSE);
if (galAcctId != null) {
Account galAccount = Provisioning.getInstance().getAccountById(galAcctId);
if (galAccount != null && (!account.getDomainId().equals(galAccount.getDomainId()))) {
throw ServiceException.PERM_DENIED("can not access galsync account of different domain");
}
params.setGalSyncAccount(galAccount);
}
GalSearchControl gal = new GalSearchControl(params);
gal.autocomplete();
return params.getResultCallback().getResponse();
}
use of com.zimbra.soap.type.GalSearchType 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.soap.type.GalSearchType in project zm-mailbox by Zimbra.
the class SearchGal method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
String domainName = request.getAttribute(AdminConstants.A_DOMAIN);
Provisioning prov = Provisioning.getInstance();
Domain domain = prov.get(Key.DomainBy.name, domainName);
if (domain == null)
throw AccountServiceException.NO_SUCH_DOMAIN(domainName);
checkDomainRight(zsc, domain, Admin.R_accessGAL);
String name = request.getAttribute(AdminConstants.E_NAME, "");
int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, 0);
String typeStr = request.getAttribute(AdminConstants.A_TYPE, GalSearchType.account.name());
GalSearchType type = GalSearchType.fromString(typeStr);
String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
String token = request.getAttribute(AdminConstants.A_TOKEN, null);
GalSearchParams params = new GalSearchParams(domain, zsc);
if (token != null)
params.setToken(token);
params.setType(type);
params.setRequest(request);
params.setQuery(name);
params.setLimit(limit);
params.setResponseName(AdminConstants.SEARCH_GAL_RESPONSE);
if (galAcctId != null)
params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
params.setResultCallback(new SearchGal.AdminGalCallback(params));
GalSearchControl gal = new GalSearchControl(params);
if (token != null)
gal.sync();
else
gal.search();
return params.getResultCallback().getResponse();
}
use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.
the class GalSearchControl method generateSearchQuery.
private void generateSearchQuery(Account galAcct) throws ServiceException {
String query = mParams.getQuery();
String searchByDn = mParams.getSearchEntryByDn();
GalSearchType type = mParams.getType();
StringBuilder searchQuery = new StringBuilder();
if (searchByDn != null) {
searchQuery.append("#dn:(" + searchByDn + ")");
} else if (!Strings.isNullOrEmpty(query)) {
searchQuery.append("contact:\"");
// escape quotes
searchQuery.append(query.replace("\"", "\\\""));
searchQuery.append("\" AND");
}
GalSearchQueryCallback queryCallback = mParams.getExtraQueryCallback();
if (queryCallback != null) {
String extraQuery = queryCallback.getMailboxSearchQuery();
if (extraQuery != null) {
ZimbraLog.gal.debug("extra search query: " + extraQuery);
searchQuery.append(" (").append(extraQuery).append(") AND");
}
}
GalMode galMode = mParams.getDomain().getGalMode();
boolean first = true;
for (DataSource ds : galAcct.getAllDataSources()) {
if (ds.getType() != DataSourceType.gal)
continue;
String galType = ds.getAttr(Provisioning.A_zimbraGalType);
if (galMode == GalMode.ldap && galType.compareTo("zimbra") == 0)
continue;
if (galMode == GalMode.zimbra && galType.compareTo("ldap") == 0)
continue;
if (first)
searchQuery.append("(");
else
searchQuery.append(" OR");
first = false;
searchQuery.append(" inid:").append(ds.getFolderId());
}
if (!first)
searchQuery.append(")");
switch(type) {
case resource:
searchQuery.append(" AND #zimbraAccountCalendarUserType:RESOURCE");
break;
case group:
searchQuery.append(" AND #type:group");
break;
case account:
searchQuery.append(" AND !(#zimbraAccountCalendarUserType:RESOURCE)");
break;
case all:
break;
}
ZimbraLog.gal.debug("query: %s", searchQuery);
mParams.parseSearchParams(mParams.getRequest(), searchQuery.toString());
}
Aggregations