use of com.zimbra.soap.account.type.MemberOfSelector 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.account.type.MemberOfSelector in project zm-mailbox by Zimbra.
the class GetAccountDistributionLists method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account acct = getRequestedAccount(zsc);
Provisioning prov = Provisioning.getInstance();
if (!canAccessAccount(zsc, acct)) {
throw ServiceException.PERM_DENIED("can not access account");
}
boolean needOwnerOf = request.getAttributeBool(AccountConstants.A_OWNER_OF, false);
MemberOfSelector needMemberOf = MemberOfSelector.fromString(request.getAttribute(AccountConstants.A_MEMBER_OF, MemberOfSelector.directOnly.name()));
Iterable<String> needAttrs = Splitter.on(',').trimResults().split(request.getAttribute(AccountConstants.A_ATTRS, ""));
Set<Group> ownerOf = null;
List<Group> memberOf = null;
HashMap<String, String> via = new HashMap<String, String>();
if (needOwnerOf) {
ownerOf = Group.GroupOwner.getOwnedGroups(acct);
}
if (MemberOfSelector.none != needMemberOf) {
memberOf = prov.getGroups(acct, MemberOfSelector.directOnly == needMemberOf, via);
}
/*
* merge the two results into one locale-sensitive sorted list
*/
Set<Entry> combined = Sets.newHashSet();
Set<String> combinedIds = Sets.newHashSet();
Set<String> ownerOfGroupIds = Sets.newHashSet();
Set<String> memberOfGroupIds = Sets.newHashSet();
if (ownerOf != null) {
for (Group group : ownerOf) {
String groupId = group.getId();
ownerOfGroupIds.add(groupId);
if (!combinedIds.contains(groupId)) {
combined.add(group);
combinedIds.add(groupId);
}
}
}
if (memberOf != null) {
for (Group group : memberOf) {
String groupId = group.getId();
memberOfGroupIds.add(groupId);
if (!combinedIds.contains(groupId)) {
combined.add(group);
combinedIds.add(groupId);
}
}
}
// sort it
List<Entry> sortedGroups = Entry.sortByDisplayName(combined, acct.getLocale());
Element response = zsc.createElement(AccountConstants.GET_ACCOUNT_DISTRIBUTION_LISTS_RESPONSE);
for (Entry entry : sortedGroups) {
Group group = (Group) entry;
Element eDL = response.addElement(AccountConstants.E_DL);
eDL.addAttribute(AccountConstants.A_NAME, group.getName());
if (group.isDynamic()) {
eDL.addAttribute(AccountConstants.A_REF, ((LdapDynamicGroup) group).getDN());
} else {
eDL.addAttribute(AccountConstants.A_REF, ((LdapDistributionList) group).getDN());
}
eDL.addAttribute(AccountConstants.A_ID, group.getId());
eDL.addAttribute(AccountConstants.A_DISPLAY, group.getDisplayName());
eDL.addAttribute(AccountConstants.A_DYNAMIC, group.isDynamic());
boolean isOwner = ownerOfGroupIds.contains(group.getId());
if (needOwnerOf) {
eDL.addAttribute(AccountConstants.A_IS_OWNER, isOwner);
}
if (MemberOfSelector.none != needMemberOf) {
boolean isMember = memberOfGroupIds.contains(group.getId());
eDL.addAttribute(AccountConstants.A_IS_MEMBER, isMember);
if (isMember) {
String viaDl = via.get(group.getName());
if (viaDl != null) {
eDL.addAttribute(AccountConstants.A_VIA, viaDl);
}
}
}
Set<String> returnAttrs = GetDistributionList.visibleAttrs(needAttrs, isOwner);
if (!returnAttrs.isEmpty()) {
GetDistributionList.encodeAttrs(group, eDL, returnAttrs);
}
}
return response;
}
Aggregations