Search in sources :

Example 11 with LdapProv

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

the class ADGroupHandler method getDelegatedAdminGroups.

private List<String> getDelegatedAdminGroups(Account acct, boolean asAdmin) throws ServiceException {
    LdapProv prov = LdapProv.getInst();
    Domain domain = prov.getDomain(acct);
    if (domain == null) {
        throw ServiceException.FAILURE("unable to get domain for account " + acct.getName(), null);
    }
    // try explicit external DN on account first
    String extDN = acct.getAuthLdapExternalDn();
    if (extDN == null) {
        // then try bind DN template on domain
        // note: for AD auth, zimbraAuthLdapSearchFilter is not used, so we 
        //       skip that. See LdapProvisioning.externalLdapAuth
        String dnTemplate = domain.getAuthLdapBindDn();
        if (dnTemplate != null) {
            extDN = LdapUtil.computeDn(acct.getName(), dnTemplate);
        }
    }
    if (extDN == null) {
        throw ServiceException.FAILURE("unable to get external DN for account " + acct.getName(), null);
    }
    ZLdapContext zlc = null;
    try {
        zlc = getExternalDelegatedAdminGroupsLdapContext(domain, asAdmin);
        ZAttributes attrs = prov.getHelper().getAttributes(zlc, extDN, new String[] { MEMBER_OF_ATTR });
        return attrs.getMultiAttrStringAsList(MEMBER_OF_ATTR, CheckBinary.NOCHECK);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ZAttributes(com.zimbra.cs.ldap.ZAttributes) Domain(com.zimbra.cs.account.Domain) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 12 with LdapProv

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

the class MilterServer method main.

public static void main(String[] args) {
    try {
        Provisioning prov = Provisioning.getInstance();
        if (prov instanceof LdapProv) {
            ((LdapProv) prov).waitForLdapServer();
        }
        MilterConfig config = new MilterConfig();
        MilterServer server = new MilterServer(config);
        // register the signal handler
        ClearCacheSignalHandler.register();
        MilterShutdownHook shutdownHook = new MilterShutdownHook(server);
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        ZimbraLog.milter.info("Starting milter server");
        server.start();
    } catch (ServiceException e) {
        ZimbraLog.milter.error("Unable to start milter server", e);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 13 with LdapProv

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

the class TestProvAlias method testRemoveAlias_entryNotExist_aliasNotExist.

//
// D
//
@Test
public void testRemoveAlias_entryNotExist_aliasNotExist() throws Exception {
    String testName = getTestName();
    // create the domain
    String domainName = "EN-AN" + "." + BASE_DOMAIN_NAME;
    domainName = domainName.toLowerCase();
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
    Domain domain = prov.createDomain(domainName, attrs);
    // create the account
    String acctName = getEmail("acct-1", domainName);
    Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
    // add an alias to the account
    String aliasName = getEmail("alias-1", domainName);
    prov.addAlias(acct, aliasName);
    // create 2 DLs
    String dl1Name = getEmail("dl-1", domainName);
    DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
    String dl2Name = getEmail("dl-2", domainName);
    DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
    // add the alias to the two DLs
    prov.addMembers(dl1, new String[] { aliasName });
    prov.addMembers(dl2, new String[] { aliasName });
    // now, hack it to delete the alias entry
    {
        List<NamedEntry> aliases = searchAliasesInDomain(domain);
        assertEquals(aliases.size(), 1);
        LdapEntry ldapAlias = (LdapEntry) aliases.get(0);
        String aliasDn = ldapAlias.getDN();
        ((LdapProv) prov).getHelper().deleteEntry(aliasDn, LdapUsage.UNITTEST);
    }
    Account nonExistingAcct = null;
    // remove the alias
    // we should *not* get a NO_SUCH_ALIAS exception
    prov.removeAlias(nonExistingAcct, aliasName);
    // reload all entries
    prov.reload(acct);
    prov.reload(dl1);
    prov.reload(dl2);
    Set<String> values;
    // ensure the alias is still on the account's mail/zimbraMailAlias attrs
    values = acct.getMultiAttrSet(Provisioning.A_mail);
    assertTrue(values.contains(aliasName));
    values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
    assertTrue(values.contains(aliasName));
    // ensure the alias is removed from all the DLs
    values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertFalse(values.contains(aliasName));
    values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertFalse(values.contains(aliasName));
    // ensure the alias entry is removed (should have been removed when we hacked to unbind it)
    List<NamedEntry> aliases = searchAliasesInDomain(domain);
    assertEquals(aliases.size(), 0);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapProv(com.zimbra.cs.account.ldap.LdapProv) NamedEntry(com.zimbra.cs.account.NamedEntry) DistributionList(com.zimbra.cs.account.DistributionList) List(java.util.List) Domain(com.zimbra.cs.account.Domain) DistributionList(com.zimbra.cs.account.DistributionList)

Example 14 with LdapProv

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

the class TestProvAlias method testRemoveAlias_entryNotExist_aliasExist_aliasPointToNonExistEntry.

//
// C - alias points to a non-existing entry
//
@Test
public void testRemoveAlias_entryNotExist_aliasExist_aliasPointToNonExistEntry() throws Exception {
    String testName = getTestName();
    // create the domain
    String domainName = "EN-AE-aliasPointToNonExistEntry" + "." + BASE_DOMAIN_NAME;
    domainName = domainName.toLowerCase();
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
    Domain domain = prov.createDomain(domainName, attrs);
    // create the account
    String acctName = getEmail("acct-1", domainName);
    Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
    // add an alias to the account
    String aliasName = getEmail("alias-1", domainName);
    prov.addAlias(acct, aliasName);
    // create 2 DLs
    String dl1Name = getEmail("dl-1", domainName);
    DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
    String dl2Name = getEmail("dl-2", domainName);
    DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
    // add the alias to the two DLs
    prov.addMembers(dl1, new String[] { aliasName });
    prov.addMembers(dl2, new String[] { aliasName });
    // now, hack it so the alias points to a non-existing entry
    {
        Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put(Provisioning.A_zimbraAliasTargetId, LdapUtil.generateUUID());
        List<NamedEntry> aliases = searchAliasesInDomain(domain);
        assertEquals(aliases.size(), 1);
        LdapEntry ldapAlias = (LdapEntry) aliases.get(0);
        ((LdapProv) prov).getHelper().modifyEntry(ldapAlias.getDN(), attributes, (Entry) ldapAlias, LdapUsage.UNITTEST);
    }
    Account nonExistingAcct = null;
    // remove the alias, on a "not found" account, and the alias is pointing to a non-existing entry
    // we should *not* get the NO_SUCH_ALIAS exception
    prov.removeAlias(nonExistingAcct, aliasName);
    // reload all entries
    prov.reload(acct);
    prov.reload(dl1);
    prov.reload(dl2);
    Set<String> values;
    // ensure the alias is still on the account's mail/zimbraMailAlias attrs
    // because there is no ref to this account so there is no way to remove them
    // (note, to remove them, A - aliasPointToNonExistEntry is the test for this)
    values = acct.getMultiAttrSet(Provisioning.A_mail);
    assertTrue(values.contains(aliasName));
    values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
    assertTrue(values.contains(aliasName));
    // ensure the alias is removed from all the DLs
    values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertFalse(values.contains(aliasName));
    values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertFalse(values.contains(aliasName));
    // ensure the alias entry is removed
    List<NamedEntry> aliases = searchAliasesInDomain(domain);
    assertEquals(aliases.size(), 0);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapProv(com.zimbra.cs.account.ldap.LdapProv) NamedEntry(com.zimbra.cs.account.NamedEntry) NamedEntry(com.zimbra.cs.account.NamedEntry) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry) Entry(com.zimbra.cs.account.Entry) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) DistributionList(com.zimbra.cs.account.DistributionList) List(java.util.List) Domain(com.zimbra.cs.account.Domain) HashMap(java.util.HashMap) Map(java.util.Map) DistributionList(com.zimbra.cs.account.DistributionList)

Example 15 with LdapProv

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

the class TestProvAlias method testCreateAlias_aliasExistAndDangling.

/*
     * test adding an alias to account but the alias is "dangling"
     * i.e. the alias entry exists but points to a non-existing entry
     * 
     * The dangling alias should be removed then recreated and then added to the account
     */
@Test
public void testCreateAlias_aliasExistAndDangling() throws Exception {
    String testName = getTestName();
    // create the domain
    String domainName = underscoreToHyphen(testName) + "." + BASE_DOMAIN_NAME;
    domainName = domainName.toLowerCase();
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraDomainType, Provisioning.DomainType.local.name());
    Domain domain = prov.createDomain(domainName, attrs);
    // create the account
    String acctName = getEmail("acct-1", domainName);
    Account acct = prov.createAccount(acctName, PASSWORD, new HashMap<String, Object>());
    // add an alias to the account
    String aliasName = getEmail("alias-1", domainName);
    prov.addAlias(acct, aliasName);
    // remember the zimbraId of the alias entry
    List<NamedEntry> aliases = searchAliasesInDomain(domain);
    assertEquals(aliases.size(), 1);
    String origZimbraIdOfAlias = aliases.get(0).getId();
    // create 2 DLs
    String dl1Name = getEmail("dl-1", domainName);
    DistributionList dl1 = prov.createDistributionList(dl1Name, new HashMap<String, Object>());
    String dl2Name = getEmail("dl-2", domainName);
    DistributionList dl2 = prov.createDistributionList(dl2Name, new HashMap<String, Object>());
    // add the alias to the two DLs
    prov.addMembers(dl1, new String[] { aliasName });
    prov.addMembers(dl2, new String[] { aliasName });
    // now, hack it to delete the orig account entry
    {
        LdapEntry ldapAccount = (LdapEntry) acct;
        ((LdapProv) prov).getHelper().deleteEntry(ldapAccount.getDN(), LdapUsage.UNITTEST);
    }
    // now , try to add the alias to another account
    String otherAcctName = getEmail("acct-other", domainName);
    Account otherAcct = prov.createAccount(otherAcctName, PASSWORD, new HashMap<String, Object>());
    prov.addAlias(otherAcct, aliasName);
    // reload all entries
    // mProv.reload(acct); this account should be gone already
    prov.reload(otherAcct);
    prov.reload(dl1);
    prov.reload(dl2);
    Set<String> values;
    // ensure the alias is added to the other account
    values = acct.getMultiAttrSet(Provisioning.A_mail);
    assertTrue(values.contains(aliasName));
    values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
    assertTrue(values.contains(aliasName));
    // ensure the alias is removed from all the DLs
    values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertFalse(values.contains(aliasName));
    values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertFalse(values.contains(aliasName));
    // ensure the alias entry is is recreated (by verifing that it's got a diff zimbraId)
    aliases = searchAliasesInDomain(domain);
    assertEquals(aliases.size(), 1);
    assertFalse(aliases.get(0).getId().equals(origZimbraIdOfAlias));
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapProv(com.zimbra.cs.account.ldap.LdapProv) NamedEntry(com.zimbra.cs.account.NamedEntry) Domain(com.zimbra.cs.account.Domain) DistributionList(com.zimbra.cs.account.DistributionList)

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