Search in sources :

Example 26 with Zimlet

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);
}
Also used : ZimbraACE(com.zimbra.cs.account.accesscontrol.ZimbraACE) NamedEntry(com.zimbra.cs.account.NamedEntry) NamedEntry(com.zimbra.cs.account.NamedEntry) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry) Entry(com.zimbra.cs.account.Entry) Zimlet(com.zimbra.cs.account.Zimlet)

Example 27 with Zimlet

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);
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) NamedEntry(com.zimbra.cs.account.NamedEntry) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry) Entry(com.zimbra.cs.account.Entry) Zimlet(com.zimbra.cs.account.Zimlet)

Example 28 with Zimlet

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);
        }
    }
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) Cos(com.zimbra.cs.account.Cos) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Example 29 with Zimlet

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);
        }
    }
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) HashMap(java.util.HashMap) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException)

Example 30 with Zimlet

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());
        }
    }
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) Element(com.zimbra.common.soap.Element) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence)

Aggregations

Zimlet (com.zimbra.cs.account.Zimlet)37 Provisioning (com.zimbra.cs.account.Provisioning)16 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)11 Element (com.zimbra.common.soap.Element)8 HashMap (java.util.HashMap)8 ServiceException (com.zimbra.common.service.ServiceException)7 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Cos (com.zimbra.cs.account.Cos)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Entry (com.zimbra.cs.account.Entry)3 NamedEntry (com.zimbra.cs.account.NamedEntry)3 LdapZimlet (com.zimbra.cs.account.ldap.entry.LdapZimlet)3 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)2 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)2 ZimbraACE (com.zimbra.cs.account.accesscontrol.ZimbraACE)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Key (com.zimbra.common.account.Key)1 AccountBy (com.zimbra.common.account.Key.AccountBy)1 DistributionListBy (com.zimbra.common.account.Key.DistributionListBy)1