Search in sources :

Example 6 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 7 with NamedEntry

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

the class GrantRights method handleACE.

/**
 * @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 {
    /*
         * Interface and parameter checking style was modeled after FolderAction, 
         * not admin Grant/RevokeRight
         */
    Right right = RightManager.getInstance().getUserRight(eACE.getAttribute(AccountConstants.A_RIGHT));
    GranteeType gtype = GranteeType.fromCode(eACE.getAttribute(AccountConstants.A_GRANT_TYPE));
    String zid = eACE.getAttribute(AccountConstants.A_ZIMBRA_ID, null);
    boolean deny = eACE.getAttributeBool(AccountConstants.A_DENY, false);
    boolean checkGranteeType = eACE.getAttributeBool(AccountConstants.A_CHECK_GRANTEE_TYPE, 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(AccountConstants.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(AccountConstants.A_PASSWORD);
        }
    } else if (gtype == GranteeType.GT_KEY) {
        zid = eACE.getAttribute(AccountConstants.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(AccountConstants.A_ACCESSKEY, null);
    } else if (zid != null) {
        nentry = lookupGranteeByZimbraId(zid, gtype, granting);
    } else {
        nentry = lookupGranteeByName(eACE.getAttribute(AccountConstants.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 Group) {
            if (checkGranteeType) {
                throw AccountServiceException.INVALID_REQUEST(eACE.getAttribute(AccountConstants.A_DISPLAY) + " is not a valid grantee for grantee type '" + gtype.getCode() + "'.", null);
            } else {
                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) Group(com.zimbra.cs.account.Group) 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 8 with NamedEntry

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

the class SearchCalendarResources method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, Integer.MAX_VALUE);
    if (limit == 0)
        limit = Integer.MAX_VALUE;
    int offset = (int) request.getAttributeLong(AdminConstants.A_OFFSET, 0);
    String domain = request.getAttribute(AdminConstants.A_DOMAIN, null);
    boolean applyCos = request.getAttributeBool(AdminConstants.A_APPLY_COS, true);
    String sortBy = request.getAttribute(AdminConstants.A_SORT_BY, null);
    boolean sortAscending = request.getAttributeBool(AdminConstants.A_SORT_ASCENDING, true);
    String attrsStr = request.getAttribute(AdminConstants.A_ATTRS, null);
    String[] attrs = attrsStr == null ? null : attrsStr.split(",");
    EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
    // Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager
    if (isDomainAdminOnly(zsc)) {
        if (domain == null) {
            domain = getAuthTokenAccountDomain(zsc).getName();
        } else {
            checkDomainRight(zsc, domain, AdminRight.PR_ALWAYS_ALLOW);
        }
    }
    Domain d = null;
    if (domain != null) {
        d = prov.get(Key.DomainBy.name, domain);
        if (d == null)
            throw AccountServiceException.NO_SUCH_DOMAIN(domain);
    }
    AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
    AdminAccessControl.SearchDirectoryRightChecker rightChecker = new AdminAccessControl.SearchDirectoryRightChecker(aac, prov, null);
    // filter is not RFC 2254 escaped
    // query is RFC 2254 escaped
    String query = LdapEntrySearchFilter.toLdapCalendarResourcesFilter(filter);
    SearchDirectoryOptions options = new SearchDirectoryOptions();
    options.setDomain(d);
    options.setTypes(SearchDirectoryOptions.ObjectType.resources);
    options.setFilterString(FilterId.ADMIN_SEARCH, query);
    options.setReturnAttrs(attrs);
    options.setSortOpt(sortAscending ? SortOpt.SORT_ASCENDING : SortOpt.SORT_DESCENDING);
    options.setSortAttr(sortBy);
    options.setConvertIDNToAscii(true);
    List<NamedEntry> resources;
    int limitMax = offset + limit;
    AdminSession session = (AdminSession) getSession(zsc, Session.Type.ADMIN);
    if (session != null) {
        resources = session.searchDirectory(options, offset, rightChecker);
    } else {
        resources = prov.searchDirectory(options);
        resources = rightChecker.getAllowed(resources, limitMax);
    }
    Element response = zsc.createElement(AdminConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
    int numEntries;
    for (numEntries = offset; numEntries < limitMax && numEntries < resources.size(); numEntries++) {
        NamedEntry entry = resources.get(numEntries);
        ToXML.encodeCalendarResource(response, (CalendarResource) entry, applyCos, null, aac.getAttrRightChecker(entry));
    }
    response.addAttribute(AdminConstants.A_MORE, numEntries < resources.size());
    response.addAttribute(AdminConstants.A_SEARCH_TOTAL, resources.size());
    return response;
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) Element(com.zimbra.common.soap.Element) LdapEntrySearchFilter(com.zimbra.cs.account.ldap.LdapEntrySearchFilter) EntrySearchFilter(com.zimbra.cs.account.EntrySearchFilter) Provisioning(com.zimbra.cs.account.Provisioning) NamedEntry(com.zimbra.cs.account.NamedEntry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AdminSession(com.zimbra.cs.session.AdminSession) Domain(com.zimbra.cs.account.Domain)

Example 9 with NamedEntry

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

the class ToXML method encodeLink.

public static Element encodeLink(Element response, ItemIdFormatter ifmt, Link link, int fields) {
    Element el = response.addNonUniqueElement(MailConstants.E_LINK);
    el.addAttribute(MailConstants.A_ID, ifmt.formatItemId(link));
    el.addAttribute(MailConstants.A_UUID, link.getUuid());
    if (needToOutput(fields, Change.NAME)) {
        String name = link.getName();
        if (!Strings.isNullOrEmpty(name)) {
            el.addAttribute(MailConstants.A_NAME, name);
        }
    }
    if (needToOutput(fields, Change.CONTENT)) {
        el.addAttribute(MailConstants.A_ZIMBRA_ID, link.getOwnerId());
        el.addAttribute(MailConstants.A_REMOTE_ID, link.getRemoteId());
        NamedEntry nentry = FolderAction.lookupGranteeByZimbraId(link.getOwnerId(), ACL.GRANTEE_USER);
        el.addAttribute(MailConstants.A_OWNER_NAME, nentry == null ? null : nentry.getName());
    }
    return el;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Element(com.zimbra.common.soap.Element)

Example 10 with NamedEntry

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

the class TestProvisioningUtil method verifyEntriesByName.

// verify list of NamedEntry contains all the names
// if checkCount == true, verify the count matches too
public static void verifyEntriesByName(List<NamedEntry> list, String[] names, boolean checkCount) throws Exception {
    Set<String> namesInList = new HashSet<String>();
    for (NamedEntry entry : list) namesInList.add(entry.getName());
    verifyEntries(namesInList, names, checkCount);
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) HashSet(java.util.HashSet)

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