Search in sources :

Example 21 with SearchDirectoryOptions

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);
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry)

Example 22 with SearchDirectoryOptions

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);
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Example 23 with SearchDirectoryOptions

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);
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) FolderNode(com.zimbra.cs.mailbox.Mailbox.FolderNode)

Example 24 with SearchDirectoryOptions

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);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) NamedEntry(com.zimbra.cs.account.NamedEntry) GroupedEntry(com.zimbra.cs.account.GroupedEntry) AliasedEntry(com.zimbra.cs.account.AliasedEntry) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) Entry(com.zimbra.cs.account.Entry) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 25 with SearchDirectoryOptions

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);
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions)

Aggregations

SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)30 NamedEntry (com.zimbra.cs.account.NamedEntry)19 Account (com.zimbra.cs.account.Account)11 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)9 Domain (com.zimbra.cs.account.Domain)8 DistributionList (com.zimbra.cs.account.DistributionList)7 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)5 Provisioning (com.zimbra.cs.account.Provisioning)4 Element (com.zimbra.common.soap.Element)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 DynamicGroup (com.zimbra.cs.account.DynamicGroup)3 AdminSession (com.zimbra.cs.session.AdminSession)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ServiceException (com.zimbra.common.service.ServiceException)2 Alias (com.zimbra.cs.account.Alias)2 CalendarResource (com.zimbra.cs.account.CalendarResource)2 LdapDistributionList (com.zimbra.cs.account.ldap.entry.LdapDistributionList)2