Search in sources :

Example 31 with NamedEntry

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

the class MailboxManager method getMailboxSizes.

/**
 * Returns the zimbra IDs and approximate sizes for all mailboxes on
 *  the system.  Note that mailboxes are created lazily, so there may be
 *  accounts homed on this system for whom there is is not yet a mailbox
 *  and hence are not included in the returned <code>Map</code>.
 *
 * @throws ServiceException  The following error codes are possible:<ul>
 *    <li><code>service.FAILURE</code> - an error occurred while accessing
 *        the database; a SQLException is encapsulated</ul>
 */
public Map<String, Long> getMailboxSizes(List<NamedEntry> accounts) throws ServiceException {
    List<Integer> requested;
    synchronized (this) {
        if (accounts == null) {
            requested = new ArrayList<Integer>(mailboxIds.values());
        } else {
            requested = new ArrayList<Integer>(accounts.size());
            for (NamedEntry account : accounts) {
                Integer mailboxId = mailboxIds.get(account.getId());
                if (mailboxId != null)
                    requested.add(mailboxId);
            }
        }
    }
    DbConnection conn = null;
    try {
        conn = DbPool.getConnection();
        return DbMailbox.getMailboxSizes(conn, requested);
    } finally {
        if (conn != null)
            DbPool.quietClose(conn);
    }
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 32 with NamedEntry

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

the class GrantPermission method lookupGranteeByName.

// orig: FolderAction.lookupGranteeByName
private static NamedEntry lookupGranteeByName(String name, GranteeType type, ZimbraSoapContext zsc) throws ServiceException {
    if (type == GranteeType.GT_AUTHUSER || type == GranteeType.GT_PUBLIC || type == GranteeType.GT_GUEST || type == GranteeType.GT_KEY)
        return null;
    Provisioning prov = Provisioning.getInstance();
    // for addresses, default to the authenticated user's domain
    if ((type == GranteeType.GT_USER || type == GranteeType.GT_GROUP) && name.indexOf('@') == -1) {
        Account authacct = prov.get(AccountBy.id, zsc.getAuthtokenAccountId(), zsc.getAuthToken());
        String authname = (authacct == null ? null : authacct.getName());
        if (authacct != null)
            name += authname.substring(authname.indexOf('@'));
    }
    NamedEntry nentry = null;
    if (name != null)
        switch(type) {
            case GT_USER:
                nentry = lookupEmailAddress(name);
                break;
            case GT_GROUP:
                nentry = prov.get(Key.DistributionListBy.name, name);
                break;
            case GT_DOMAIN:
                nentry = prov.get(Key.DomainBy.name, name);
                break;
        }
    if (nentry != null)
        return nentry;
    switch(type) {
        case GT_USER:
            throw AccountServiceException.NO_SUCH_ACCOUNT(name);
        case GT_GROUP:
            throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(name);
        case GT_DOMAIN:
            throw AccountServiceException.NO_SUCH_DOMAIN(name);
        default:
            throw ServiceException.FAILURE("LDAP entry not found for " + name + " : " + type, null);
    }
}
Also used : GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) Provisioning(com.zimbra.cs.account.Provisioning)

Example 33 with NamedEntry

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

the class GrantPermission method handleACE.

/**
 * // orig: FolderAction
 *
 * @param eACE
 * @param zsc
 * @param granting true if granting, false if revoking
 * @return
 * @throws ServiceException
 */
static ZimbraACE handleACE(Element eACE, ZimbraSoapContext zsc, boolean granting) throws ServiceException {
    Right right = RightManager.getInstance().getUserRight(eACE.getAttribute(MailConstants.A_RIGHT));
    GranteeType gtype = GranteeType.fromCode(eACE.getAttribute(MailConstants.A_GRANT_TYPE));
    String zid = eACE.getAttribute(MailConstants.A_ZIMBRA_ID, null);
    boolean deny = eACE.getAttributeBool(MailConstants.A_DENY, false);
    String secret = null;
    NamedEntry nentry = null;
    if (gtype == GranteeType.GT_AUTHUSER) {
        zid = GuestAccount.GUID_AUTHUSER;
    } else if (gtype == GranteeType.GT_PUBLIC) {
        zid = GuestAccount.GUID_PUBLIC;
    } else if (gtype == GranteeType.GT_GUEST) {
        zid = eACE.getAttribute(MailConstants.A_DISPLAY);
        if (zid == null || zid.indexOf('@') < 0)
            throw ServiceException.INVALID_REQUEST("invalid guest id or password", null);
        // make sure they didn't accidentally specify "guest" instead of "usr"
        try {
            nentry = lookupGranteeByName(zid, GranteeType.GT_USER, zsc);
            zid = nentry.getId();
            gtype = nentry instanceof DistributionList ? GranteeType.GT_GROUP : GranteeType.GT_USER;
        } catch (ServiceException e) {
            // this is the normal path, where lookupGranteeByName throws account.NO_SUCH_USER
            secret = eACE.getAttribute(MailConstants.A_PASSWORD);
        }
    } else if (gtype == GranteeType.GT_KEY) {
        zid = eACE.getAttribute(MailConstants.A_DISPLAY);
        // unlike guest, we do not require the display name to be an email address
        /*
            if (zid == null || zid.indexOf('@') < 0)
                throw ServiceException.INVALID_REQUEST("invalid guest id or key", null);
            */
        // unlike guest, we do not fixup grantee type for key grantees if they specify an internal user
        // get the optional accesskey
        secret = eACE.getAttribute(MailConstants.A_ACCESSKEY, null);
    } else if (zid != null) {
        nentry = lookupGranteeByZimbraId(zid, gtype, granting);
    } else {
        nentry = lookupGranteeByName(eACE.getAttribute(MailConstants.A_DISPLAY), gtype, zsc);
        zid = nentry.getId();
        // make sure they didn't accidentally specify "usr" instead of "grp"
        if (gtype == GranteeType.GT_USER && nentry instanceof DistributionList)
            gtype = GranteeType.GT_GROUP;
    }
    RightModifier rightModifier = null;
    if (deny)
        rightModifier = RightModifier.RM_DENY;
    return new ZimbraACE(zid, gtype, right, rightModifier, secret);
}
Also used : ZimbraACE(com.zimbra.cs.account.accesscontrol.ZimbraACE) NamedEntry(com.zimbra.cs.account.NamedEntry) GranteeType(com.zimbra.cs.account.accesscontrol.GranteeType) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Right(com.zimbra.cs.account.accesscontrol.Right) RightModifier(com.zimbra.cs.account.accesscontrol.RightModifier) DistributionList(com.zimbra.cs.account.DistributionList)

Example 34 with NamedEntry

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

the class GrantPermission method lookupGranteeByZimbraId.

// orig: FolderAction.lookupGranteeByZimbraId
private static NamedEntry lookupGranteeByZimbraId(String zid, GranteeType type, boolean granting) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    NamedEntry nentry = null;
    try {
        switch(type) {
            case GT_USER:
                nentry = prov.get(AccountBy.id, zid);
                if (nentry == null && granting)
                    throw AccountServiceException.NO_SUCH_ACCOUNT(zid);
                else
                    return nentry;
            case GT_GROUP:
                nentry = prov.get(Key.DistributionListBy.id, zid);
                if (nentry == null && granting)
                    throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(zid);
                else
                    return nentry;
            case GT_DOMAIN:
                nentry = prov.get(Key.DomainBy.id, zid);
                if (nentry == null && granting)
                    throw AccountServiceException.NO_SUCH_DOMAIN(zid);
                else
                    return nentry;
            case GT_GUEST:
            case GT_KEY:
            case GT_AUTHUSER:
            case GT_PUBLIC:
            default:
                return null;
        }
    } catch (ServiceException e) {
        if (granting)
            throw e;
        else
            return null;
    }
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 35 with NamedEntry

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

the class TestDistListACL method doCheckSentToDistListGuestRight.

private void doCheckSentToDistListGuestRight(DistributionList targetDl, String email, String guest, boolean expected) throws ServiceException {
    ZimbraLog.test.info("DL name %s ID %s", targetDl.getName(), targetDl.getId());
    Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
    Assert.assertNotNull("Unable to find Group object for DL by name", group);
    AccessManager.ViaGrant via = new AccessManager.ViaGrant();
    NamedEntry ne = GranteeType.lookupGrantee(prov, GranteeType.GT_GUEST, GranteeBy.name, email);
    MailTarget grantee = null;
    if (ne instanceof MailTarget) {
        grantee = (MailTarget) ne;
    }
    boolean result = RightCommand.checkRight(prov, "dl", /* targetType */
    TargetBy.name, listAddress, grantee, RightConsts.RT_sendToDistList, null, /* attrs */
    via);
    if (expected) {
        Assert.assertTrue(String.format("%s should be able to send to DL (as guest %s)", email, guest), accessMgr.canDo(email, group, User.R_sendToDistList, false));
        Assert.assertTrue(String.format("%s should have right to send to DL (as guest %s)", email, guest), result);
        ZimbraLog.test.info("Test for %s against dom %s Via=%s", email, guest, via);
    } else {
        Assert.assertFalse(String.format("%s should NOT be able to send to DL (because not guest %s)", email, guest), accessMgr.canDo(email, group, User.R_sendToDistList, false));
        Assert.assertFalse(String.format("%s should NOT have right to send to DL (because not guest %s)", email, guest), result);
    }
}
Also used : AccessManager(com.zimbra.cs.account.AccessManager) Group(com.zimbra.cs.account.Group) NamedEntry(com.zimbra.cs.account.NamedEntry) MailTarget(com.zimbra.cs.account.MailTarget)

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