use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetAllConfig method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Config config = prov.getConfig();
AdminAccessControl aac = checkRight(zsc, context, config, AdminRight.PR_ALWAYS_ALLOW);
Element response = zsc.createElement(AdminConstants.GET_ALL_CONFIG_RESPONSE);
encodeConfig(response, config, null, aac.getAttrRightChecker(config));
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ExportAndDeleteItems method handle.
@Override
public Element handle(Element requst, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
// Parse request.
ExportAndDeleteItemsRequest req = zsc.elementToJaxb(requst);
ExportAndDeleteMailboxSpec mailbox = req.getMailbox();
if (mailbox == null) {
throw ServiceException.INVALID_REQUEST("empty mbox id", null);
}
Mailbox mbox = MailboxManager.getInstance().getMailboxById(mailbox.getId());
Multimap<Integer, Integer> idRevs = HashMultimap.create();
for (ExportAndDeleteItemSpec item : mailbox.getItems()) {
idRevs.put(item.getId(), item.getVersion());
}
String dirPath = req.getExportDir();
String prefix = req.getExportFilenamePrefix();
// Lock the mailbox, to make sure that another thread doesn't modify the items we're exporting/deleting.
mbox.lock.lock();
try {
DbConnection conn = null;
try {
conn = DbPool.getConnection();
if (dirPath != null) {
File exportDir = new File(dirPath);
if (!exportDir.isDirectory()) {
DbPool.quietClose(conn);
throw ServiceException.INVALID_REQUEST(dirPath + " is not a directory", null);
}
String filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM, prefix);
export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM, "id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, prefix);
export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, "id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_REVISION, prefix);
export(conn, mbox, DbMailItem.TABLE_REVISION, "item_id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_REVISION_DUMPSTER, prefix);
export(conn, mbox, DbMailItem.TABLE_REVISION_DUMPSTER, "item_id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT, prefix);
export(conn, mbox, DbMailItem.TABLE_APPOINTMENT, "item_id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, prefix);
export(conn, mbox, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, "item_id", idRevs, filePath);
}
// delete item from mail_item and revision table
for (Integer itemId : idRevs.keySet()) {
Collection<Integer> revs = idRevs.get(itemId);
for (int rev : revs) {
if (rev == 0) {
// delete all revisions to make sure we delete all blobs
List<MailItem> list = null;
try {
list = mbox.getAllRevisions(null, itemId, MailItem.Type.UNKNOWN);
} catch (NoSuchItemException ex) {
// exception happens when we try to delete a mail_item which is already in mail_item_dumpster
continue;
}
for (MailItem item : list) {
if (item.getType() == MailItem.Type.DOCUMENT) {
mbox.purgeRevision(null, itemId, item.getVersion(), false);
}
}
mbox.delete(null, itemId, MailItem.Type.UNKNOWN, null);
break;
} else if (!revs.contains(0)) {
try {
mbox.purgeRevision(null, itemId, rev, false);
} catch (NoSuchItemException ex) {
// exception happens when we try to delete a revision which is already in revision_dumpster
continue;
}
}
}
}
// Delete items from mail_item_dumpster & revision_dumpster tables just
// incase moved to dumpster tables
DbBlobConsistency.delete(conn, mbox, idRevs);
} finally {
conn.commit();
DbPool.quietClose(conn);
}
} finally {
mbox.lock.release();
}
return zsc.createElement(AdminConstants.EXPORT_AND_DELETE_ITEMS_RESPONSE);
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class CreateGalSyncAccount method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
CreateGalSyncAccountRequest cgaRequest = zsc.elementToJaxb(request);
String name = cgaRequest.getName();
String domainStr = cgaRequest.getDomain();
GalMode type = cgaRequest.getType();
AccountSelector acctSelector = cgaRequest.getAccount();
AccountBy acctBy = acctSelector.getBy();
String acctValue = acctSelector.getKey();
String password = cgaRequest.getPassword();
String folder = cgaRequest.getFolder();
String mailHost = cgaRequest.getMailHost();
Domain domain = prov.getDomainByName(domainStr);
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
}
Account account = null;
try {
account = prov.get(acctBy.toKeyAccountBy(), acctValue, zsc.getAuthToken());
} catch (ServiceException se) {
ZimbraLog.gal.warn("error checking GalSyncAccount", se);
}
// create the system account if not already exists.
if (account == null) {
if (acctBy != AccountBy.name) {
throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
}
// there should be one gal sync account per domain per mailhost
for (String acctId : domain.getGalAccountId()) {
Account acct = prov.getAccountById(acctId);
if ((acct != null) && (acct.getMailHost().equals(mailHost))) {
throw AccountServiceException.ACCOUNT_EXISTS(acct.getName());
}
}
// XXX revisit
checkDomainRightByEmail(zsc, acctValue, Admin.R_createAccount);
Map<String, Object> accountAttrs = new HashMap<String, Object>();
StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraIsSystemResource, LdapConstants.LDAP_TRUE);
StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraIsSystemAccount, LdapConstants.LDAP_TRUE);
StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraHideInGal, LdapConstants.LDAP_TRUE);
StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraContactMaxNumEntries, "0");
StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraMailHost, mailHost);
checkSetAttrsOnCreate(zsc, TargetType.account, acctValue, accountAttrs);
account = prov.createAccount(acctValue, password, accountAttrs);
}
if (!Provisioning.onLocalServer(account)) {
String host = account.getMailHost();
Server server = prov.getServerByName(host);
return proxyRequest(request, context, server);
}
addDataSource(request, zsc, account, domain, folder, name, type);
Element response = zsc.createElement(AdminConstants.CREATE_GAL_SYNC_ACCOUNT_RESPONSE);
ToXML.encodeAccount(response, account, false, emptySet, null);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class CreateSystemRetentionPolicy method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
CreateSystemRetentionPolicyRequest req = zsc.elementToJaxb(request);
Provisioning prov = Provisioning.getInstance();
// assume default retention policy to be set in globalConfig (for backward compatibility)
Entry entry = prov.getConfig();
// check if cos is specified
CosSelector cosSelector = req.getCos();
if (cosSelector != null) {
entry = prov.get(Key.CosBy.fromString(cosSelector.getBy().name()), cosSelector.getKey());
if (entry == null)
throw AccountServiceException.NO_SUCH_COS(cosSelector.getKey());
}
// check right
checkSetRight(entry, zsc, context, this);
Policy keep = req.getKeepPolicy();
Policy purge = req.getPurgePolicy();
if (keep == null && purge == null) {
throw ServiceException.INVALID_REQUEST("No keep or purge policy specified.", null);
}
if (keep != null && purge != null) {
throw ServiceException.INVALID_REQUEST("Cannot specify both keep and purge policy.", null);
}
Policy newPolicy;
if (keep != null) {
newPolicy = RetentionPolicyManager.getInstance().createSystemKeepPolicy(entry, keep.getName(), keep.getLifetime());
} else {
newPolicy = RetentionPolicyManager.getInstance().createSystemPurgePolicy(entry, purge.getName(), purge.getLifetime());
}
CreateSystemRetentionPolicyResponse res = new CreateSystemRetentionPolicyResponse(newPolicy);
return zsc.jaxbToElement(res);
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class AdminDocumentHandler method proxyIfNecessary.
@Override
protected Element proxyIfNecessary(Element request, Map<String, Object> context) throws ServiceException {
// if we've explicitly been told to execute here, don't proxy
ZimbraSoapContext zsc = getZimbraSoapContext(context);
if (zsc.getProxyTarget() != null)
return null;
try {
Provisioning prov = Provisioning.getInstance();
Provisioning.Reasons reasons = new Provisioning.Reasons();
// check whether we need to proxy to the home server of a target account
String[] xpath = getProxiedAccountPath();
String acctId = (xpath != null ? getXPath(request, xpath) : null);
if (acctId != null) {
Account acct = getAccount(prov, AccountBy.id, acctId, zsc.getAuthToken());
if (acct != null && !Provisioning.onLocalServer(acct, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedAccountPath=%s reason: %s", Joiner.on("/").join(xpath), reasons.getReason());
return proxyRequest(request, context, acctId);
}
}
xpath = getProxiedAccountElementPath();
Element acctElt = (xpath != null ? getXPathElement(request, xpath) : null);
if (acctElt != null) {
Account acct = getAccount(prov, AccountBy.fromString(acctElt.getAttribute(AdminConstants.A_BY)), acctElt.getText(), zsc.getAuthToken());
if (acct != null && !Provisioning.onLocalServer(acct, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedAccountElementPath=%s acctElt=%s reason: %s", Joiner.on("/").join(xpath), acctElt.toString(), reasons.getReason());
return proxyRequest(request, context, acct.getId());
}
}
// check whether we need to proxy to the home server of a target calendar resource
xpath = getProxiedResourcePath();
String rsrcId = (xpath != null ? getXPath(request, xpath) : null);
if (rsrcId != null) {
CalendarResource rsrc = getCalendarResource(prov, Key.CalendarResourceBy.id, rsrcId);
if (rsrc != null && !Provisioning.onLocalServer(rsrc, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedResourcePath=%s rsrcId=%s reason: %s", Joiner.on("/").join(xpath), rsrcId, reasons.getReason());
return proxyRequest(request, context, rsrcId);
}
}
xpath = getProxiedResourceElementPath();
Element resourceElt = (xpath != null ? getXPathElement(request, xpath) : null);
if (resourceElt != null) {
CalendarResource rsrc = getCalendarResource(prov, Key.CalendarResourceBy.fromString(resourceElt.getAttribute(AdminConstants.A_BY)), resourceElt.getText());
if (rsrc != null && !Provisioning.onLocalServer(rsrc, reasons)) {
ZimbraLog.soap.info("Proxying request: ProxiedResourceElementPath=%s resourceElt=%s reason: %s", Joiner.on("/").join(xpath), resourceElt.toString(), reasons.getReason());
return proxyRequest(request, context, rsrc.getId());
}
}
// check whether we need to proxy to a target server
xpath = getProxiedServerPath();
String serverId = (xpath != null ? getXPath(request, xpath) : null);
if (serverId != null) {
Server server = prov.get(Key.ServerBy.id, serverId);
if (server != null && !getLocalHostId().equalsIgnoreCase(server.getId())) {
ZimbraLog.soap.info("Proxying request: ProxiedServerPath=%s serverId=%s server=%s reason: server ID=%s != localHostId=%s", Joiner.on("/").join(xpath), serverId, server.getName(), server.getId(), getLocalHostId());
return proxyRequest(request, context, server);
}
}
return null;
} catch (ServiceException e) {
// if something went wrong proxying the request, just execute it locally
if (ServiceException.PROXY_ERROR.equals(e.getCode()))
return null;
// but if it's a real error, it's a real error
throw e;
}
}
Aggregations