use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestAutoProvision method errorHandling.
@Test
@Bug(bug = 70720)
public void errorHandling() throws Exception {
/*
* create and setup zimbra domain
*/
Map<String, Object> domainAttrs = Maps.newHashMap();
domainAttrs.put(Provisioning.A_zimbraAutoProvLdapURL, "ldap://localhost:389");
domainAttrs.put(Provisioning.A_zimbraAutoProvLdapAdminBindDn, extDomainAdminBindDn);
domainAttrs.put(Provisioning.A_zimbraAutoProvLdapAdminBindPassword, extDomainAdminBindPassword);
StringUtil.addToMultiMap(domainAttrs, Provisioning.A_zimbraAutoProvMode, AutoProvMode.LAZY.name());
StringUtil.addToMultiMap(domainAttrs, Provisioning.A_zimbraAutoProvMode, AutoProvMode.MANUAL.name());
domainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(cn=auth*)");
// domainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(cn=%n)");
domainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
domainAttrs.put(Provisioning.A_zimbraAutoProvAccountNameMap, "cn");
domainAttrs.put(Provisioning.A_zimbraAutoProvAttrMap, "userPassword=userPassword");
Domain domain = createZimbraDomain(genDomainSegmentName(), domainAttrs);
/*
* create external accounts
*/
Map<String, Object> extAcct1Attrs = Maps.newHashMap();
extAcct1Attrs.put("cn", "authaccount01");
createExternalAcctEntry("acct1", "test123", extAcct1Attrs);
Map<String, Object> extAcct2Attrs = Maps.newHashMap();
extAcct2Attrs.put("cn", "authaccount02");
createExternalAcctEntry("acct2", "test123", extAcct2Attrs);
Map<String, Object> extAcct3Attrs = Maps.newHashMap();
extAcct3Attrs.put("cn", "authaccount03");
createExternalAcctEntry("acct3", "test123", extAcct3Attrs);
Map<String, Object> extAcct4Attrs = Maps.newHashMap();
extAcct4Attrs.put("cn", "authaccount04");
createExternalAcctEntry("acct4", "test123", extAcct4Attrs);
/*
* do a manual auto provision
*/
SoapTransport transport = authZimbraAdmin();
DomainSelector domainSel = new DomainSelector(DomainSelector.DomainBy.name, domain.getName());
PrincipalSelector principalSel = PrincipalSelector.create(AutoProvPrincipalBy.name, "authaccount04");
AutoProvAccountRequest req = AutoProvAccountRequest.create(domainSel, principalSel);
boolean caughtException = false;
try {
invokeJaxb(transport, req);
} catch (ServiceException e) {
String msg = e.getMessage();
if (e.getCode().equals(LdapException.MULTIPLE_ENTRIES_MATCHED) && msg.contains(String.format("uid=acct1,ou=people,%s", extDomainDn)) && msg.contains(String.format("uid=acct2,ou=people,%s", extDomainDn)) && msg.contains(String.format("uid=acct3,ou=people,%s", extDomainDn)) && msg.contains(String.format("uid=acct4,ou=people,%s", extDomainDn))) {
caughtException = true;
}
}
assertTrue(caughtException);
/*
* modify domain to have the correct search filter
*/
domain.setAutoProvLdapSearchFilter("(cn=%n)");
/*
* do the manual provision, should succeed this time
*/
AutoProvAccountResponse resp = invokeJaxb(transport, req);
AccountInfo acctInfo = resp.getAccount();
assertEquals(TestUtil.getAddress("authaccount04", domain.getName()), acctInfo.getName());
/*
* do the same manual provision again, should fail with
*/
caughtException = false;
try {
invokeJaxb(transport, req);
} catch (ServiceException e) {
String msg = e.getMessage();
if (e.getCode().equals(AccountServiceException.ACCOUNT_EXISTS)) {
caughtException = true;
}
}
assertTrue(caughtException);
/*
<CreateDomainRequest xmlns="urn:zimbraAdmin">
<name>autoprov44.1330496906457.com</name>
<a n="zimbraAutoProvLdapURL">ldap://zqa-003.eng.vmware.com:389/</a>
<a n="zimbraAutoProvLdapAdminBindDn">administrator@zimbraqa.com</a>
<a n="zimbraAutoProvLdapAdminBindPassword">liquidsys</a>
<a n="zimbraAutoProvMode">LAZY</a>
<a n="zimbraAutoProvMode">MANUAL</a>
<a n="zimbraAutoProvLdapSearchFilter">(cn=auth*)</a>
<a n="zimbraAutoProvLdapSearchBase">OU=CommonUsers,DC=zimbraqa,DC=com</a>
<a n="zimbraAutoProvAccountNameMap">cn</a>
<a n="zimbraAutoProvAttrMap">userPassword=userPassword</a>
</CreateDomainRequest>
zmsoap -z AutoProvAccountRequest domain=bug70720.com.zimbra.qa.unittest.prov.soap.testautoprovision.soaptest.unittest @by=name ../principal=authaccount04 @by=name
this zmsoap yields the following soap:
<AutoProvAccountRequest xmlns="urn:zimbraAdmin">
<domain by="name">bug70720.com.zimbra.qa.unittest.prov.soap.testautoprovision.soaptest.unittest</domain>
<principal by="name">authaccount04</principal>
</AutoProvAccountRequest>
*/
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestAutoProvision method eagerModeDomainUnlockedWhenThreadStopped.
@Test
public void eagerModeDomainUnlockedWhenThreadStopped() throws Exception {
// must be > TestDomainLockListener.HOLD_IT_AT_THIS_ENTRY
int numAccts = TestDomainLockListener.HOLD_IT_AT_THIS_ENTRY + 2;
for (int i = 1; i <= numAccts; i++) {
createExternalAcctEntry("eagerMode-" + i, "test123", null);
}
Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
// setup auto prov
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(&(uid=%u)(mail=eagerMode*)" + AutoProvisionTestUtil.MarkEntryProvisionedListener.NOT_PROVED_FILTER + ")");
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvAccountNameMap, Provisioning.A_uid);
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvListenerClass, TestDomainLockListener.class.getName());
Domain zimbraDomain = createZimbraDomain(genDomainSegmentName(), zimbraDomainAttrs);
// create a domain for the admin so the admin account won't interfere with our account counting
Domain domain = provUtil.createDomain(getZimbraDomainName("admin-domain"));
Account admin = provUtil.createGlobalAdmin(genAcctNameLocalPart(), domain);
SoapTransport transport = authAdmin(admin.getName());
/*
* verify the auto prov thread is not running
*/
verifyAutoProvTask(transport, Action.status, Status.idle);
/*
* change LC key autpprov_initial_sleep_ms to 0, so we don't need to wait that long
* (default is 5 mins)
*/
modifyLocalconfigAndReload(transport, LC.autoprov_initial_sleep_ms, "0");
// schedule the domain on local server
Server localServer = prov.getLocalServer();
localServer.addAutoProvScheduledDomains(zimbraDomain.getName());
/*
* verify the auto prov thread is running
*/
verifyAutoProvTask(transport, Action.status, Status.running);
/*
* let the auto prov thread run for a while, until after the
* TestDomainLockListener.HOLD_IT_AT_THIS_ENTRYth account is auto provisioned
*/
while (true) {
long numAcctsAutoProvisioned = prov.countObjects(CountObjectsType.account, zimbraDomain, null);
if (numAcctsAutoProvisioned == TestDomainLockListener.HOLD_IT_AT_THIS_ENTRY) {
break;
}
System.out.println(getTestName() + " waiting for 1 second");
Thread.sleep(Constants.MILLIS_PER_SECOND);
}
/*
* verify the domain is locked, since the eager auto prov thread should be at work
*/
prov.reload(zimbraDomain);
assertEquals(localServer.getId(), zimbraDomain.getAutoProvLock());
/*
* un-schedule the domain
*/
localServer.unsetAutoProvScheduledDomains();
/*
* verify the thread is stopped, and the domain is unlocked
*/
verifyAutoProvTask(transport, Action.status, Status.idle);
prov.reload(zimbraDomain);
assertNull(zimbraDomain.getAutoProvLock());
/*
* done test, set the LC key back
*/
modifyLocalconfigAndReload(transport, LC.autoprov_initial_sleep_ms, DEFAULT_AUTOPROV_INITIAL_SLEEP_MS);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestCheckRights method defaultPermission.
@Test
public void defaultPermission() throws Exception {
// pair of <right, default permission>
Pair<String, Boolean> right1 = new Pair<String, Boolean>(Right.RT_invite, Boolean.TRUE);
Pair<String, Boolean> right2 = new Pair<String, Boolean>(Right.RT_viewFreeBusy, Boolean.TRUE);
Pair<String, Boolean> right3 = new Pair<String, Boolean>(Right.RT_loginAs, Boolean.FALSE);
Account acct = provUtil.createAccount(genAcctNameLocalPart("acct"), domain);
String targetKey = "not-exist@test.com";
SoapTransport transport = authUser(acct.getName());
CheckRightsRequest req = new CheckRightsRequest();
CheckRightsTargetSpec targetSpec = new CheckRightsTargetSpec(TargetType.account, TargetBy.name, targetKey, Lists.newArrayList(right1.getFirst(), right2.getFirst(), right3.getFirst()));
req.addTarget(targetSpec);
CheckRightsResponse resp = invokeJaxb(transport, req);
List<CheckRightsTargetInfo> targets = resp.getTargets();
for (CheckRightsTargetInfo target : targets) {
assertEquals(TargetType.account, target.getTargetType());
assertEquals(TargetBy.name, target.getTargetBy());
assertEquals(targetKey, target.getTargetKey());
assertEquals(right1.getSecond() && right2.getSecond() && right3.getSecond(), target.getAllow());
Set<String> actual = Sets.newHashSet();
List<CheckRightsRightInfo> rights = target.getRights();
for (CheckRightsRightInfo rightInfo : rights) {
actual.add(rightInfo.getRight() + ":" + rightInfo.getAllow());
}
Verify.verifyEquals(Sets.newHashSet(right1.getFirst() + ":" + right1.getSecond(), right2.getFirst() + ":" + right2.getSecond(), right3.getFirst() + ":" + right3.getSecond()), actual);
}
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestCheckRights method basic.
@Test
public void basic() throws Exception {
String right = Right.RT_loginAs;
Account acct = provUtil.createAccount(genAcctNameLocalPart("target"), domain);
Account target1 = provUtil.createAccount(genAcctNameLocalPart("target1"), domain);
Account target2 = provUtil.createAccount(genAcctNameLocalPart("target2"), domain);
// target1 grant right to acct, target2 does not
grantRight(target1, GranteeType.usr, acct, right);
SoapTransport transport = authUser(acct.getName());
CheckRightsRequest req = new CheckRightsRequest();
req.addTarget(new CheckRightsTargetSpec(TargetType.account, TargetBy.name, target1.getName(), Lists.newArrayList(right)));
req.addTarget(new CheckRightsTargetSpec(TargetType.account, TargetBy.name, target2.getName(), Lists.newArrayList(right)));
CheckRightsResponse resp = invokeJaxb(transport, req);
Set<String> target1Result = Sets.newHashSet();
Set<String> target2Result = Sets.newHashSet();
List<CheckRightsTargetInfo> targets = resp.getTargets();
for (CheckRightsTargetInfo target : targets) {
assertEquals(TargetType.account, target.getTargetType());
assertEquals(TargetBy.name, target.getTargetBy());
String key = target.getTargetKey();
Set<String> result = null;
if (target1.getName().equals(key)) {
assertEquals(true, target.getAllow());
result = target1Result;
} else if (target2.getName().equals(key)) {
assertEquals(false, target.getAllow());
result = target2Result;
} else {
fail();
}
List<CheckRightsRightInfo> rights = target.getRights();
for (CheckRightsRightInfo rightInfo : rights) {
result.add(rightInfo.getRight() + ":" + rightInfo.getAllow());
}
}
Verify.verifyEquals(Sets.newHashSet(right + ":" + true), target1Result);
Verify.verifyEquals(Sets.newHashSet(right + ":" + false), target2Result);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestCheckRights method delegatedSendRight.
@Test
public void delegatedSendRight() throws Exception {
String right = Right.RT_sendAs;
Account acct = provUtil.createAccount(genAcctNameLocalPart("target"), domain);
Account targetAcct = provUtil.createAccount(genAcctNameLocalPart("target-acct"), domain);
String alias1 = TestUtil.getAddress(genAcctNameLocalPart("target-acct-alias-1"), domain.getName());
String alias2 = TestUtil.getAddress(genAcctNameLocalPart("target-acct-alias-2"), domain.getName());
prov.addAlias(targetAcct, alias1);
prov.addAlias(targetAcct, alias2);
prov.modifyAttrs(targetAcct, Collections.singletonMap(Provisioning.A_zimbraPrefAllowAddressForDelegatedSender, alias1));
grantRight(targetAcct, GranteeType.usr, acct, right);
SoapTransport transport = authUser(acct.getName());
CheckRightsRequest req = new CheckRightsRequest();
req.addTarget(new CheckRightsTargetSpec(TargetType.account, TargetBy.name, targetAcct.getName(), Lists.newArrayList(right)));
req.addTarget(new CheckRightsTargetSpec(TargetType.account, TargetBy.name, alias1, Lists.newArrayList(right)));
req.addTarget(new CheckRightsTargetSpec(TargetType.account, TargetBy.name, alias2, Lists.newArrayList(right)));
CheckRightsResponse resp = invokeJaxb(transport, req);
Set<String> primaryMailResult = Sets.newHashSet();
Set<String> alias1Result = Sets.newHashSet();
Set<String> alias2Result = Sets.newHashSet();
List<CheckRightsTargetInfo> targets = resp.getTargets();
for (CheckRightsTargetInfo target : targets) {
assertEquals(TargetType.account, target.getTargetType());
assertEquals(TargetBy.name, target.getTargetBy());
String key = target.getTargetKey();
Set<String> result = null;
if (targetAcct.getName().equals(key)) {
assertEquals(false, target.getAllow());
result = primaryMailResult;
} else if (alias1.equals(key)) {
assertEquals(true, target.getAllow());
result = alias1Result;
} else if (alias2.equals(key)) {
assertEquals(false, target.getAllow());
result = alias2Result;
} else {
fail();
}
List<CheckRightsRightInfo> rights = target.getRights();
for (CheckRightsRightInfo rightInfo : rights) {
result.add(rightInfo.getRight() + ":" + rightInfo.getAllow());
}
}
Verify.verifyEquals(Sets.newHashSet(right + ":" + false), primaryMailResult);
Verify.verifyEquals(Sets.newHashSet(right + ":" + true), alias1Result);
Verify.verifyEquals(Sets.newHashSet(right + ":" + false), alias2Result);
}
Aggregations