Search in sources :

Example 61 with ZimbraSoapContext

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;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) GetDataSourcesRequest(com.zimbra.soap.admin.message.GetDataSourcesRequest) DataSource(com.zimbra.cs.account.DataSource)

Example 62 with ZimbraSoapContext

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;
}
Also used : Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) Entry(com.zimbra.cs.account.Entry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AttributeConstraint(com.zimbra.cs.account.accesscontrol.AttributeConstraint) Map(java.util.Map)

Example 63 with ZimbraSoapContext

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;
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) DistributionListBy(com.zimbra.common.account.Key.DistributionListBy) Element(com.zimbra.common.soap.Element) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) GetDistributionListRequest(com.zimbra.soap.admin.message.GetDistributionListRequest) AttrRightChecker(com.zimbra.cs.account.AccessManager.AttrRightChecker) Entry(com.zimbra.cs.account.Entry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DistributionList(com.zimbra.cs.account.DistributionList)

Example 64 with ZimbraSoapContext

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;
}
Also used : Server(com.zimbra.cs.account.Server) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) SummaryItem(com.zimbra.cs.rmgmt.RemoteMailQueue.SummaryItem) RemoteMailQueue(com.zimbra.cs.rmgmt.RemoteMailQueue) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) QueueAttr(com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr)

Example 65 with ZimbraSoapContext

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;
}
Also used : Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AdminSession(com.zimbra.cs.session.AdminSession) Element(com.zimbra.common.soap.Element)

Aggregations

ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)382 Element (com.zimbra.common.soap.Element)315 Provisioning (com.zimbra.cs.account.Provisioning)162 Account (com.zimbra.cs.account.Account)158 Mailbox (com.zimbra.cs.mailbox.Mailbox)106 OperationContext (com.zimbra.cs.mailbox.OperationContext)82 ItemId (com.zimbra.cs.service.util.ItemId)58 Server (com.zimbra.cs.account.Server)47 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)44 ServiceException (com.zimbra.common.service.ServiceException)40 HashMap (java.util.HashMap)37 Domain (com.zimbra.cs.account.Domain)32 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)23 IOException (java.io.IOException)20 Group (com.zimbra.cs.account.Group)17 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)17 Message (com.zimbra.cs.mailbox.Message)17 MimeMessage (javax.mail.internet.MimeMessage)16 Map (java.util.Map)15