Search in sources :

Example 46 with NamedEntry

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

the class FixCalendarPriority method fixAccounts.

private static void fixAccounts(List<String> acctNames) throws ServiceException {
    int numAccts = acctNames.size();
    boolean all = (numAccts == 1 && ALL.equals(acctNames.get(0)));
    int numFixedAccts = 0;
    int numFixedAppts = 0;
    List<NamedEntry> accts;
    if (all) {
        accts = getAccountsOnServer();
    } else {
        accts = new ArrayList<NamedEntry>(acctNames.size());
        for (String name : acctNames) {
            try {
                accts.add(Provisioning.getInstance().get(AccountBy.name, name));
            } catch (ServiceException e) {
                ZimbraLog.calendar.error("Error looking up account " + name + ": " + e.getMessage(), e);
            }
        }
    }
    numAccts = accts.size();
    int every = 10;
    for (NamedEntry entry : accts) {
        if (!(entry instanceof Account))
            continue;
        Account acct = (Account) entry;
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
        try {
            numFixedAppts += mbox.fixAllCalendarItemPriority(null);
        } catch (ServiceException e) {
            ZimbraLog.calendar.error("Error fixing calendar item priority in mailbox " + mbox.getId() + ": " + e.getMessage(), e);
        }
        numFixedAccts++;
        if (numFixedAccts % every == 0) {
            ZimbraLog.calendar.info("Progress: fixed calendar item priority in " + numFixedAccts + "/" + numAccts + " accounts");
        }
    }
    ZimbraLog.calendar.info("Fixed priority in total " + numFixedAppts + " calendar items in " + numFixedAccts + " accounts");
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Mailbox(com.zimbra.cs.mailbox.Mailbox)

Example 47 with NamedEntry

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

the class FixCalendarTZ method fixAccounts.

private static void fixAccounts(List<String> acctNames, long after, TimeZoneFixupRules tzfixupRules) throws ServiceException {
    int numAccts = acctNames.size();
    boolean all = (numAccts == 1 && ALL.equals(acctNames.get(0)));
    int numFixedAccts = 0;
    int numFixedAppts = 0;
    List<NamedEntry> accts;
    if (all) {
        accts = getAccountsOnServer();
    } else {
        accts = new ArrayList<NamedEntry>(acctNames.size());
        for (String name : acctNames) {
            try {
                accts.add(Provisioning.getInstance().get(AccountBy.name, name));
            } catch (ServiceException e) {
                ZimbraLog.calendar.error("Error looking up account " + name + ": " + e.getMessage(), e);
            }
        }
    }
    numAccts = accts.size();
    int every = 10;
    for (NamedEntry entry : accts) {
        if (!(entry instanceof Account))
            continue;
        Account acct = (Account) entry;
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
        try {
            numFixedAppts += mbox.fixAllCalendarItemTZ(null, after, tzfixupRules);
        } catch (ServiceException e) {
            ZimbraLog.calendar.error("Error fixing timezones in mailbox " + mbox.getId() + ": " + e.getMessage(), e);
        }
        numFixedAccts++;
        if (numFixedAccts % every == 0) {
            ZimbraLog.calendar.info("Progress: fixed calendar timezones in " + numFixedAccts + "/" + numAccts + " accounts");
        }
    }
    ZimbraLog.calendar.info("Fixed timezones in total " + numFixedAppts + " calendar items in " + numFixedAccts + " accounts");
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Mailbox(com.zimbra.cs.mailbox.Mailbox)

Example 48 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 49 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 50 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)

Aggregations

NamedEntry (com.zimbra.cs.account.NamedEntry)109 Account (com.zimbra.cs.account.Account)51 ServiceException (com.zimbra.common.service.ServiceException)26 Domain (com.zimbra.cs.account.Domain)24 Provisioning (com.zimbra.cs.account.Provisioning)23 AccountServiceException (com.zimbra.cs.account.AccountServiceException)19 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)19 DistributionList (com.zimbra.cs.account.DistributionList)18 SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)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)8 MailTarget (com.zimbra.cs.account.MailTarget)8 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 AccessManager (com.zimbra.cs.account.AccessManager)7 DynamicGroup (com.zimbra.cs.account.DynamicGroup)7