Search in sources :

Example 1 with GalMode

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

the class CreateGalSyncAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    CreateGalSyncAccountRequest cgaRequest = zsc.elementToJaxb(request);
    String name = cgaRequest.getName();
    String domainStr = cgaRequest.getDomain();
    GalMode type = cgaRequest.getType();
    AccountSelector acctSelector = cgaRequest.getAccount();
    AccountBy acctBy = acctSelector.getBy();
    String acctValue = acctSelector.getKey();
    String password = cgaRequest.getPassword();
    String folder = cgaRequest.getFolder();
    String mailHost = cgaRequest.getMailHost();
    Domain domain = prov.getDomainByName(domainStr);
    if (domain == null) {
        throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
    }
    Account account = null;
    try {
        account = prov.get(acctBy.toKeyAccountBy(), acctValue, zsc.getAuthToken());
    } catch (ServiceException se) {
        ZimbraLog.gal.warn("error checking GalSyncAccount", se);
    }
    // create the system account if not already exists.
    if (account == null) {
        if (acctBy != AccountBy.name) {
            throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
        }
        // there should be one gal sync account per domain per mailhost
        for (String acctId : domain.getGalAccountId()) {
            Account acct = prov.getAccountById(acctId);
            if ((acct != null) && (acct.getMailHost().equals(mailHost))) {
                throw AccountServiceException.ACCOUNT_EXISTS(acct.getName());
            }
        }
        // XXX revisit
        checkDomainRightByEmail(zsc, acctValue, Admin.R_createAccount);
        Map<String, Object> accountAttrs = new HashMap<String, Object>();
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraIsSystemResource, LdapConstants.LDAP_TRUE);
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraIsSystemAccount, LdapConstants.LDAP_TRUE);
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraHideInGal, LdapConstants.LDAP_TRUE);
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraContactMaxNumEntries, "0");
        StringUtil.addToMultiMap(accountAttrs, Provisioning.A_zimbraMailHost, mailHost);
        checkSetAttrsOnCreate(zsc, TargetType.account, acctValue, accountAttrs);
        account = prov.createAccount(acctValue, password, accountAttrs);
    }
    if (!Provisioning.onLocalServer(account)) {
        String host = account.getMailHost();
        Server server = prov.getServerByName(host);
        return proxyRequest(request, context, server);
    }
    addDataSource(request, zsc, account, domain, folder, name, type);
    Element response = zsc.createElement(AdminConstants.CREATE_GAL_SYNC_ACCOUNT_RESPONSE);
    ToXML.encodeAccount(response, account, false, emptySet, null);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) GalMode(com.zimbra.soap.admin.type.GalMode) Server(com.zimbra.cs.account.Server) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) Provisioning(com.zimbra.cs.account.Provisioning) CreateGalSyncAccountRequest(com.zimbra.soap.admin.message.CreateGalSyncAccountRequest) AccountBy(com.zimbra.soap.type.AccountBy) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Domain(com.zimbra.cs.account.Domain)

Example 2 with GalMode

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

the class AddGalSyncDataSource method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    AddGalSyncDataSourceRequest dsRequest = zsc.elementToJaxb(request);
    String name = dsRequest.getName();
    String domainStr = dsRequest.getDomain();
    GalMode type = dsRequest.getType();
    AccountSelector acctSelector = dsRequest.getAccount();
    AccountBy acctBy = acctSelector.getBy();
    String acctValue = acctSelector.getKey();
    String folder = dsRequest.getFolder();
    Domain domain = prov.getDomainByName(domainStr);
    if (domain == null) {
        throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
    }
    Account account = null;
    try {
        account = prov.get(acctBy.toKeyAccountBy(), acctValue, zsc.getAuthToken());
    } catch (ServiceException se) {
        ZimbraLog.gal.warn("error checking GalSyncAccount", se);
    }
    if (account == null) {
        throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
    }
    if (!Provisioning.onLocalServer(account)) {
        String host = account.getMailHost();
        Server server = prov.getServerByName(host);
        return proxyRequest(request, context, server);
    }
    CreateGalSyncAccount.addDataSource(request, zsc, account, domain, folder, name, type);
    Element response = zsc.createElement(AdminConstants.ADD_GAL_SYNC_DATASOURCE_RESPONSE);
    ToXML.encodeAccount(response, account, false, emptySet, null);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) GalMode(com.zimbra.soap.admin.type.GalMode) AddGalSyncDataSourceRequest(com.zimbra.soap.admin.message.AddGalSyncDataSourceRequest) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Server(com.zimbra.cs.account.Server) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.soap.type.AccountBy)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)2 Element (com.zimbra.common.soap.Element)2 Account (com.zimbra.cs.account.Account)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Domain (com.zimbra.cs.account.Domain)2 Provisioning (com.zimbra.cs.account.Provisioning)2 Server (com.zimbra.cs.account.Server)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 GalMode (com.zimbra.soap.admin.type.GalMode)2 AccountBy (com.zimbra.soap.type.AccountBy)2 AccountSelector (com.zimbra.soap.type.AccountSelector)2 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 AddGalSyncDataSourceRequest (com.zimbra.soap.admin.message.AddGalSyncDataSourceRequest)1 CreateGalSyncAccountRequest (com.zimbra.soap.admin.message.CreateGalSyncAccountRequest)1 HashMap (java.util.HashMap)1