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);
}
}
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);
}
}
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);
}
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);
}
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));
}
Aggregations