Search in sources :

Example 1 with ObjectType

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

the class LdapProvisioning method countObjects.

@Override
public long countObjects(CountObjectsType type, Domain domain, UCService ucService) throws ServiceException {
    if (domain != null && !type.allowsDomain()) {
        throw ServiceException.INVALID_REQUEST("domain cannot be specified for counting type: " + type.toString(), null);
    }
    if (ucService != null && !type.allowsUCService()) {
        throw ServiceException.INVALID_REQUEST("UCService cannot be specified for counting type: " + type.toString(), null);
    }
    ZLdapFilter filter;
    // setup types for finding bases
    Set<ObjectType> types = Sets.newHashSet();
    switch(type) {
        case userAccount:
            types.add(ObjectType.accounts);
            filter = filterFactory.allNonSystemAccounts();
            break;
        case internalUserAccount:
        case internalUserAccountX:
            types.add(ObjectType.accounts);
            filter = filterFactory.allNonSystemInternalAccounts();
            break;
        case internalArchivingAccount:
            types.add(ObjectType.accounts);
            filter = filterFactory.allNonSystemArchivingAccounts();
            break;
        case account:
            types.add(ObjectType.accounts);
            types.add(ObjectType.resources);
            filter = filterFactory.allAccounts();
            break;
        case alias:
            types.add(ObjectType.aliases);
            filter = filterFactory.allAliases();
            break;
        case dl:
            types.add(ObjectType.distributionlists);
            types.add(ObjectType.dynamicgroups);
            filter = mDIT.filterGroupsByDomain(domain);
            if (domain != null && !InMemoryLdapServer.isOn()) {
                ZLdapFilter dnSubtreeMatchFilter = ((LdapDomain) domain).getDnSubtreeMatchFilter();
                filter = filterFactory.andWith(filter, dnSubtreeMatchFilter);
            }
            break;
        case calresource:
            types.add(ObjectType.resources);
            filter = filterFactory.allCalendarResources();
            break;
        case domain:
            types.add(ObjectType.domains);
            filter = filterFactory.allDomains();
            break;
        case cos:
            types.add(ObjectType.coses);
            filter = filterFactory.allCoses();
            break;
        case server:
            types.add(ObjectType.servers);
            filter = filterFactory.allServers();
            break;
        case accountOnUCService:
            if (ucService == null) {
                throw ServiceException.INVALID_REQUEST("UCService is required for counting type: " + type.toString(), null);
            }
            types.add(ObjectType.accounts);
            types.add(ObjectType.resources);
            filter = filterFactory.accountsOnUCService(ucService.getId());
            break;
        case cosOnUCService:
            if (ucService == null) {
                throw ServiceException.INVALID_REQUEST("UCService is required for counting type: " + type.toString(), null);
            }
            types.add(ObjectType.coses);
            filter = filterFactory.cosesOnUCService(ucService.getId());
            break;
        case domainOnUCService:
            if (ucService == null) {
                throw ServiceException.INVALID_REQUEST("UCService is required for counting type: " + type.toString(), null);
            }
            types.add(ObjectType.domains);
            filter = filterFactory.domainsOnUCService(ucService.getId());
            break;
        default:
            throw ServiceException.INVALID_REQUEST("unsupported counting type:" + type.toString(), null);
    }
    String[] bases = getSearchBases(domain, types);
    long num = 0;
    for (String base : bases) {
        num += countObjects(base, filter);
    }
    return num;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ObjectType(com.zimbra.cs.account.SearchDirectoryOptions.ObjectType) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain)

Example 2 with ObjectType

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

the class LdapProvisioning method searchDirectoryInternal.

private List<NamedEntry> searchDirectoryInternal(SearchDirectoryOptions options, NamedEntry.Visitor visitor) throws ServiceException {
    Set<ObjectType> types = options.getTypes();
    if (types == null) {
        throw ServiceException.INVALID_REQUEST("missing types", null);
    }
    /*
         * base
         */
    Domain domain = options.getDomain();
    String[] bases = null;
    if (options.getTypes().contains(ObjectType.habgroups)) {
        bases = new String[1];
        bases[0] = options.getHabRootGroupDn();
    } else {
        bases = getSearchBases(domain, types);
    }
    /*
         * filter
         */
    int flags = options.getTypesAsFlags();
    ZLdapFilter filter = options.getFilter();
    String filterStr = options.getFilterString();
    // exact one of filter or filterString has to be set
    if (filter != null && filterStr != null) {
        throw ServiceException.INVALID_REQUEST("only one of filter or filterString can be set", null);
    }
    if (filter == null) {
        if (options.getConvertIDNToAscii() && !Strings.isNullOrEmpty(filterStr)) {
            filterStr = LdapEntrySearchFilter.toLdapIDNFilter(filterStr);
        }
        // prepend objectClass filters
        String objectClass = getObjectClassQuery(flags);
        if (filterStr == null || filterStr.equals("")) {
            filterStr = objectClass;
        } else {
            if (filterStr.startsWith("(") && filterStr.endsWith(")")) {
                filterStr = "(&" + objectClass + filterStr + ")";
            } else {
                filterStr = "(&" + objectClass + "(" + filterStr + ")" + ")";
            }
        }
        FilterId filterId = options.getFilterId();
        if (filterId == null) {
            throw ServiceException.INVALID_REQUEST("missing filter id", null);
        }
        filter = filterFactory.fromFilterString(options.getFilterId(), filterStr);
    }
    if (domain != null && !InMemoryLdapServer.isOn()) {
        boolean groupsTree = false;
        boolean peopleTree = false;
        if (types.contains(ObjectType.dynamicgroups)) {
            groupsTree = true;
        }
        if (types.contains(ObjectType.accounts) || types.contains(ObjectType.aliases) || types.contains(ObjectType.distributionlists) || types.contains(ObjectType.resources)) {
            peopleTree = true;
        }
        if (groupsTree && peopleTree) {
            ZLdapFilter dnSubtreeMatchFilter = ((LdapDomain) domain).getDnSubtreeMatchFilter();
            filter = filterFactory.andWith(filter, dnSubtreeMatchFilter);
        }
    }
    /*
         * return attrs
         */
    String[] returnAttrs = fixReturnAttrs(options.getReturnAttrs(), flags);
    return searchObjects(bases, filter, returnAttrs, options, visitor);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ObjectType(com.zimbra.cs.account.SearchDirectoryOptions.ObjectType) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) FilterId(com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId)

Aggregations

ObjectType (com.zimbra.cs.account.SearchDirectoryOptions.ObjectType)2 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)2 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)2 Domain (com.zimbra.cs.account.Domain)1 FilterId (com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId)1