Search in sources :

Example 26 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 27 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)

Example 28 with SearchDirectoryOptions

use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllDistributionLists.

@Override
public List<?> getAllDistributionLists(Domain domain) throws ServiceException {
    SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(domain);
    searchOpts.setFilter(mDIT.filterDistributionListsByDomain(domain));
    searchOpts.setTypes(ObjectType.distributionlists);
    searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
    return searchDirectoryInternal(searchOpts);
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions)

Example 29 with SearchDirectoryOptions

use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllCalendarResources.

@Override
public List<?> getAllCalendarResources(Domain domain) throws ServiceException {
    SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(domain);
    searchOpts.setFilter(mDIT.filterCalendarResourcesByDomain(domain));
    searchOpts.setTypes(ObjectType.resources);
    searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
    return searchDirectoryInternal(searchOpts);
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions)

Example 30 with SearchDirectoryOptions

use of com.zimbra.cs.account.SearchDirectoryOptions in project zm-mailbox by Zimbra.

the class BUG_66387 method searchAndFixAccounts.

private int searchAndFixAccounts() throws ServiceException {
    String[] attrsToGet = new String[] { Provisioning.A_zimbraAllowFromAddress };
    SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(attrsToGet);
    searchOpts.setTypes(SearchDirectoryOptions.ObjectType.accounts, SearchDirectoryOptions.ObjectType.resources);
    searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
    searchOpts.setSortAttr(Provisioning.A_zimbraMailDeliveryAddress);
    searchOpts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    searchOpts.setFilterString(FilterId.LDAP_UPGRADE, "(" + Provisioning.A_zimbraAllowFromAddress + "=*)");
    List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
    for (int i = 0; i < accounts.size(); ++i) {
        NamedEntry entry = accounts.get(i);
        if (entry instanceof Account) {
            Account acct = (Account) entry;
            fixAccount(acct.getName(), acct.getAllowFromAddress());
        }
    }
    return accounts.size();
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) Account(com.zimbra.cs.account.Account)

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