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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations