Search in sources :

Example 1 with CacheSelector

use of com.zimbra.soap.admin.type.CacheSelector in project zm-mailbox by Zimbra.

the class FlushCache method flushCacheOnImapDaemons.

private static void flushCacheOnImapDaemons(FlushCacheRequest req, ZimbraSoapContext zsc) throws ServiceException {
    CacheSelector selector = req.getCache();
    String cacheTypes = selector.getTypes();
    CacheEntry[] cacheEntries = getCacheEntries(selector);
    Account acct = Provisioning.getInstance().get(AccountBy.id, zsc.getAuthtokenAccountId(), zsc.getAuthToken());
    flushCacheOnImapDaemons(cacheTypes, cacheEntries, acct.getName(), zsc.getAuthToken());
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) Account(com.zimbra.cs.account.Account) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry)

Example 2 with CacheSelector

use of com.zimbra.soap.admin.type.CacheSelector in project zm-mailbox by Zimbra.

the class FlushCache method doFlushCache.

public static void doFlushCache(AdminDocumentHandler handler, Map<String, Object> context, FlushCacheRequest req) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Server localServer = Provisioning.getInstance().getLocalServer();
    handler.checkRight(zsc, context, localServer, Admin.R_flushCache);
    CacheSelector cacheSelector = req.getCache();
    boolean allServers = cacheSelector.isAllServers();
    boolean imapServers = cacheSelector.isIncludeImapServers();
    String[] types = cacheSelector.getTypes().split(",");
    for (String type : types) {
        CacheEntryType cacheType = null;
        try {
            cacheType = CacheEntryType.fromString(type);
            doFlush(context, cacheType, cacheSelector);
        } catch (ServiceException e) {
            if (cacheType == null) {
                // see if it is a registered extension
                CacheExtension ce = CacheExtension.getHandler(type);
                if (ce != null) {
                    ce.flushCache();
                } else {
                    throw e;
                }
            } else {
                throw e;
            }
        }
    }
    if (imapServers) {
        flushCacheOnImapDaemons(req, zsc);
    }
    if (allServers) {
        flushCacheOnAllServers(zsc, req);
    }
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) Server(com.zimbra.cs.account.Server) ServiceException(com.zimbra.common.service.ServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CacheExtension(com.zimbra.cs.account.CacheExtension) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType)

Example 3 with CacheSelector

use of com.zimbra.soap.admin.type.CacheSelector in project zm-mailbox by Zimbra.

the class ImapHandler method doFLUSHCACHE.

private boolean doFLUSHCACHE(String tag, List<CacheEntryType> types, List<CacheEntrySelector> entries) throws IOException {
    if (!checkState(tag, State.AUTHENTICATED)) {
        return true;
    } else if (!checkZimbraAdminAuth()) {
        sendNO(tag, "must be authenticated as admin with X-ZIMBRA auth mechanism");
        return true;
    }
    if (types.isEmpty()) {
        // nothing to do here
        sendOK(tag, "FLUSHCACHE completed");
        return true;
    }
    AuthToken authToken = ((ZimbraAuthenticator) authenticator).getAuthToken();
    try {
        AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(authToken);
        Server localServer = Provisioning.getInstance().getLocalServer();
        aac.checkRight(localServer, Admin.R_flushCache);
    } catch (ServiceException e) {
        if (e.getCode().equalsIgnoreCase(ServiceException.PERM_DENIED)) {
            ZimbraLog.imap.error("insufficient rights for flushing cache on IMAP server", e);
        } else {
            ZimbraLog.imap.error("error while checking rights for flushing cache on IMAP server", e);
        }
        return canContinue(e);
    }
    CacheSelector cacheSelector = new CacheSelector();
    cacheSelector.setEntries(entries);
    for (CacheEntryType type : types) {
        try {
            FlushCache.doFlush(null, type, cacheSelector);
        } catch (ServiceException e) {
            ZimbraLog.imap.error("error flushing cache on IMAP server", e);
            return canContinue(e);
        }
    }
    sendOK(tag, "FLUSHCACHE completed");
    return true;
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) ZimbraAuthenticator(com.zimbra.cs.security.sasl.ZimbraAuthenticator) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) AuthToken(com.zimbra.cs.account.AuthToken) AdminAccessControl(com.zimbra.cs.service.admin.AdminAccessControl) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType)

Example 4 with CacheSelector

use of com.zimbra.soap.admin.type.CacheSelector in project zm-mailbox by Zimbra.

the class SoapProvisioning method flushCache.

public void flushCache(String type, CacheEntry[] entries, boolean allServers, boolean imapDaemons) throws ServiceException {
    CacheSelector sel = new CacheSelector(allServers, type);
    if (entries != null) {
        for (CacheEntry entry : entries) {
            sel.addEntry(new CacheEntrySelector(SoapProvisioning.toJaxb(entry.mEntryBy), entry.mEntryIdentity));
        }
    }
    sel.setIncludeImapServers(imapDaemons);
    invokeJaxb(new FlushCacheRequest(sel));
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) CacheEntrySelector(com.zimbra.soap.admin.type.CacheEntrySelector) FlushCacheRequest(com.zimbra.soap.admin.message.FlushCacheRequest)

Example 5 with CacheSelector

use of com.zimbra.soap.admin.type.CacheSelector in project zm-mailbox by Zimbra.

the class GrantRight method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    GrantRightRequest grReq = zsc.elementToJaxb(request);
    RightModifierInfo modifierInfo = grReq.getRight();
    if (modifierInfo == null) {
        throw ServiceException.INVALID_REQUEST("No information specified on what right to assign", null);
    }
    RightModifier rightModifier = getRightModifier(modifierInfo);
    // right checking is done in RightCommand
    EffectiveRightsTargetSelector erTargSel = grReq.getTarget();
    RightCommand.grantRight(Provisioning.getInstance(), getAuthenticatedAccount(zsc), erTargSel, grReq.getGrantee(), modifierInfo.getValue(), rightModifier);
    // Bug 100965 Avoid Cross server delegate admin being broken after initial creation due to stale caches
    if (com.zimbra.soap.type.TargetType.domain == erTargSel.getType()) {
        TargetBy by = erTargSel.getBy();
        if ((TargetBy.id == by) || (TargetBy.name == by)) {
            CacheSelector cacheSel = new CacheSelector(true, /* allServers */
            CacheEntryType.domain.toString());
            CacheEntrySelector ceSel = new CacheEntrySelector((TargetBy.id == erTargSel.getBy()) ? CacheEntryBy.id : CacheEntryBy.name, erTargSel.getValue());
            cacheSel.addEntry(ceSel);
            FlushCacheRequest fcReq = new FlushCacheRequest(cacheSel);
            try {
                FlushCache.doFlushCache(this, context, fcReq);
            } catch (ServiceException se) {
                ZimbraLog.acl.info("Problem flushing acl cache for domain %s/%s after granting rights", erTargSel.getBy(), erTargSel.getValue(), se);
            }
        }
    }
    Element response = zsc.createElement(AdminConstants.GRANT_RIGHT_RESPONSE);
    return response;
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) RightModifierInfo(com.zimbra.soap.admin.type.RightModifierInfo) GrantRightRequest(com.zimbra.soap.admin.message.GrantRightRequest) CacheEntrySelector(com.zimbra.soap.admin.type.CacheEntrySelector) ServiceException(com.zimbra.common.service.ServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) RightModifier(com.zimbra.cs.account.accesscontrol.RightModifier) FlushCacheRequest(com.zimbra.soap.admin.message.FlushCacheRequest) TargetBy(com.zimbra.soap.type.TargetBy) EffectiveRightsTargetSelector(com.zimbra.soap.admin.type.EffectiveRightsTargetSelector)

Aggregations

CacheSelector (com.zimbra.soap.admin.type.CacheSelector)5 ServiceException (com.zimbra.common.service.ServiceException)3 Server (com.zimbra.cs.account.Server)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 FlushCacheRequest (com.zimbra.soap.admin.message.FlushCacheRequest)2 CacheEntrySelector (com.zimbra.soap.admin.type.CacheEntrySelector)2 CacheEntryType (com.zimbra.soap.admin.type.CacheEntryType)2 Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthToken (com.zimbra.cs.account.AuthToken)1 CacheExtension (com.zimbra.cs.account.CacheExtension)1 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)1 RightModifier (com.zimbra.cs.account.accesscontrol.RightModifier)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 ZimbraAuthenticator (com.zimbra.cs.security.sasl.ZimbraAuthenticator)1 AdminAccessControl (com.zimbra.cs.service.admin.AdminAccessControl)1 GrantRightRequest (com.zimbra.soap.admin.message.GrantRightRequest)1 EffectiveRightsTargetSelector (com.zimbra.soap.admin.type.EffectiveRightsTargetSelector)1 RightModifierInfo (com.zimbra.soap.admin.type.RightModifierInfo)1