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;
}
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;
}
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);
}
}
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();
}
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();
}
}
Aggregations