Search in sources :

Example 1 with LdapDIT

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

the class CollectAllEffectiveRights method getAllGroups.

private Set<String> getAllGroups() throws ServiceException {
    LdapDIT ldapDIT = mProv.getDIT();
    String base = ldapDIT.mailBranchBaseDN();
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().allGroups();
    // hack, see LDAPDIT.dnToEmail, for now we get naming rdn for both default and possible custom DIT
    String[] returnAttrs = new String[] { Provisioning.A_cn, Provisioning.A_uid };
    Visitor visitor = new Visitor(mProv);
    mProv.searchLdapOnMaster(base, filter, returnAttrs, visitor);
    return visitor.getResult();
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor)

Example 2 with LdapDIT

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

the class BUG_18277 method getAllDomainOrGlobalAdmins.

private void getAllDomainOrGlobalAdmins(Set<String> domainAdminIds, Set<String> globalAdminIds) throws ServiceException {
    LdapDIT dit = prov.getDIT();
    String[] returnAttrs = new String[] { Provisioning.A_objectClass, Provisioning.A_zimbraId, Provisioning.A_zimbraIsAdminAccount, Provisioning.A_zimbraIsDomainAdminAccount, Provisioning.A_zimbraIsDelegatedAdminAccount };
    String configBranchBaseDn = dit.configBranchBaseDN();
    String base = dit.mailBranchBaseDN();
    String query = "(&(objectclass=zimbraAccount)(|(zimbraIsDomainAdminAccount=TRUE)(zimbraIsAdminAccount=TRUE)))";
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
        Bug18277Visitor visitor = new Bug18277Visitor(this, configBranchBaseDn, domainAdminIds, globalAdminIds);
        SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
        zlc.searchPaged(searchOpts);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all objects", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ServiceException(com.zimbra.common.service.ServiceException) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions)

Example 3 with LdapDIT

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

the class BUG_57866 method upgradeGalSyncAccounts.

private void upgradeGalSyncAccounts(ZLdapContext zlc) throws ServiceException {
    LdapDIT dit = prov.getDIT();
    String[] returnAttrs = new String[] { Provisioning.A_zimbraGalAccountId };
    String base = dit.mailBranchBaseDN();
    String query = "(&(objectclass=zimbraDomain)(zimbraGalAccountId=*))";
    final Set<String> galAcctIds = new HashSet<String>();
    SearchLdapVisitor visitor = new SearchLdapVisitor(false) {

        @Override
        public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
            try {
                String acctId;
                acctId = ldapAttrs.getAttrString(Provisioning.A_zimbraGalAccountId);
                if (acctId != null) {
                    galAcctIds.add(acctId);
                }
            } catch (ServiceException e) {
                printer.printStackTrace("unsble to search domains for GAL sync accounts", e);
            }
        }
    };
    SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    zlc.searchPaged(searchOpts);
    for (String galAcctId : galAcctIds) {
        printer.format("Checking GAL sync account %s\n", galAcctId);
        Account acct = prov.get(AccountBy.id, galAcctId);
        setIsSystemAccount(zlc, acct);
    }
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) IAttributes(com.zimbra.cs.ldap.IAttributes) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) HashSet(java.util.HashSet)

Example 4 with LdapDIT

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

the class TestLdapHelper method searchForEntryMultipleMatchedEntries.

@Test
public void searchForEntryMultipleMatchedEntries() throws Exception {
    LdapDIT dit = prov.getDIT();
    String base = dit.configBranchBaseDN();
    ZLdapFilter filter = filterFactory.allAccounts();
    boolean caughtException = false;
    try {
        ZSearchResultEntry entry = ldapHelper.searchForEntry(base, filter, null, false);
        assertNotNull(entry);
    } catch (LdapMultipleEntriesMatchedException e) {
        caughtException = true;
    }
    assertTrue(caughtException);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) LdapMultipleEntriesMatchedException(com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 5 with LdapDIT

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

the class TestLdapHelper method searchDir.

@Test
public void searchDir() throws Exception {
    LdapDIT dit = prov.getDIT();
    String base = dit.configBranchBaseDN();
    ZLdapFilter filter = filterFactory.anyEntry();
    String[] returnAttrs = new String[] { "objectClass" };
    ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_ONELEVEL, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
    ZSearchResultEnumeration ne = ldapHelper.searchDir(base, filter, searchControls);
    Set<String> expected = new HashSet<String>();
    expected.add(dit.adminBaseDN());
    expected.add(dit.appAdminBaseDN());
    expected.add(dit.zimletBaseDN());
    expected.add(dit.cosBaseDN());
    expected.add(dit.globalDynamicGroupBaseDN());
    expected.add(dit.serverBaseDN());
    expected.add(dit.xmppcomponentBaseDN());
    expected.add(dit.globalGrantDN());
    expected.add(dit.configDN());
    expected.add(dit.shareLocatorBaseDN());
    expected.add(dit.ucServiceBaseDN());
    int numFound = 0;
    while (ne.hasMore()) {
        ZSearchResultEntry sr = ne.next();
        assertTrue(expected.contains(sr.getDN()));
        numFound++;
    }
    ne.close();
    assertEquals(expected.size(), numFound);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) HashSet(java.util.HashSet) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Aggregations

LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)15 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)7 HashSet (java.util.HashSet)7 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)5 ServiceException (com.zimbra.common.service.ServiceException)4 LdapProv (com.zimbra.cs.account.ldap.LdapProv)4 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)4 SearchLdapVisitor (com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor)4 Account (com.zimbra.cs.account.Account)2 IAttributes (com.zimbra.cs.ldap.IAttributes)2 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)2 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)2 LdapMultipleEntriesMatchedException (com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException)1