Search in sources :

Example 11 with SearchAccountsOptions

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

the class FixCalendarTZ method getAccountsOnServer.

private static List<NamedEntry> getAccountsOnServer() throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Server server = prov.getLocalServer();
    String serverName = server.getAttr(Provisioning.A_zimbraServiceHostname);
    SearchAccountsOptions searchOpts = new SearchAccountsOptions(new String[] { Provisioning.A_zimbraId });
    searchOpts.setSortOpt(SortOpt.SORT_DESCENDING);
    List<NamedEntry> accts = prov.searchAccountsOnServer(server, searchOpts);
    ZimbraLog.calendar.info("Found " + accts.size() + " accounts on server " + serverName);
    return accts;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) Server(com.zimbra.cs.account.Server) Provisioning(com.zimbra.cs.account.Provisioning)

Example 12 with SearchAccountsOptions

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

the class GetAggregateQuotaUsageOnServer method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    if (!AccessControlUtil.isGlobalAdmin(getAuthenticatedAccount(zsc))) {
        throw ServiceException.PERM_DENIED("only global admin is allowed");
    }
    Map<String, Long> domainAggrQuotaUsed = new HashMap<String, Long>();
    SearchAccountsOptions searchOpts = new SearchAccountsOptions();
    searchOpts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
    searchOpts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    Provisioning prov = Provisioning.getInstance();
    List<NamedEntry> accounts = prov.searchAccountsOnServer(prov.getLocalServer(), searchOpts);
    Map<String, Long> acctQuotaUsed = MailboxManager.getInstance().getMailboxSizes(accounts);
    for (NamedEntry ne : accounts) {
        if (!(ne instanceof Account)) {
            continue;
        }
        Account acct = (Account) ne;
        Long acctQuota = acctQuotaUsed.get(acct.getId());
        if (acctQuota == null) {
            acctQuota = 0L;
        }
        String domainId = acct.getDomainId();
        if (domainId == null) {
            continue;
        }
        Long aggrQuota = domainAggrQuotaUsed.get(domainId);
        domainAggrQuotaUsed.put(domainId, aggrQuota == null ? acctQuota : aggrQuota + acctQuota);
    }
    Element response = zsc.createElement(AdminConstants.GET_AGGR_QUOTA_USAGE_ON_SERVER_RESPONSE);
    for (String domainId : domainAggrQuotaUsed.keySet()) {
        Domain domain = prov.getDomainById(domainId);
        Element domainElt = response.addElement(AdminConstants.E_DOMAIN);
        domainElt.addAttribute(AdminConstants.A_NAME, domain.getName());
        domainElt.addAttribute(AdminConstants.A_ID, domainId);
        domainElt.addAttribute(AdminConstants.A_QUOTA_USED, domainAggrQuotaUsed.get(domainId));
    }
    return response;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Account(com.zimbra.cs.account.Account) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning)

Example 13 with SearchAccountsOptions

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

the class LdapProvisioning method getAllAccounts.

@Override
public void getAllAccounts(Domain domain, Server server, NamedEntry.Visitor visitor) throws ServiceException {
    if (server != null) {
        SearchAccountsOptions searchOpts = new SearchAccountsOptions(domain);
        searchOpts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
        searchAccountsOnServerInternal(server, searchOpts, visitor);
    } else {
        getAllAccounts(domain, visitor);
    }
}
Also used : SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions)

Example 14 with SearchAccountsOptions

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

the class LdapProvisioning method countAccount.

@Override
public CountAccountResult countAccount(Domain domain) throws ServiceException {
    CountAccountVisitor visitor = new CountAccountVisitor(this);
    SearchAccountsOptions option = new SearchAccountsOptions(domain, new String[] { Provisioning.A_zimbraCOSId, Provisioning.A_zimbraIsSystemResource });
    option.setIncludeType(IncludeType.ACCOUNTS_ONLY);
    option.setFilter(mDIT.filterAccountsOnlyByDomain(domain));
    searchDirectoryInternal(option, visitor);
    return visitor.getResult();
}
Also used : SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions)

Example 15 with SearchAccountsOptions

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

the class ExternalUserProvServlet method provisionVirtualAccountAndRedirect.

private static void provisionVirtualAccountAndRedirect(HttpServletRequest req, HttpServletResponse resp, String displayName, String password, String grantorId, String extUserEmail) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    try {
        Account owner = prov.getAccountById(grantorId);
        Domain domain = prov.getDomain(owner);
        Account grantee = prov.getAccountByName(mapExtEmailToAcctName(extUserEmail, domain));
        if (grantee != null) {
            throw AccountServiceException.ACCOUNT_EXISTS(extUserEmail);
        }
        // search all shares accessible to the external user
        SearchAccountsOptions searchOpts = new SearchAccountsOptions(domain, new String[] { Provisioning.A_zimbraId, Provisioning.A_displayName, Provisioning.A_zimbraSharedItem });
        // get all groups extUserEmail belongs to
        GuestAccount guestAcct = new GuestAccount(extUserEmail, null);
        List<String> groupIds = prov.getGroupMembership(guestAcct, false).groupIds();
        List<String> grantees = Lists.newArrayList(extUserEmail);
        grantees.addAll(groupIds);
        searchOpts.setFilter(ZLdapFilterFactory.getInstance().accountsByGrants(grantees, false, false));
        List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
        if (accounts.isEmpty()) {
            throw AccountServiceException.NO_SHARE_EXISTS();
        }
        // create external account
        Map<String, Object> attrs = new HashMap<String, Object>();
        attrs.put(Provisioning.A_zimbraIsExternalVirtualAccount, ProvisioningConstants.TRUE);
        attrs.put(Provisioning.A_zimbraExternalUserMailAddress, extUserEmail);
        attrs.put(Provisioning.A_zimbraMailHost, prov.getLocalServer().getServiceHostname());
        if (!StringUtil.isNullOrEmpty(displayName)) {
            attrs.put(Provisioning.A_displayName, displayName);
        }
        attrs.put(Provisioning.A_zimbraHideInGal, ProvisioningConstants.TRUE);
        attrs.put(Provisioning.A_zimbraMailStatus, Provisioning.MailStatus.disabled.toString());
        if (!StringUtil.isNullOrEmpty(password)) {
            attrs.put(Provisioning.A_zimbraVirtualAccountInitialPasswordSet, ProvisioningConstants.TRUE);
        }
        // create external account mailbox
        Mailbox granteeMbox;
        try {
            grantee = prov.createAccount(mapExtEmailToAcctName(extUserEmail, domain), password, attrs);
            granteeMbox = MailboxManager.getInstance().getMailboxByAccount(grantee);
        } catch (ServiceException e) {
            // the next attempt
            if (grantee != null) {
                prov.deleteAccount(grantee.getId());
            }
            throw e;
        }
        // create mountpoints
        Set<MailItem.Type> viewTypes = new HashSet<MailItem.Type>();
        for (NamedEntry ne : accounts) {
            Account account = (Account) ne;
            String[] sharedItems = account.getSharedItem();
            for (String sharedItem : sharedItems) {
                ShareInfoData shareData = AclPushSerializer.deserialize(sharedItem);
                if (!granteeMatchesShare(shareData, grantee)) {
                    continue;
                }
                String sharedFolderPath = shareData.getPath();
                String mountpointName = getMountpointName(account, grantee, sharedFolderPath);
                MailItem.Type viewType = shareData.getFolderDefaultViewCode();
                Mountpoint mtpt = granteeMbox.createMountpoint(null, getMptParentFolderId(viewType, prov), mountpointName, account.getId(), shareData.getItemId(), shareData.getItemUuid(), viewType, 0, MailItem.DEFAULT_COLOR, false);
                if (viewType == MailItem.Type.APPOINTMENT) {
                    // make sure that the mountpoint is checked in the UI by default
                    granteeMbox.alterTag(null, mtpt.getId(), mtpt.getType(), Flag.FlagInfo.CHECKED, true, null);
                }
                viewTypes.add(viewType);
            }
        }
        enableAppFeatures(grantee, viewTypes);
        setCookieAndRedirect(req, resp, grantee);
    } catch (ServiceException e) {
        ZimbraLog.account.debug("Exception while creating virtual account for %s", extUserEmail, e);
        throw e;
    } catch (Exception e) {
        ZimbraLog.account.debug("Exception while creating virtual account for %s", extUserEmail, e);
        throw ServiceException.TEMPORARILY_UNAVAILABLE();
    }
}
Also used : GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) GuestAccount(com.zimbra.cs.account.GuestAccount) HashMap(java.util.HashMap) ShareInfoData(com.zimbra.cs.account.ShareInfoData) Provisioning(com.zimbra.cs.account.Provisioning) ServletException(javax.servlet.ServletException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) AuthTokenException(com.zimbra.cs.account.AuthTokenException) NamedEntry(com.zimbra.cs.account.NamedEntry) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Domain(com.zimbra.cs.account.Domain) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) HashSet(java.util.HashSet)

Aggregations

SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)19 NamedEntry (com.zimbra.cs.account.NamedEntry)12 Account (com.zimbra.cs.account.Account)9 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)7 Provisioning (com.zimbra.cs.account.Provisioning)5 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)5 Server (com.zimbra.cs.account.Server)4 ServiceException (com.zimbra.common.service.ServiceException)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 Domain (com.zimbra.cs.account.Domain)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ZMailbox (com.zimbra.client.ZMailbox)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 Element (com.zimbra.common.soap.Element)1 AddressList (com.zimbra.cs.account.AddressList)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 CalendarResource (com.zimbra.cs.account.CalendarResource)1 DistributionList (com.zimbra.cs.account.DistributionList)1