Search in sources :

Example 26 with NamedEntry

use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.

the class RightCommand method revokeRight.

public static void revokeRight(Provisioning prov, Account authedAcct, TargetType tt, TargetBy targetBy, String target, GranteeType gt, GranteeBy granteeBy, String grantee, String right, RightModifier rightModifier) throws ServiceException {
    verifyAccessManager();
    // target
    Entry targetEntry = TargetType.lookupTarget(prov, tt, targetBy, target);
    // grantee
    NamedEntry granteeEntry = null;
    String granteeId = null;
    try {
        if (gt.isZimbraEntry()) {
            granteeEntry = GranteeType.lookupGrantee(prov, gt, granteeBy, grantee);
            granteeId = granteeEntry.getId();
        } else {
            // for all and pub, ZimbraACE will use the correct id, granteeId here will be ignored
            // for guest, grantee id is the email
            // for key, grantee id is the display name
            granteeId = grantee;
        }
    } catch (AccountServiceException e) {
        String code = e.getCode();
        if (AccountServiceException.NO_SUCH_ACCOUNT.equals(code) || AccountServiceException.NO_SUCH_DISTRIBUTION_LIST.equals(code) || Constants.ERROR_CODE_NO_SUCH_DOMAIN.equals(code)) {
            ZimbraLog.acl.warn("revokeRight: no such grantee " + grantee);
            // if granteeBy is id, we try to revoke the orphan grant
            if (granteeBy == GranteeBy.id)
                granteeId = grantee;
            else
                throw ServiceException.INVALID_REQUEST("cannot find grantee by name: " + grantee + ", try revoke by grantee id if you want to remove the orphan grant", e);
        } else
            throw e;
    }
    // right
    // note: if a forbidden attr is persisted in an ACL in an inline attr right
    // (it can get in in a release before the attr is considered forbidden),
    // the getRight() call will throw exception.
    // Such grants will have to be removed by "zmprov modify{Entry} zimbraACE ..."
    // command.  We do NOT want to do any special treatment here because those
    // grants are not even loaded into memory, which is nice and clean, we don't
    // want to hack that part.
    Right r = RightManager.getInstance().getRight(right);
    if (granteeEntry != null) {
        validateGrant(authedAcct, tt, targetEntry, gt, granteeEntry, null, r, rightModifier, true);
    }
    Set<ZimbraACE> aces = new HashSet<ZimbraACE>();
    ZimbraACE ace = new ZimbraACE(granteeId, gt, r, rightModifier, null);
    aces.add(ace);
    List<ZimbraACE> revoked = ACLUtil.revokeRight(prov, targetEntry, aces);
    if (revoked.isEmpty())
        throw AccountServiceException.NO_SUCH_GRANT(ace.dump(true));
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) AccountServiceException(com.zimbra.cs.account.AccountServiceException) NamedEntry(com.zimbra.cs.account.NamedEntry) Entry(com.zimbra.cs.account.Entry) HashSet(java.util.HashSet)

Example 27 with NamedEntry

use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.

the class RightCommand method grantRightInternal.

private static void grantRightInternal(Provisioning prov, Account authedAcct, TargetType tt, TargetBy targetBy, String target, GranteeType gt, GranteeBy granteeBy, String grantee, String secret, String right, RightModifier rightModifier, boolean dryRun) throws ServiceException {
    verifyAccessManager();
    // target
    Entry targetEntry = TargetType.lookupTarget(prov, tt, targetBy, target);
    // right
    Right r = RightManager.getInstance().getRight(right);
    // grantee
    NamedEntry granteeEntry = null;
    String granteeId;
    if (gt.isZimbraEntry()) {
        granteeEntry = GranteeType.lookupGrantee(prov, gt, granteeBy, grantee);
        granteeId = granteeEntry.getId();
    } else if (gt == GranteeType.GT_EXT_GROUP) {
        boolean asAdmin = !r.isUserRight();
        ExternalGroup extGroup = ExternalGroup.get(DomainBy.name, grantee, asAdmin);
        if (extGroup == null) {
            throw ServiceException.INVALID_REQUEST("unable to find external group " + grantee, null);
        }
        granteeId = extGroup.getId();
    } else {
        // for all and pub, ZimbraACE will use the correct id, granteeId here will be ignored
        // for guest, grantee id is the email
        // for key, grantee id is the display name
        granteeId = grantee;
    }
    validateGrant(authedAcct, tt, targetEntry, gt, granteeEntry, secret, r, rightModifier, false);
    if (dryRun) {
        return;
    }
    Set<ZimbraACE> aces = new HashSet<ZimbraACE>();
    ZimbraACE ace = new ZimbraACE(granteeId, gt, r, rightModifier, secret);
    aces.add(ace);
    ACLUtil.grantRight(prov, targetEntry, aces);
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) NamedEntry(com.zimbra.cs.account.NamedEntry) Entry(com.zimbra.cs.account.Entry) HashSet(java.util.HashSet)

Example 28 with NamedEntry

use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllGroups.

/**
 * Get all static distribution lists and dynamic groups
 */
@SuppressWarnings("unchecked")
@Override
public List getAllGroups(Domain domain) throws ServiceException {
    SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(domain);
    searchOpts.setFilter(mDIT.filterGroupsByDomain(domain));
    searchOpts.setTypes(ObjectType.distributionlists, ObjectType.dynamicgroups);
    searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
    List<NamedEntry> groups = (List<NamedEntry>) searchDirectoryInternal(searchOpts);
    return groups;
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) ArrayList(java.util.ArrayList) List(java.util.List) AddressList(com.zimbra.cs.account.AddressList) DistributionList(com.zimbra.cs.account.DistributionList)

Example 29 with NamedEntry

use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.

the class LdapProvisioning method getNamesForIds.

@Override
public Map<String, String> getNamesForIds(Set<String> ids, EntryType type) throws ServiceException {
    final Map<String, String> result = new HashMap<String, String>();
    Set<String> unresolvedIds;
    NamedEntry entry;
    final String nameAttr;
    final EntryType entryType = type;
    String base;
    String objectClass;
    switch(entryType) {
        case account:
            unresolvedIds = new HashSet<String>();
            for (String id : ids) {
                entry = accountCache.getById(id);
                if (entry != null)
                    result.put(id, entry.getName());
                else
                    unresolvedIds.add(id);
            }
            nameAttr = Provisioning.A_zimbraMailDeliveryAddress;
            base = mDIT.mailBranchBaseDN();
            objectClass = AttributeClass.OC_zimbraAccount;
            break;
        case group:
            unresolvedIds = ids;
            // see dnToEmail
            nameAttr = Provisioning.A_uid;
            base = mDIT.mailBranchBaseDN();
            objectClass = AttributeClass.OC_zimbraDistributionList;
            break;
        case cos:
            unresolvedIds = new HashSet<String>();
            for (String id : ids) {
                entry = cosCache.getById(id);
                if (entry != null)
                    result.put(id, entry.getName());
                else
                    unresolvedIds.add(id);
            }
            nameAttr = Provisioning.A_cn;
            base = mDIT.cosBaseDN();
            objectClass = AttributeClass.OC_zimbraCOS;
            break;
        case domain:
            unresolvedIds = new HashSet<String>();
            for (String id : ids) {
                entry = getFromCache(Key.DomainBy.id, id, GetFromDomainCacheOption.POSITIVE);
                if (entry != null)
                    result.put(id, entry.getName());
                else
                    unresolvedIds.add(id);
            }
            nameAttr = Provisioning.A_zimbraDomainName;
            base = mDIT.domainBaseDN();
            objectClass = AttributeClass.OC_zimbraDomain;
            break;
        default:
            throw ServiceException.FAILURE("unsupported entry type for getNamesForIds" + type.name(), null);
    }
    // we are done if all ids can be resolved in our cache
    if (unresolvedIds.size() == 0)
        return result;
    SearchLdapVisitor visitor = new SearchLdapVisitor() {

        @Override
        public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
            String id = (String) attrs.get(Provisioning.A_zimbraId);
            String name = null;
            try {
                switch(entryType) {
                    case account:
                        name = ldapAttrs.getAttrString(Provisioning.A_zimbraMailDeliveryAddress);
                        if (name == null)
                            name = mDIT.dnToEmail(dn, ldapAttrs);
                        break;
                    case group:
                        name = mDIT.dnToEmail(dn, ldapAttrs);
                        break;
                    case cos:
                        name = ldapAttrs.getAttrString(Provisioning.A_cn);
                        break;
                    case domain:
                        name = ldapAttrs.getAttrString(Provisioning.A_zimbraDomainName);
                        break;
                }
            } catch (ServiceException e) {
                name = null;
            }
            if (name != null)
                result.put(id, name);
        }
    };
    String[] returnAttrs = new String[] { Provisioning.A_zimbraId, nameAttr };
    searchNamesForIds(unresolvedIds, base, objectClass, returnAttrs, visitor);
    return result;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) IAttributes(com.zimbra.cs.ldap.IAttributes) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 30 with NamedEntry

use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllHabGroups.

@Override
public List getAllHabGroups(Domain domain, String rootDn) throws ServiceException {
    SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(domain);
    searchOpts.setFilter(mDIT.filterHabGroupsByDn());
    searchOpts.setTypes(ObjectType.habgroups);
    searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
    searchOpts.setHabRootGroupDn(rootDn);
    List<NamedEntry> groups = (List<NamedEntry>) searchDirectoryInternal(searchOpts);
    return groups;
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) ArrayList(java.util.ArrayList) List(java.util.List) AddressList(com.zimbra.cs.account.AddressList) DistributionList(com.zimbra.cs.account.DistributionList)

Aggregations

NamedEntry (com.zimbra.cs.account.NamedEntry)109 Account (com.zimbra.cs.account.Account)51 ServiceException (com.zimbra.common.service.ServiceException)24 Domain (com.zimbra.cs.account.Domain)24 Provisioning (com.zimbra.cs.account.Provisioning)23 DistributionList (com.zimbra.cs.account.DistributionList)19 SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)19 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)19 AccountServiceException (com.zimbra.cs.account.AccountServiceException)18 HashSet (java.util.HashSet)17 Entry (com.zimbra.cs.account.Entry)15 HashMap (java.util.HashMap)15 Element (com.zimbra.common.soap.Element)14 Group (com.zimbra.cs.account.Group)14 SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)12 GuestAccount (com.zimbra.cs.account.GuestAccount)9 MailTarget (com.zimbra.cs.account.MailTarget)8 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 ArrayList (java.util.ArrayList)8 AccessManager (com.zimbra.cs.account.AccessManager)7