use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetDataSources method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetDataSourcesRequest req = JaxbUtil.elementToJaxb(request);
String id = req.getId();
Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
defendAgainstAccountOrCalendarResourceHarvesting(account, AccountBy.id, id, zsc, Admin.R_adminLoginAs, Admin.R_adminLoginCalendarResourceAs);
Element response = zsc.createElement(AdminConstants.GET_DATA_SOURCES_RESPONSE);
List<DataSource> sources = Provisioning.getInstance().getAllDataSources(account);
for (DataSource ds : sources) {
com.zimbra.cs.service.account.ToXML.encodeDataSource(response, ds);
}
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetDelegatedAdminConstraints method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Entry entry = getEntry(request);
AdminAccessControl.GetAttrsRight gar = new AdminAccessControl.GetAttrsRight();
gar.addAttr(Provisioning.A_zimbraConstraint);
checkRight(zsc, context, entry, gar);
Map<String, AttributeConstraint> constraints = AttributeConstraint.getConstraint(entry);
Element response = zsc.createElement(AdminConstants.GET_DELEGATED_ADMIN_CONSTRAINTS_RESPONSE);
// return constraints for requested attrs
boolean hasRequestedAttrs = false;
for (Element a : request.listElements(AdminConstants.E_A)) {
hasRequestedAttrs = true;
String attrName = a.getAttribute(AdminConstants.A_NAME);
AttributeConstraint ac = constraints.get(attrName);
if (ac != null) {
Element eAttr = response.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_NAME, attrName);
ac.toXML(eAttr);
}
}
// no attr is specifically requested, return all
if (!hasRequestedAttrs) {
for (Map.Entry<String, AttributeConstraint> cons : constraints.entrySet()) {
String attrName = cons.getKey();
AttributeConstraint ac = cons.getValue();
Element eAttr = response.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_NAME, attrName);
ac.toXML(eAttr);
}
}
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetDistributionList method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
GetDistributionListRequest req = JaxbUtil.elementToJaxb(request);
int limit = (req.getLimit() == null) ? 0 : req.getLimit();
if (limit < 0) {
throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
}
int offset = (req.getOffset() == null) ? 0 : req.getOffset();
if (offset < 0) {
throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
}
boolean sortAscending = !Boolean.FALSE.equals(req.isSortAscending());
Set<String> reqAttrs = getReqAttrs(req.getAttrs(), AttributeClass.distributionList);
DistributionListSelector dlSel = req.getDl();
DistributionListBy dlBy = dlSel.getBy().toKeyDistributionListBy();
AttrRightChecker arc = null;
Group group = getGroupFromContext(context);
if (group == null) {
if (DistributionListBy.name.equals(dlBy)) {
Entry pseudoTarget = pseudoTargetInSameDomainAsEmail(TargetType.dl, dlSel.getKey());
if (null != pseudoTarget) {
AdminAccessControl aac = checkDistributionListRight(zsc, (DistributionList) pseudoTarget, AdminRight.PR_ALWAYS_ALLOW);
arc = aac.getAttrRightChecker(pseudoTarget);
}
}
if (arc != null) {
defendAgainstGroupHarvestingWhenAbsent(dlBy, dlSel.getKey(), zsc, new GroupHarvestingCheckerUsingGetAttrsPerms(zsc, arc, Arrays.asList(minimumAttrs)));
} else {
defendAgainstGroupHarvestingWhenAbsent(dlBy, dlSel.getKey(), zsc, Admin.R_getDistributionList);
}
} else if (group.isDynamic()) {
AdminAccessControl aac = checkDynamicGroupRight(zsc, (DynamicGroup) group, AdminRight.PR_ALWAYS_ALLOW);
arc = aac.getAttrRightChecker(group);
} else {
AdminAccessControl aac = checkDistributionListRight(zsc, (DistributionList) group, AdminRight.PR_ALWAYS_ALLOW);
arc = aac.getAttrRightChecker(group);
}
defendAgainstGroupHarvesting(group, dlBy, dlSel.getKey(), zsc, new GroupHarvestingCheckerUsingGetAttrsPerms(zsc, arc, Arrays.asList(minimumAttrs)));
Element response = zsc.createElement(AdminConstants.GET_DISTRIBUTION_LIST_RESPONSE);
Element eDL = encodeDistributionList(response, group, true, false, reqAttrs, arc);
// return member info only if the authed has right to see zimbraMailForwardingAddress
boolean allowMembers = true;
if (group.isDynamic()) {
allowMembers = arc == null ? true : arc.allowAttr(Provisioning.A_member);
} else {
allowMembers = arc == null ? true : arc.allowAttr(Provisioning.A_zimbraMailForwardingAddress);
}
if (allowMembers) {
encodeMembers(response, eDL, group, offset, limit, sortAscending);
}
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetMailQueue method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Element serverElem = request.getElement(AdminConstants.E_SERVER);
String serverName = serverElem.getAttribute(AdminConstants.A_NAME);
Server server = prov.get(Key.ServerBy.name, serverName);
if (server == null) {
throw ServiceException.INVALID_REQUEST("server with name " + serverName + " could not be found", null);
}
checkRight(zsc, context, server, Admin.R_manageMailQueue);
Element queueElem = serverElem.getElement(AdminConstants.E_QUEUE);
String queueName = queueElem.getAttribute(AdminConstants.A_NAME);
boolean scan = queueElem.getAttributeBool(AdminConstants.A_SCAN, false);
long waitMillis = (queueElem.getAttributeLong(AdminConstants.A_WAIT, MAIL_QUEUE_SCAN_DEFUALT_WAIT_SECONDS)) * 1000;
Element queryElem = queueElem.getElement(AdminConstants.E_QUERY);
int offset = (int) queryElem.getAttributeLong(AdminConstants.A_OFFSET, 0);
int limit = (int) queryElem.getAttributeLong(AdminConstants.A_LIMIT, MAIL_QUEUE_QUERY_DEFAULT_LIMIT);
Query query = buildLuceneQuery(queryElem);
RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, queueName, scan);
boolean stillScanning = rmq.waitForScan(waitMillis);
RemoteMailQueue.SearchResult sr = rmq.search(query, offset, limit);
Element response = zsc.createElement(AdminConstants.GET_MAIL_QUEUE_RESPONSE);
serverElem = response.addElement(AdminConstants.E_SERVER);
serverElem.addAttribute(AdminConstants.A_NAME, serverName);
queueElem = serverElem.addElement(AdminConstants.E_QUEUE);
queueElem.addAttribute(AdminConstants.A_NAME, queueName);
queueElem.addAttribute(AdminConstants.A_TIME, rmq.getScanTime());
queueElem.addAttribute(AdminConstants.A_SCAN, stillScanning);
queueElem.addAttribute(AdminConstants.A_TOTAL, rmq.getNumMessages());
queueElem.addAttribute(AdminConstants.A_MORE, ((offset + limit) < sr.hits));
for (QueueAttr attr : sr.sitems.keySet()) {
List<SummaryItem> slist = sr.sitems.get(attr);
Collections.sort(slist);
Element qsElem = queueElem.addElement(AdminConstants.A_QUEUE_SUMMARY);
qsElem.addAttribute(AdminConstants.A_TYPE, attr.toString());
int i = 0;
for (SummaryItem sitem : slist) {
i++;
if (i > MAIL_QUEUE_SUMMARY_CUTOFF) {
break;
}
Element qsiElem = qsElem.addElement(AdminConstants.A_QUEUE_SUMMARY_ITEM);
qsiElem.addAttribute(AdminConstants.A_N, sitem.count());
qsiElem.addAttribute(AdminConstants.A_T, sitem.term());
}
}
for (Map<QueueAttr, String> qitem : sr.qitems) {
Element qiElem = queueElem.addElement(AdminConstants.A_QUEUE_ITEM);
for (QueueAttr attr : qitem.keySet()) {
qiElem.addAttribute(attr.toString(), qitem.get(attr));
}
}
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class GetMailboxStats method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Server localServer = Provisioning.getInstance().getLocalServer();
checkRight(zsc, context, localServer, Admin.R_getMailboxStats);
MailboxStats stats = null;
AdminSession session = (AdminSession) getSession(zsc, Session.Type.ADMIN);
if (session != null) {
MailboxStats cachedStats = (MailboxStats) session.getData(GET_MAILBOX_STATS_CACHE_KEY);
if (cachedStats == null) {
stats = doStats();
session.setData(GET_MAILBOX_STATS_CACHE_KEY, stats);
} else {
stats = cachedStats;
}
} else {
stats = doStats();
}
Element response = zsc.createElement(AdminConstants.GET_MAILBOX_STATS_RESPONSE);
Element statsElem = response.addElement(AdminConstants.E_STATS);
statsElem.addAttribute(AdminConstants.A_NUM_MBOXES, stats.mNumMboxes);
statsElem.addAttribute(AdminConstants.A_TOTAL_SIZE, stats.mTotalSize);
return response;
}
Aggregations