Search in sources :

Example 36 with LdapProv

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

the class TestProvAlias method testRemoveAlias_entryExist_aliasExist_aliasPointToNonExistEntry.

//
// A - alias points to a non-existing entry
// 
@Test
public void testRemoveAlias_entryExist_aliasExist_aliasPointToNonExistEntry() throws Exception {
    String testName = getTestName();
    // create the domain
    String domainName = "EE-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);
    }
    // remove the alias
    // ensure we *do* get a NO_SUCH_ALIAS exception
    boolean good = false;
    try {
        prov.removeAlias(acct, aliasName);
    } catch (ServiceException e) {
        assertEquals(e.getCode(), (AccountServiceException.NO_SUCH_ALIAS));
        good = true;
    }
    assertTrue(good);
    // reload all entries
    prov.reload(acct);
    prov.reload(dl1);
    prov.reload(dl2);
    Set<String> values;
    // ensure the alias is removed from the account's mail/zimbraMailAlias attrs
    values = acct.getMultiAttrSet(Provisioning.A_mail);
    assertFalse(values.contains(aliasName));
    values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
    assertFalse(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) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) 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 37 with LdapProv

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

the class TestObjectClass method getAttrsInOCs.

@Test
public void getAttrsInOCs() throws Exception {
    LdapProv ldapProv = (LdapProv) prov;
    String[] ocs = { "amavisAccount" };
    Set<String> attrsInOCs = new HashSet<String>();
    ldapProv.getAttrsInOCs(ocs, attrsInOCs);
    assertEquals(48, attrsInOCs.size());
    assertTrue(attrsInOCs.contains("amavisBlacklistSender"));
    assertTrue(attrsInOCs.contains("amavisWhitelistSender"));
/*
        int i = 1;
        for (String attr : attrsInOCs) {
            System.out.println(i++ + " " + attr);
        }
        */
}
Also used : LdapProv(com.zimbra.cs.account.ldap.LdapProv) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with LdapProv

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

the class TestProvAlias method testRemoveAlias_entryExist_aliasNotExist.

//
// B
//
@Test
public void testRemoveAlias_entryExist_aliasNotExist() throws Exception {
    String testName = getTestName();
    // create the domain
    String domainName = "EE-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);
    }
    // remove the alias
    // ensure we *do* get a NO_SUCH_ALIAS exception
    boolean good = false;
    try {
        prov.removeAlias(acct, aliasName);
    } catch (ServiceException e) {
        assertEquals(e.getCode(), (AccountServiceException.NO_SUCH_ALIAS));
        good = true;
    }
    assertTrue(good);
    // reload all entries
    prov.reload(acct);
    prov.reload(dl1);
    prov.reload(dl2);
    Set<String> values;
    // ensure the alias is removed from the account's mail/zimbraMailAlias attrs
    values = acct.getMultiAttrSet(Provisioning.A_mail);
    assertFalse(values.contains(aliasName));
    values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
    assertFalse(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) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionList(com.zimbra.cs.account.DistributionList) List(java.util.List) 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