Search in sources :

Example 1 with ZimletException

use of com.zimbra.cs.zimlet.ZimletException in project zm-mailbox by Zimbra.

the class ModifyZimlet method doStatus.

void doStatus(ZimbraSoapContext zsc, Map<String, Object> context, Element z) throws ServiceException {
    String name = z.getAttribute(AdminConstants.A_NAME);
    Zimlet zimlet = Provisioning.getInstance().getZimlet(name);
    if (z == null)
        throw AccountServiceException.NO_SUCH_ZIMLET(name);
    Element s = z.getElement(AdminConstants.E_STATUS);
    String val = s.getAttribute(AdminConstants.A_VALUE, null);
    if (val == null)
        return;
    boolean status = val.equalsIgnoreCase("enabled");
    Map<String, String> attrRightNeeded = new HashMap<String, String>();
    attrRightNeeded.put(Provisioning.A_zimbraZimletEnabled, status ? ProvisioningConstants.TRUE : ProvisioningConstants.FALSE);
    checkRight(zsc, context, zimlet, attrRightNeeded);
    try {
        ZimletUtil.setZimletEnable(name, status);
    } catch (ZimletException ze) {
        throw ServiceException.FAILURE("cannot modify status", ze);
    }
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) ZimletException(com.zimbra.cs.zimlet.ZimletException)

Example 2 with ZimletException

use of com.zimbra.cs.zimlet.ZimletException in project zm-mailbox by Zimbra.

the class ConfigureZimlet method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    checkRightTODO();
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Element content = request.getElement(MailConstants.E_CONTENT);
    String attachment = content.getAttribute(MailConstants.A_ATTACHMENT_ID, null);
    Upload up = FileUploadServlet.fetchUpload(zsc.getAuthtokenAccountId(), attachment, zsc.getAuthToken());
    if (up == null) {
        throw MailServiceException.NO_SUCH_UPLOAD(attachment);
    }
    Element response = zsc.createElement(AdminConstants.CONFIGURE_ZIMLET_RESPONSE);
    try {
        byte[] blob = ByteUtil.getContent(up.getInputStream(), 0);
        ZimletUtil.installConfig(new String(blob));
    } catch (IOException ioe) {
        throw ServiceException.FAILURE("cannot configure", ioe);
    } catch (ZimletException ze) {
        throw ServiceException.FAILURE("cannot configure", ze);
    } finally {
        FileUploadServlet.deleteUpload(up);
    }
    return response;
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ZimletException(com.zimbra.cs.zimlet.ZimletException) Upload(com.zimbra.cs.service.FileUploadServlet.Upload) IOException(java.io.IOException)

Example 3 with ZimletException

use of com.zimbra.cs.zimlet.ZimletException in project zm-mailbox by Zimbra.

the class LdapProvisioning method getZimlet.

private Zimlet getZimlet(String name, ZLdapContext initZlc, boolean useZimletCache) throws ServiceException {
    LdapZimlet zimlet = null;
    if (useZimletCache) {
        zimlet = zimletCache.getByName(name);
    }
    if (zimlet != null) {
        return zimlet;
    }
    try {
        String dn = mDIT.zimletNameToDN(name);
        ZAttributes attrs = helper.getAttributes(initZlc, LdapServerType.REPLICA, LdapUsage.GET_ZIMLET, dn, null);
        zimlet = new LdapZimlet(dn, attrs, this);
        if (useZimletCache) {
            ZimletUtil.reloadZimlet(name);
            // put LdapZimlet into the cache after successful ZimletUtil.reloadZimlet()
            zimletCache.put(zimlet);
        }
        return zimlet;
    } catch (LdapEntryNotFoundException e) {
        return null;
    } catch (ServiceException ne) {
        throw ServiceException.FAILURE("unable to get zimlet: " + name, ne);
    } catch (ZimletException ze) {
        throw ServiceException.FAILURE("unable to load zimlet: " + name, ze);
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) ZAttributes(com.zimbra.cs.ldap.ZAttributes) ZimletException(com.zimbra.cs.zimlet.ZimletException)

Example 4 with ZimletException

use of com.zimbra.cs.zimlet.ZimletException in project zm-mailbox by Zimbra.

the class ModifyZimlet method doAcl.

void doAcl(ZimbraSoapContext zsc, Map<String, Object> context, Element z) throws ServiceException {
    String name = z.getAttribute(AdminConstants.A_NAME);
    Element a = z.getElement(AdminConstants.E_ACL);
    String cosName = a.getAttribute(AdminConstants.A_COS, null);
    if (cosName == null)
        return;
    Cos cos = Provisioning.getInstance().get(Key.CosBy.name, cosName);
    if (cos == null)
        throw AccountServiceException.NO_SUCH_COS(cosName);
    checkRight(zsc, context, cos, Admin.R_manageZimlet);
    String acl = a.getAttribute(AdminConstants.A_ACL, null);
    if (acl == null)
        throw ServiceException.INVALID_REQUEST("missing acl attribute", null);
    acl = acl.toLowerCase();
    try {
        if (acl.equals("grant")) {
            ZimletUtil.activateZimlet(name, cosName);
        } else if (acl.equals("deny")) {
            ZimletUtil.deactivateZimlet(name, cosName);
        } else {
            throw ServiceException.INVALID_REQUEST("invalid acl setting " + acl, null);
        }
    } catch (ZimletException ze) {
        throw ServiceException.FAILURE("cannot modify acl", ze);
    }
}
Also used : Cos(com.zimbra.cs.account.Cos) Element(com.zimbra.common.soap.Element) ZimletException(com.zimbra.cs.zimlet.ZimletException)

Aggregations

ZimletException (com.zimbra.cs.zimlet.ZimletException)4 Element (com.zimbra.common.soap.Element)3 ServiceException (com.zimbra.common.service.ServiceException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 Cos (com.zimbra.cs.account.Cos)1 Zimlet (com.zimbra.cs.account.Zimlet)1 LdapZimlet (com.zimbra.cs.account.ldap.entry.LdapZimlet)1 LdapEntryNotFoundException (com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException)1 ZAttributes (com.zimbra.cs.ldap.ZAttributes)1 Upload (com.zimbra.cs.service.FileUploadServlet.Upload)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1