Search in sources :

Example 21 with LdapProv

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

the class TestLdap method deleteAllNonDefaultCoses.

private static void deleteAllNonDefaultCoses() throws Exception {
    LdapDIT dit = ((LdapProv) Provisioning.getInstance()).getDIT();
    String cosBaseDN = dit.cosBaseDN();
    Set<String> defaultCosDN = new HashSet<String>();
    defaultCosDN.add(dit.cosNametoDN(Provisioning.DEFAULT_COS_NAME));
    defaultCosDN.add(dit.cosNametoDN(Provisioning.DEFAULT_EXTERNAL_COS_NAME));
    deleteAllChildrenUnderDN(cosBaseDN, defaultCosDN);
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) LdapProv(com.zimbra.cs.account.ldap.LdapProv) HashSet(java.util.HashSet)

Example 22 with LdapProv

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

the class TestObjectClass method getMostSpecificOC.

@Test
public void getMostSpecificOC() throws Exception {
    LdapProv ldapProv = (LdapProv) prov;
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "zimbraAccount", "organizationalPerson", "person" }, "inetOrgPerson"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "inetOrgPerson" }, "organizationalPerson"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "organizationalPerson", "inetOrgPerson" }, "person"));
    assertEquals("bbb", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "inetOrgPerson" }, "bbb"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "aaa" }, "inetOrgPerson"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "person", "inetOrgPerson" }, "organizationalPerson"));
}
Also used : LdapProv(com.zimbra.cs.account.ldap.LdapProv) Test(org.junit.Test)

Example 23 with LdapProv

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

the class ProvUtil method lookupAccount.

private Account lookupAccount(String key, boolean mustFind, boolean applyDefault) throws ServiceException {
    Account account;
    if (applyDefault == true || (prov instanceof LdapProv)) {
        account = prov.getAccount(key);
    } else {
        /*
             * oops, do not apply default, and we are SoapProvisioning
             * 
             * This a bit awkward because the applyDefault is controlled at the Entry.getAttrs, not at the provisioning
             * interface. But for SOAP, this needs to be passed to the get(AccountBy) method so it can set the flag in
             * SOAP. We do not want to add a provisioning method for this. Instead, we make it a SOAPProvisioning only
             * method.
             */
        SoapProvisioning soapProv = (SoapProvisioning) prov;
        account = soapProv.getAccount(key, applyDefault);
    }
    if (mustFind && account == null) {
        throw AccountServiceException.NO_SUCH_ACCOUNT(key);
    } else {
        return account;
    }
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 24 with LdapProv

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

the class ProvUtil method doSearchAccounts.

private void doSearchAccounts(String[] args) throws ServiceException, ArgException {
    boolean verbose = false;
    int i = 1;
    if (args[i].equals("-v")) {
        verbose = true;
        i++;
        if (args.length < i - 1) {
            usage();
            return;
        }
    }
    if (args.length < i + 1) {
        usage();
        return;
    }
    String query = args[i];
    Map<String, Object> attrs = getMap(args, i + 1);
    String limitStr = (String) attrs.get("limit");
    int limit = limitStr == null ? Integer.MAX_VALUE : Integer.parseInt(limitStr);
    String offsetStr = (String) attrs.get("offset");
    int offset = offsetStr == null ? 0 : Integer.parseInt(offsetStr);
    String sortBy = (String) attrs.get("sortBy");
    String sortAscending = (String) attrs.get("sortAscending");
    boolean isSortAscending = (sortAscending != null) ? "1".equalsIgnoreCase(sortAscending) : true;
    String[] attrsToGet = null;
    String typesStr = (String) attrs.get("types");
    if (typesStr == null) {
        typesStr = SearchDirectoryOptions.ObjectType.accounts.name() + "," + SearchDirectoryOptions.ObjectType.aliases.name() + "," + SearchDirectoryOptions.ObjectType.distributionlists.name() + "," + SearchDirectoryOptions.ObjectType.dynamicgroups.name() + "," + SearchDirectoryOptions.ObjectType.resources.name();
    }
    String domainStr = (String) attrs.get("domain");
    SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(attrsToGet);
    if (domainStr != null) {
        Domain d = lookupDomain(domainStr, prov);
        searchOpts.setDomain(d);
    }
    searchOpts.setTypes(typesStr);
    searchOpts.setSortOpt(isSortAscending ? SortOpt.SORT_ASCENDING : SortOpt.SORT_DESCENDING);
    searchOpts.setSortAttr(sortBy);
    // if LdapClient is not initialized(the case for SoapProvisioning), FilterId
    // is not initialized. Use null for SoapProvisioning, it will be set to
    // FilterId.ADMIN_SEARCH in SearchDirectory soap handler.
    FilterId filterId = (prov instanceof LdapProv) ? FilterId.ADMIN_SEARCH : null;
    searchOpts.setFilterString(filterId, query);
    // query must be already RFC 2254 escaped
    searchOpts.setConvertIDNToAscii(true);
    List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
    for (int j = offset; j < offset + limit && j < accounts.size(); j++) {
        NamedEntry account = accounts.get(j);
        if (verbose) {
            if (account instanceof Account) {
                dumpAccount((Account) account, true, null);
            } else if (account instanceof Alias) {
                dumpAlias((Alias) account);
            } else if (account instanceof DistributionList) {
                dumpGroup((DistributionList) account, null);
            } else if (account instanceof Domain) {
                dumpDomain((Domain) account, null);
            }
        } else {
            console.println(account.getName());
        }
    }
}
Also used : FilterId(com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 25 with LdapProv

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

the class ForeignPrincipal method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
    if (entry == null || context.isCreate()) {
        return;
    }
    if (!(entry instanceof Account))
        return;
    Provisioning prov = Provisioning.getInstance();
    if (!(prov instanceof LdapProv))
        return;
    Account acct = (Account) entry;
    ((LdapProv) prov).removeFromCache(acct);
}
Also used : Account(com.zimbra.cs.account.Account) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Aggregations

LdapProv (com.zimbra.cs.account.ldap.LdapProv)38 Domain (com.zimbra.cs.account.Domain)14 Account (com.zimbra.cs.account.Account)12 HashMap (java.util.HashMap)12 DistributionList (com.zimbra.cs.account.DistributionList)8 Provisioning (com.zimbra.cs.account.Provisioning)8 ServiceException (com.zimbra.common.service.ServiceException)7 NamedEntry (com.zimbra.cs.account.NamedEntry)6 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)6 HashSet (java.util.HashSet)6 Map (java.util.Map)5 AccountServiceException (com.zimbra.cs.account.AccountServiceException)4 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)4 List (java.util.List)4 Entry (com.zimbra.cs.account.Entry)3 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)3 RightCommand (com.zimbra.cs.account.accesscontrol.RightCommand)3 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)3 GranteeBy (com.zimbra.soap.admin.type.GranteeSelector.GranteeBy)3 PublishedShareInfoVisitor (com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)2