Search in sources :

Example 91 with NamedEntry

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

the class GrantRights method lookupGranteeByName.

private static NamedEntry lookupGranteeByName(String name, GranteeType type, ZimbraSoapContext zsc) throws ServiceException {
    if (type == GranteeType.GT_AUTHUSER || type == GranteeType.GT_PUBLIC || type == GranteeType.GT_GUEST || type == GranteeType.GT_KEY) {
        return null;
    }
    Provisioning prov = Provisioning.getInstance();
    // for addresses, default to the authenticated user's domain
    if ((type == GranteeType.GT_USER || type == GranteeType.GT_GROUP) && name.indexOf('@') == -1) {
        Account authacct = prov.get(AccountBy.id, zsc.getAuthtokenAccountId(), zsc.getAuthToken());
        String authname = (authacct == null ? null : authacct.getName());
        if (authacct != null) {
            name += authname.substring(authname.indexOf('@'));
        }
    }
    NamedEntry nentry = null;
    if (name != null)
        switch(type) {
            case GT_USER:
                nentry = lookupEmailAddress(name);
                break;
            case GT_GROUP:
                nentry = prov.get(Key.DistributionListBy.name, name);
                break;
            case GT_DOMAIN:
                nentry = prov.get(Key.DomainBy.name, name);
                break;
        }
    if (nentry != null) {
        return nentry;
    }
    switch(type) {
        case GT_USER:
            throw AccountServiceException.NO_SUCH_ACCOUNT(name);
        case GT_GROUP:
            throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(name);
        case GT_DOMAIN:
            throw AccountServiceException.NO_SUCH_DOMAIN(name);
        default:
            throw ServiceException.FAILURE("LDAP entry not found for " + name + " : " + type, null);
    }
}
Also used : GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) Provisioning(com.zimbra.cs.account.Provisioning)

Example 92 with NamedEntry

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

the class GrantRights method lookupGranteeByZimbraId.

private static NamedEntry lookupGranteeByZimbraId(String zid, GranteeType type, boolean granting) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    NamedEntry nentry = null;
    try {
        switch(type) {
            case GT_USER:
                nentry = prov.get(AccountBy.id, zid);
                if (nentry == null && granting) {
                    throw AccountServiceException.NO_SUCH_ACCOUNT(zid);
                } else {
                    return nentry;
                }
            case GT_GROUP:
                nentry = prov.get(Key.DistributionListBy.id, zid);
                if (nentry == null && granting) {
                    throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(zid);
                } else {
                    return nentry;
                }
            case GT_DOMAIN:
                nentry = prov.get(Key.DomainBy.id, zid);
                if (nentry == null && granting) {
                    throw AccountServiceException.NO_SUCH_DOMAIN(zid);
                } else {
                    return nentry;
                }
            case GT_GUEST:
            case GT_KEY:
            case GT_AUTHUSER:
            case GT_PUBLIC:
            default:
                return null;
        }
    } catch (ServiceException e) {
        if (granting) {
            throw e;
        } else {
            return null;
        }
    }
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 93 with NamedEntry

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

the class GrantRights method lookupEmailAddress.

private static NamedEntry lookupEmailAddress(String name) throws ServiceException {
    NamedEntry nentry = null;
    Provisioning prov = Provisioning.getInstance();
    nentry = prov.get(AccountBy.name, name);
    //look for both distribution list and dynamic group
    if (nentry == null) {
        nentry = prov.getGroup(Key.DistributionListBy.name, name);
    }
    return nentry;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Provisioning(com.zimbra.cs.account.Provisioning)

Example 94 with NamedEntry

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

the class TestProvAlias method testRemoveAlias_entryExist_aliasExist_aliasPointToOtherEntry.

//
// A - alias points to other existing entry
//
@Test
public void testRemoveAlias_entryExist_aliasExist_aliasPointToOtherEntry() throws Exception {
    String testName = getTestName();
    // create the domain
    String domainName = "EE-AE-aliasPointToOtherEntry" + "." + 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 the alias points to
    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 });
    // create another account
    String otherAcctName = getEmail("acct-other", domainName);
    Account otherAcct = prov.createAccount(otherAcctName, PASSWORD, new HashMap<String, Object>());
    // and hack the other account to also contain the alias in it's mail/zimbraMailAlias attrs
    // the hacked attrs should be removed after the removeAlais call
    {
        Map<String, Object> attributes = new HashMap<String, Object>();
        // can no long do this, we now have an unique constraint on mail
        // attributes.put(Provisioning.A_mail, aliasName);
        attributes.put(Provisioning.A_zimbraMailAlias, aliasName);
        LdapEntry ldapAccount = (LdapEntry) otherAcct;
        ((LdapProv) prov).getHelper().modifyEntry(ldapAccount.getDN(), attributes, (Entry) ldapAccount, LdapUsage.UNITTEST);
        // make sure the attrs did get hacked in
        prov.reload(otherAcct);
        Set<String> values;
        // values = otherAcct.getMultiAttrSet(Provisioning.A_mail);
        // assertTrue(values.contains(aliasName));
        values = otherAcct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
        assertTrue(values.contains(aliasName));
    }
    // remove the alias, on the "other" account, which is *not* the target for the alias we are removing
    // ensure we *do* get a NO_SUCH_ALIAS exception
    boolean good = false;
    try {
        prov.removeAlias(otherAcct, aliasName);
    } catch (ServiceException e) {
        assertEquals(e.getCode(), (AccountServiceException.NO_SUCH_ALIAS));
        good = true;
    }
    assertTrue(good);
    // reload all entries
    prov.reload(acct);
    prov.reload(otherAcct);
    prov.reload(dl1);
    prov.reload(dl2);
    Set<String> values;
    // ensure the alias is still on the account
    values = acct.getMultiAttrSet(Provisioning.A_mail);
    assertTrue(values.contains(aliasName));
    values = acct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
    assertTrue(values.contains(aliasName));
    // ensure the hacked in attrs are removed from the other account
    values = otherAcct.getMultiAttrSet(Provisioning.A_mail);
    assertFalse(values.contains(aliasName));
    values = otherAcct.getMultiAttrSet(Provisioning.A_zimbraMailAlias);
    assertFalse(values.contains(aliasName));
    // ensure the alias is *not* removed from any the DLs
    values = dl1.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertTrue(values.contains(aliasName));
    values = dl2.getMultiAttrSet(Provisioning.A_zimbraMailForwardingAddress);
    assertTrue(values.contains(aliasName));
    // ensure the alias entry is *not* removed
    List<NamedEntry> aliases = searchAliasesInDomain(domain);
    assertEquals(aliases.size(), 1);
    assertTrue(aliases.get(0).getName().equals(aliasName));
}
Also used : Account(com.zimbra.cs.account.Account) Set(java.util.Set) 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) Domain(com.zimbra.cs.account.Domain) HashMap(java.util.HashMap) Map(java.util.Map) DistributionList(com.zimbra.cs.account.DistributionList)

Example 95 with NamedEntry

use of com.zimbra.cs.account.NamedEntry 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)

Aggregations

NamedEntry (com.zimbra.cs.account.NamedEntry)109 Account (com.zimbra.cs.account.Account)51 ServiceException (com.zimbra.common.service.ServiceException)26 Domain (com.zimbra.cs.account.Domain)24 Provisioning (com.zimbra.cs.account.Provisioning)23 AccountServiceException (com.zimbra.cs.account.AccountServiceException)19 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)19 DistributionList (com.zimbra.cs.account.DistributionList)18 SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)18 HashSet (java.util.HashSet)17 Entry (com.zimbra.cs.account.Entry)15 HashMap (java.util.HashMap)15 Element (com.zimbra.common.soap.Element)14 Group (com.zimbra.cs.account.Group)14 SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)12 GuestAccount (com.zimbra.cs.account.GuestAccount)8 MailTarget (com.zimbra.cs.account.MailTarget)8 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 AccessManager (com.zimbra.cs.account.AccessManager)7 DynamicGroup (com.zimbra.cs.account.DynamicGroup)7