use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.
the class TestACL method grantRight.
/*
* utility methods to grant/revoke right
*
* To simulate how grants are done in the real server/zmprov, we first call TargetType.lookupTarget to
* "look for" the taret, then use the returned entry instead of giving the target entry passed in
* directly to RightUtil.
*
* This is for testing user rights, which goes to RightUtil directly (i.e. not through RightCommand)
*
*/
protected List<ZimbraACE> grantRight(TargetType targetType, Entry target, Set<ZimbraACE> aces) throws ServiceException {
/*
* make sure all rights are user right, tests written earlier could still be using
* this to grant
*/
for (ZimbraACE ace : aces) {
assertTrue(ace.getRight().isUserRight());
}
Entry targetEntry;
if (target instanceof Zimlet) {
// must be by name
String targetName = ((Zimlet) target).getName();
targetEntry = TargetType.lookupTarget(mProv, targetType, TargetBy.name, targetName);
} else {
String targetId = (target instanceof NamedEntry) ? ((NamedEntry) target).getId() : null;
targetEntry = TargetType.lookupTarget(mProv, targetType, TargetBy.id, targetId);
}
return ACLUtil.grantRight(mProv, targetEntry, aces);
}
use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.
the class TestACL method revokeRight.
protected List<ZimbraACE> revokeRight(TargetType targetType, Entry target, Set<ZimbraACE> aces) throws ServiceException {
// call TargetType.lookupTarget instead of passing the target entry directly for two reasons:
// 1. to simulate how grants are done in the real server/zmprov
// 2. convert DistributionList to AclGroup
Entry targetEntry;
if (target instanceof Zimlet) {
// must be by name
String targetName = ((Zimlet) target).getName();
targetEntry = TargetType.lookupTarget(mProv, targetType, TargetBy.name, targetName);
} else {
String targetId = (target instanceof NamedEntry) ? ((NamedEntry) target).getId() : null;
targetEntry = TargetType.lookupTarget(mProv, targetType, TargetBy.id, targetId);
}
return ACLUtil.revokeRight(mProv, targetEntry, aces);
}
use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.
the class ZimletUtil method showInfo.
public static void showInfo(String zimlet) throws ServiceException, ZimletException, IOException {
Provisioning prov = Provisioning.getInstance();
Zimlet z = prov.getZimlet(zimlet);
if (z == null) {
throw AccountServiceException.NO_SUCH_ZIMLET(zimlet);
}
List<Zimlet> plist = orderZimletsByPriority();
int pri = 0;
for (Zimlet zp : plist) {
if (zp.compareTo(z) == 0) {
break;
}
pri++;
}
System.out.println("Zimlet " + z.getName());
System.out.println(" Version: " + z.getAttr(Provisioning.A_zimbraZimletVersion));
System.out.println(" Description: " + z.getDescription());
System.out.println(" Priority: " + pri);
System.out.println(" Enabled: " + (z.isEnabled() ? "true" : "false"));
System.out.println("Indexing Enabled: " + (z.isIndexingEnabled() ? "true" : "false"));
if (z.isExtension()) {
System.out.println(" Extension: true");
}
String cosList = null;
for (Cos cos : prov.getAllCos()) {
for (String zc : getAvailableZimlets(cos).getZimletNamesAsArray()) {
if (zc.compareTo(zimlet) != 0) {
continue;
}
if (cosList == null) {
cosList = cos.getName();
} else {
cosList = cosList + ", " + cos.getName();
}
break;
}
}
System.out.println("Activated in COS: " + cosList);
System.out.println(" Config: " + z.getHandlerConfig());
ZimletFile zf = getZimlet(zimlet);
if (zf == null) {
System.out.println("*** Zimlet file is missing on this machine");
} else {
ZimletDescription desc = zf.getZimletDescription();
String val = desc.getRegexString();
if (val != null) {
System.out.println(" RegEx: " + val);
}
val = desc.getContentObjectAsXML();
if (val != null) {
System.out.println(" Content Object: " + val);
}
val = desc.getPanelItemAsXML();
if (val != null) {
System.out.println(" Panel Item: " + val);
}
val = null;
for (String script : desc.getScripts()) {
if (val == null) {
val = script;
} else {
val = val + ", " + script;
}
}
if (val != null) {
System.out.println(" Scripts: " + val);
}
val = null;
for (String css : desc.getStyleSheets()) {
if (val == null) {
val = css;
} else {
val = val + ", " + css;
}
}
if (val != null) {
System.out.println(" CSS: " + val);
}
val = null;
for (String target : desc.getTargets()) {
if (val == null) {
val = target;
} else {
val = val + ", " + target;
}
}
if (val != null) {
System.out.println(" Targets: " + val);
}
}
}
use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.
the class ZimletUtil method setZimletEnable.
/**
*
* Change the enabled status of the Zimlet.
*
* @param zimlet
* @param enabled
* @throws ZimletException
*/
public static void setZimletEnable(String zimlet, boolean enabled) throws ZimletException {
Provisioning prov = Provisioning.getInstance();
try {
Zimlet z = prov.getZimlet(zimlet);
if (z == null) {
throw AccountServiceException.NO_SUCH_ZIMLET(zimlet);
}
Map<String, String> attr = new HashMap<String, String>();
attr.put(Provisioning.A_zimbraZimletEnabled, enabled ? ProvisioningConstants.TRUE : ProvisioningConstants.FALSE);
prov.modifyAttrs(z, attr);
} catch (Exception e) {
if (enabled) {
throw ZimletException.CANNOT_ENABLE(zimlet, e);
} else {
throw ZimletException.CANNOT_DISABLE(zimlet, e);
}
}
}
use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.
the class ModifyZimletPrefs method doResponse.
private void doResponse(Provisioning prov, Element response, Account acct) throws ServiceException {
ZimletPresence userZimlets = ZimletUtil.getUserZimlets(acct);
for (String zimletName : userZimlets.getZimletNames()) {
Zimlet zimlet = prov.getZimlet(zimletName);
if (zimlet != null && zimlet.isEnabled() && !zimlet.isExtension()) {
Element eZimlet = response.addElement(AccountConstants.E_ZIMLET);
eZimlet.addAttribute(AccountConstants.A_NAME, zimletName);
eZimlet.addAttribute(AccountConstants.A_ZIMLET_PRESENCE, userZimlets.getPresence(zimletName).toString());
}
}
}
Aggregations