Search in sources :

Example 1 with AccountInfo

use of com.zimbra.soap.admin.type.AccountInfo in project zm-mailbox by Zimbra.

the class SoapProvisioning method searchDirectory.

@Override
public List<NamedEntry> searchDirectory(SearchDirectoryOptions options) throws ServiceException {
    List<NamedEntry> result = new ArrayList<NamedEntry>();
    SearchDirectoryRequest req = new SearchDirectoryRequest();
    req.setQuery(options.getFilterString());
    if (options.getMaxResults() != 0) {
        req.setMaxResults(options.getMaxResults());
    }
    if (options.getDomain() != null) {
        req.setDomain(options.getDomain().getName());
    }
    if (options.getSortAttr() != null) {
        req.setSortBy(options.getSortAttr());
    }
    Set<SearchDirectoryOptions.ObjectType> types = options.getTypes();
    if (types != null) {
        req.setTypes(SearchDirectoryOptions.ObjectType.toCSVString(types));
    }
    req.setSortAscending(options.getSortOpt() != SortOpt.SORT_DESCENDING);
    if (options.getReturnAttrs() != null) {
        req.addAttrs(options.getReturnAttrs());
    }
    // TODO: handle ApplyCos, limit, offset?
    SearchDirectoryResponse resp = invokeJaxb(req);
    List<AdminObjectInterface> entries = resp.getEntries();
    for (AdminObjectInterface entry : entries) {
        if (entry instanceof AccountInfo) {
            result.add(new SoapAccount((AccountInfo) entry, this));
        } else if (entry instanceof CalendarResourceInfo) {
            result.add(new SoapCalendarResource((CalendarResourceInfo) entry, this));
        } else if (entry instanceof AliasInfo) {
            result.add(new SoapAlias((AliasInfo) entry, this));
        } else if (entry instanceof DistributionListInfo) {
            result.add(new SoapDistributionList((DistributionListInfo) entry, this));
        } else if (entry instanceof DomainInfo) {
            result.add(new SoapDomain((DomainInfo) entry, this));
        }
    }
    return result;
}
Also used : DistributionListInfo(com.zimbra.soap.admin.type.DistributionListInfo) CalendarResourceInfo(com.zimbra.soap.admin.type.CalendarResourceInfo) ArrayList(java.util.ArrayList) NamedEntry(com.zimbra.cs.account.NamedEntry) AliasInfo(com.zimbra.soap.admin.type.AliasInfo) DomainInfo(com.zimbra.soap.admin.type.DomainInfo) AdminObjectInterface(com.zimbra.soap.admin.type.AdminObjectInterface) AccountInfo(com.zimbra.soap.admin.type.AccountInfo)

Example 2 with AccountInfo

use of com.zimbra.soap.admin.type.AccountInfo in project zm-mailbox by Zimbra.

the class SoapProvisioning method getAllAdminAccounts.

// SoapProvisioning only, for zmprov
public List<Account> getAllAdminAccounts(boolean applyDefault) throws ServiceException {
    ArrayList<Account> result = new ArrayList<Account>();
    GetAllAdminAccountsResponse resp = invokeJaxb(new GetAllAdminAccountsRequest(applyDefault));
    for (AccountInfo acct : resp.getAccountList()) {
        result.add(new SoapAccount(acct, this));
    }
    return result;
}
Also used : Account(com.zimbra.cs.account.Account) ArrayList(java.util.ArrayList) AccountInfo(com.zimbra.soap.admin.type.AccountInfo)

Example 3 with AccountInfo

use of com.zimbra.soap.admin.type.AccountInfo 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

AccountInfo (com.zimbra.soap.admin.type.AccountInfo)3 ArrayList (java.util.ArrayList)2 ServiceException (com.zimbra.common.service.ServiceException)1 SoapTransport (com.zimbra.common.soap.SoapTransport)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Domain (com.zimbra.cs.account.Domain)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 Bug (com.zimbra.qa.QA.Bug)1 AutoProvAccountRequest (com.zimbra.soap.admin.message.AutoProvAccountRequest)1 AutoProvAccountResponse (com.zimbra.soap.admin.message.AutoProvAccountResponse)1 AdminObjectInterface (com.zimbra.soap.admin.type.AdminObjectInterface)1 AliasInfo (com.zimbra.soap.admin.type.AliasInfo)1 CalendarResourceInfo (com.zimbra.soap.admin.type.CalendarResourceInfo)1 DistributionListInfo (com.zimbra.soap.admin.type.DistributionListInfo)1 DomainInfo (com.zimbra.soap.admin.type.DomainInfo)1 DomainSelector (com.zimbra.soap.admin.type.DomainSelector)1 PrincipalSelector (com.zimbra.soap.admin.type.PrincipalSelector)1 Test (org.junit.Test)1