use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method testFilterWithCharsNeedEscaping.
private void testFilterWithCharsNeedEscaping(Account expected, String filterAttr, String filterValue) throws Exception {
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setDomain(prov.getDomain(expected));
options.setTypes(SearchDirectoryOptions.ObjectType.accounts);
options.setFilterString(FilterId.UNITTEST, String.format("(%s=%s)", filterAttr, filterValue));
options.setReturnAttrs(new String[] { Provisioning.A_zimbraMailDeliveryAddress });
options.setConvertIDNToAscii(true);
List<NamedEntry> entries = prov.searchDirectory(options);
Verify.verifyEquals(Lists.newArrayList(expected), entries, true);
}
use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method testBadFilter.
private void testBadFilter(String filter) throws Exception {
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setTypes(SearchDirectoryOptions.ObjectType.accounts);
options.setFilterString(FilterId.UNITTEST, filter);
options.setReturnAttrs(new String[] { Provisioning.A_zimbraId });
options.setConvertIDNToAscii(true);
String errorCode = null;
try {
prov.searchDirectory(options);
} catch (ServiceException e) {
errorCode = e.getCode();
}
assertEquals(LdapException.INVALID_SEARCH_FILTER, errorCode);
}
use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.
the class FolderAction method revokeOrphanGrants.
private void revokeOrphanGrants(OperationContext octxt, Mailbox mbox, ItemId iid, String granteeId, byte gtype) throws ServiceException {
// check if the grantee still exists
SearchDirectoryOptions opts = new SearchDirectoryOptions();
if (gtype == ACL.GRANTEE_USER) {
opts.addType(SearchDirectoryOptions.ObjectType.accounts);
opts.addType(SearchDirectoryOptions.ObjectType.resources);
} else if (gtype == ACL.GRANTEE_GROUP) {
opts.addType(SearchDirectoryOptions.ObjectType.distributionlists);
} else if (gtype == ACL.GRANTEE_COS) {
opts.addType(SearchDirectoryOptions.ObjectType.coses);
} else if (gtype == ACL.GRANTEE_DOMAIN) {
opts.addType(SearchDirectoryOptions.ObjectType.domains);
} else {
throw ServiceException.INVALID_REQUEST("invalid grantee type for revokeOrphanGrants", null);
}
String query = "(" + Provisioning.A_zimbraId + "=" + granteeId + ")";
opts.setFilterString(FilterId.SEARCH_GRANTEE, query);
// search the grantee on LDAP master
opts.setOnMaster(true);
List<NamedEntry> entries = Provisioning.getInstance().searchDirectory(opts);
if (entries.size() != 0) {
throw ServiceException.INVALID_REQUEST("grantee " + granteeId + " exists", null);
}
// the grantee indeed does not exist, revoke all grants granted to the grantee
// in this folder and all subfolders
FolderNode rootNode = mbox.getFolderTree(octxt, iid, true);
revokeOrphanGrants(octxt, mbox, rootNode, granteeId, gtype);
}
use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.
the class LdapProvisioning method renameDomain.
// LdapProv
@Override
public void renameDomain(String zimbraId, String newDomainName) throws ServiceException {
newDomainName = newDomainName.toLowerCase().trim();
newDomainName = IDNUtil.toAsciiDomainName(newDomainName);
NameUtil.validNewDomainName(newDomainName);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_DOMAIN);
RenameDomain.RenameDomainLdapHelper helper = new RenameDomain.RenameDomainLdapHelper(this, zlc) {
private ZLdapContext toZLdapContext() {
return LdapClient.toZLdapContext(mProv, mZlc);
}
@Override
public void createEntry(String dn, Map<String, Object> attrs) throws ServiceException {
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(attrs);
entry.setDN(dn);
ZLdapContext ldapContext = toZLdapContext();
ldapContext.createEntry(entry);
}
@Override
public void deleteEntry(String dn) throws ServiceException {
ZLdapContext ldapContext = toZLdapContext();
ldapContext.deleteEntry(dn);
}
@Override
public void renameEntry(String oldDn, String newDn) throws ServiceException {
ZLdapContext ldapContext = toZLdapContext();
ldapContext.renameEntry(oldDn, newDn);
}
@Override
public void searchDirectory(SearchDirectoryOptions options, NamedEntry.Visitor visitor) throws ServiceException {
((LdapProvisioning) mProv).searchDirectory(options, visitor);
}
@Override
public void renameAddressesInAllDistributionLists(Map<String, String> changedPairs) {
((LdapProvisioning) mProv).renameAddressesInAllDistributionLists(changedPairs);
}
@Override
public void renameXMPPComponent(String zimbraId, String newName) throws ServiceException {
((LdapProvisioning) mProv).renameXMPPComponent(zimbraId, newName);
}
@Override
public Account getAccountById(String id) throws ServiceException {
// note: we do NOT want to get a cached entry
return ((LdapProvisioning) mProv).getAccountByQuery(mProv.getDIT().mailBranchBaseDN(), ZLdapFilterFactory.getInstance().accountById(id), toZLdapContext(), true);
}
@Override
public DistributionList getDistributionListById(String id) throws ServiceException {
// note: we do NOT want to get a cahed entry
return ((LdapProvisioning) mProv).getDistributionListByQuery(mDIT.mailBranchBaseDN(), filterFactory.distributionListById(id), toZLdapContext(), false);
}
@Override
public DynamicGroup getDynamicGroupById(String id) throws ServiceException {
// note: we do NOT want to get a cahed entry
return ((LdapProvisioning) mProv).getDynamicGroupByQuery(filterFactory.dynamicGroupById(id), toZLdapContext(), false);
}
@Override
public void modifyLdapAttrs(Entry entry, Map<String, ? extends Object> attrs) throws ServiceException {
((LdapProvisioning) mProv).modifyLdapAttrs(entry, toZLdapContext(), attrs);
}
};
Domain oldDomain = getDomainById(zimbraId, zlc);
if (oldDomain == null)
throw AccountServiceException.NO_SUCH_DOMAIN(zimbraId);
RenameDomain rd = new RenameDomain(this, helper, oldDomain, newDomainName);
rd.execute();
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllDomains.
@Override
public void getAllDomains(NamedEntry.Visitor visitor, String[] retAttrs) throws ServiceException {
SearchDirectoryOptions opts = new SearchDirectoryOptions(retAttrs);
opts.setFilter(filterFactory.allDomains());
opts.setTypes(ObjectType.domains);
searchDirectoryInternal(opts, visitor);
}
Aggregations