Search in sources :

Example 11 with DomainSelector

use of com.zimbra.soap.admin.type.DomainSelector 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>
        */
}
Also used : PrincipalSelector(com.zimbra.soap.admin.type.PrincipalSelector) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DomainSelector(com.zimbra.soap.admin.type.DomainSelector) AutoProvAccountResponse(com.zimbra.soap.admin.message.AutoProvAccountResponse) AutoProvAccountRequest(com.zimbra.soap.admin.message.AutoProvAccountRequest) Domain(com.zimbra.cs.account.Domain) SoapTransport(com.zimbra.common.soap.SoapTransport) AccountInfo(com.zimbra.soap.admin.type.AccountInfo) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

Aggregations

DomainSelector (com.zimbra.soap.admin.type.DomainSelector)11 ServiceException (com.zimbra.common.service.ServiceException)5 HABOrgUnitRequest (com.zimbra.soap.admin.message.HABOrgUnitRequest)4 HashSet (java.util.HashSet)4 SoapTransport (com.zimbra.common.soap.SoapTransport)3 Domain (com.zimbra.cs.account.Domain)3 CountObjectsRequest (com.zimbra.soap.admin.message.CountObjectsRequest)3 CountObjectsResponse (com.zimbra.soap.admin.message.CountObjectsResponse)3 HABOrgUnitResponse (com.zimbra.soap.admin.message.HABOrgUnitResponse)3 Test (org.junit.Test)3 SoapFaultException (com.zimbra.common.soap.SoapFaultException)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Provisioning (com.zimbra.cs.account.Provisioning)2 SoapTest (com.zimbra.qa.unittest.prov.soap.SoapTest)2 GetDomainInfoRequest (com.zimbra.soap.admin.message.GetDomainInfoRequest)2 GetDomainInfoResponse (com.zimbra.soap.admin.message.GetDomainInfoResponse)2 DomainInfo (com.zimbra.soap.admin.type.DomainInfo)2 UCService (com.zimbra.cs.account.UCService)1 AdminRight (com.zimbra.cs.account.accesscontrol.AdminRight)1 RightCommand (com.zimbra.cs.account.accesscontrol.RightCommand)1