Search in sources :

Example 36 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetAdminConsoleUIComp method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetAdminConsoleUICompRequest req = zsc.elementToJaxb(request);
    AccountSelector accountSel = req.getAccount();
    DistributionListSelector dlSel = req.getDl();
    Element resp = zsc.createElement(AdminConstants.GET_ADMIN_CONSOLE_UI_COMP_RESPONSE);
    if ((null != accountSel) && (null != dlSel)) {
        throw ServiceException.INVALID_REQUEST("can only specify eith account or dl", null);
    }
    Account authedAcct = getAuthenticatedAccount(zsc);
    Set<String> added = new HashSet<String>();
    GroupMembership aclGroups = null;
    if (accountSel != null) {
        AccountBy by = accountSel.getBy().toKeyAccountBy();
        String key = accountSel.getKey();
        Account acct = prov.get(by, key);
        AccountHarvestingCheckerUsingCheckRight checker = new AccountHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewAccountAdminUI);
        if (acct == null) {
            defendAgainstAccountHarvestingWhenAbsent(by, key, zsc, checker);
        } else {
            if (!authedAcct.getId().equals(acct.getId())) {
                defendAgainstAccountHarvesting(acct, by, key, zsc, checker);
            }
            addValues(acct, resp, added, false);
            aclGroups = prov.getGroupMembership(acct, true);
        }
    } else if (dlSel != null) {
        Key.DistributionListBy by = dlSel.getBy().toKeyDistributionListBy();
        String key = dlSel.getKey();
        DistributionList dl = prov.getDLBasic(by, key);
        GroupHarvestingCheckerUsingCheckRight checker = new GroupHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewDistributionListAdminUI);
        if (dl == null) {
            defendAgainstGroupHarvestingWhenAbsent(by, key, zsc, checker);
        } else {
            defendAgainstGroupHarvesting(dl, by, key, zsc, checker);
            addValues(dl, resp, added, false);
            aclGroups = prov.getGroupMembership(dl, true);
        }
    } else {
        // use the authed account
        addValues(authedAcct, resp, added, false);
        aclGroups = prov.getGroupMembership(authedAcct, true);
    }
    if (aclGroups != null) {
        for (String groupId : aclGroups.groupIds()) {
            DistributionList dl = prov.get(Key.DistributionListBy.id, groupId);
            addValues(dl, resp, added, true);
        }
    }
    return resp;
}
Also used : Account(com.zimbra.cs.account.Account) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) GroupMembership(com.zimbra.cs.account.Provisioning.GroupMembership) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetAdminConsoleUICompRequest(com.zimbra.soap.admin.message.GetAdminConsoleUICompRequest) HashSet(java.util.HashSet) DistributionList(com.zimbra.cs.account.DistributionList)

Example 37 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetAdminSavedSearches method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account acct = getRequestedAccount(zsc);
    checkAccountRight(zsc, acct, Admin.R_viewAdminSavedSearch);
    Element response = zsc.createElement(AdminConstants.GET_ADMIN_SAVED_SEARCHES_RESPONSE);
    HashSet<String> specificSearches = null;
    for (Iterator it = request.elementIterator(AdminConstants.E_SEARCH); it.hasNext(); ) {
        if (specificSearches == null)
            specificSearches = new HashSet<String>();
        Element e = (Element) it.next();
        String name = e.getAttribute(AdminConstants.A_NAME);
        if (name != null)
            specificSearches.add(name);
    }
    handle(acct, response, specificSearches);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 38 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetAllAccountLoggers 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_manageAccountLogger);
    Provisioning prov = Provisioning.getInstance();
    Map<String, Element> accountElements = new HashMap<String, Element>();
    Element response = zsc.createElement(AdminConstants.GET_ALL_ACCOUNT_LOGGERS_RESPONSE);
    for (AccountLogger al : LogFactory.getAllAccountLoggers()) {
        // Look up account
        Account account = prov.get(AccountBy.name, al.getAccountName(), zsc.getAuthToken());
        if (account == null) {
            ZimbraLog.misc.info("GetAllAccountLoggers: unable to find account '%s'.  Ignoring account logger.", al.getAccountName());
            continue;
        }
        // Add elements
        Element eAccountLogger = accountElements.get(account.getId());
        if (eAccountLogger == null) {
            eAccountLogger = response.addElement(AdminConstants.E_ACCOUNT_LOGGER);
            accountElements.put(account.getId(), eAccountLogger);
        }
        eAccountLogger.addAttribute(AdminConstants.A_ID, account.getId());
        eAccountLogger.addAttribute(AdminConstants.A_NAME, account.getName());
        Element eLogger = eAccountLogger.addElement(AdminConstants.E_LOGGER);
        eLogger.addAttribute(AdminConstants.A_CATEGORY, al.getCategory());
        eLogger.addAttribute(AdminConstants.A_LEVEL, al.getLevel().toString());
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) HashMap(java.util.HashMap) AccountLogger(com.zimbra.common.util.AccountLogger) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 39 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetAllActiveServers method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
    Element response = zsc.createElement(AdminConstants.GET_ALL_ACTIVE_SERVERS_RESPONSE);
    CuratorManager curator = CuratorManager.getInstance();
    if (curator == null) {
        return response;
    }
    Set<String> serverIds;
    try {
        serverIds = curator.getActiveServers();
    } catch (Exception e) {
        throw ServiceException.FAILURE("error while getting active servers", e);
    }
    Provisioning prov = Provisioning.getInstance();
    List<Server> servers = new ArrayList<Server>();
    for (String serverId : serverIds) {
        Server server = prov.getServerById(serverId);
        servers.add(server);
    }
    AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
    for (Iterator<Server> it = servers.iterator(); it.hasNext(); ) {
        Server server = it.next();
        if (aac.hasRightsToList(server, Admin.R_listServer, null))
            GetServer.encodeServer(response, server, true, null, aac.getAttrRightChecker(server));
    }
    return response;
}
Also used : Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) CuratorManager(com.zimbra.cs.zookeeper.CuratorManager) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 40 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetAllAlwaysOnClusters method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    List<AlwaysOnCluster> clusters = prov.getAllAlwaysOnClusters();
    AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
    Element response = zsc.createElement(AdminConstants.GET_ALL_ALWAYSONCLUSTERS_RESPONSE);
    for (Iterator<AlwaysOnCluster> it = clusters.iterator(); it.hasNext(); ) {
        AlwaysOnCluster cluster = it.next();
        if (aac.hasRightsToList(cluster, Admin.R_listAlwaysOnCluster, null))
            GetAlwaysOnCluster.encodeAlwaysOnCluster(response, cluster, null, aac.getAttrRightChecker(cluster));
    }
    return response;
}
Also used : AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)410 Element (com.zimbra.common.soap.Element)322 Account (com.zimbra.cs.account.Account)175 Provisioning (com.zimbra.cs.account.Provisioning)164 Mailbox (com.zimbra.cs.mailbox.Mailbox)126 OperationContext (com.zimbra.cs.mailbox.OperationContext)95 ItemId (com.zimbra.cs.service.util.ItemId)60 Server (com.zimbra.cs.account.Server)48 ServiceException (com.zimbra.common.service.ServiceException)43 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)43 HashMap (java.util.HashMap)42 Domain (com.zimbra.cs.account.Domain)34 ArrayList (java.util.ArrayList)27 HashSet (java.util.HashSet)26 IOException (java.io.IOException)24 Test (org.junit.Test)20 Message (com.zimbra.cs.mailbox.Message)18 Group (com.zimbra.cs.account.Group)17 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)17 MimeMessage (javax.mail.internet.MimeMessage)16