Search in sources :

Example 6 with DataSourceType

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

the class ModifyDataSource method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    //boolean wipeOutOldData = false;
    Element eDataSource = CreateDataSource.getDataSourceElement(request);
    DataSourceType type = DataSourceType.fromString(eDataSource.getName());
    String id = eDataSource.getAttribute(MailConstants.A_ID);
    DataSource ds = prov.get(account, Key.DataSourceBy.id, id);
    if (ds == null) {
        throw ServiceException.INVALID_REQUEST("Unable to find data source with id=" + id, null);
    }
    Map<String, Object> dsAttrs = new HashMap<String, Object>();
    String value = eDataSource.getAttribute(MailConstants.A_NAME, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceName, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_IS_ENABLED, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapUtil.getLdapBooleanString(eDataSource.getAttributeBool(MailConstants.A_DS_IS_ENABLED)));
    }
    value = eDataSource.getAttribute(MailConstants.A_FOLDER, null);
    if (value != null) {
        Mailbox mbox = getRequestedMailbox(zsc);
        CreateDataSource.validateFolderId(account, mbox, eDataSource, type);
        dsAttrs.put(Provisioning.A_zimbraDataSourceFolderId, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_HOST, null);
    if (value != null && !value.equals(ds.getHost())) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceHost, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_PORT, null);
    if (value != null)
        dsAttrs.put(Provisioning.A_zimbraDataSourcePort, value);
    value = eDataSource.getAttribute(MailConstants.A_DS_CONNECTION_TYPE, null);
    if (value != null)
        dsAttrs.put(Provisioning.A_zimbraDataSourceConnectionType, value);
    value = eDataSource.getAttribute(MailConstants.A_DS_USERNAME, null);
    if (value != null && !value.equals(ds.getUsername())) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceUsername, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_PASSWORD, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourcePassword, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_OAUTH_TOKEN, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthToken, value);
        dsAttrs.put(Provisioning.A_zimbraDataSourceAuthMechanism, ZAttrProvisioning.DataSourceAuthMechanism.XOAUTH2.name());
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_CLIENT_ID, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthClientId, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_CLIENT_SECRET, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthClientSecret, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_REFRESH_TOKEN, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthRefreshToken, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_REFRESH_TOKEN_URL, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthRefreshTokenUrl, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_LEAVE_ON_SERVER, null);
    if (value != null) {
        if (type != DataSourceType.pop3) {
            String msg = String.format("%s only allowed for %s data sources", MailConstants.A_DS_LEAVE_ON_SERVER, MailConstants.E_DS_POP3);
            throw ServiceException.INVALID_REQUEST(msg, null);
        }
        boolean newValue = eDataSource.getAttributeBool(MailConstants.A_DS_LEAVE_ON_SERVER);
        if (newValue != ds.leaveOnServer()) {
            dsAttrs.put(Provisioning.A_zimbraDataSourceLeaveOnServer, LdapUtil.getLdapBooleanString(newValue));
            Mailbox mbox = getRequestedMailbox(zsc);
            DbPop3Message.deleteUids(mbox, ds.getId());
            DbDataSource.deleteAllMappings(ds);
        }
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_POLLING_INTERVAL, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourcePollingInterval, value);
    }
    // import class
    String importClass = eDataSource.getAttribute(MailConstants.A_DS_IMPORT_CLASS, DataSourceManager.getDefaultImportClass(type));
    if (importClass != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceImportClassName, importClass);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_SMTP_ENABLED, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceSmtpEnabled, LdapUtil.getLdapBooleanString(eDataSource.getAttributeBool(MailConstants.A_DS_SMTP_ENABLED)));
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_SMTP_HOST, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceSmtpHost, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_SMTP_PORT, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceSmtpPort, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_SMTP_CONNECTION_TYPE, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceSmtpConnectionType, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_SMTP_AUTH_REQUIRED, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceSmtpAuthRequired, LdapUtil.getLdapBooleanString(eDataSource.getAttributeBool(MailConstants.A_DS_SMTP_AUTH_REQUIRED)));
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_SMTP_USERNAME, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceSmtpAuthUsername, value);
    }
    value = eDataSource.getAttribute(MailConstants.A_DS_SMTP_PASSWORD, null);
    if (value != null) {
        dsAttrs.put(Provisioning.A_zimbraDataSourceSmtpAuthPassword, value);
    }
    if (eDataSource.getAttributeBool(MailConstants.A_DS_TEST, false)) {
        TestDataSource.testDataSourceConnection(prov, eDataSource, type, account);
    }
    processCommonOptionalAttrs(dsAttrs, eDataSource);
    prov.modifyDataSource(account, id, dsAttrs);
    Element response = zsc.createElement(MailConstants.MODIFY_DATA_SOURCE_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) DataSourceType(com.zimbra.soap.admin.type.DataSourceType) ZAttrProvisioning(com.zimbra.common.account.ZAttrProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource) DbDataSource(com.zimbra.cs.db.DbDataSource)

Example 7 with DataSourceType

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

the class AccountUtil method getImapPop3EmailAddresses.

/**
     * Gets all email addresses for the imap and pop3 external accounts for the given account.
     * @param acct
     * @return
     * @throws ServiceException
     */
public static Set<String> getImapPop3EmailAddresses(Account acct) throws ServiceException {
    List<DataSource> dataSources = acct.getAllDataSources();
    Set<String> addrs = new HashSet<String>();
    for (DataSource dataSource : dataSources) {
        DataSourceType dataSourceType = dataSource.getType();
        if (dataSourceType == DataSourceType.imap || dataSourceType == DataSourceType.pop3) {
            addrs.add(dataSource.getEmailAddress().toLowerCase());
        }
    }
    return addrs;
}
Also used : DataSourceType(com.zimbra.soap.admin.type.DataSourceType) DataSource(com.zimbra.cs.account.DataSource) HashSet(java.util.HashSet)

Example 8 with DataSourceType

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

the class CreateDataSource method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    String id = request.getAttribute(AdminConstants.E_ID);
    Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
    if (account == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(id);
    checkAdminLoginAsRight(zsc, prov, account);
    Element dsEl = request.getElement(AccountConstants.E_DATA_SOURCE);
    Map<String, Object> attrs = AdminService.getAttrs(dsEl);
    DataSourceType type = DataSourceType.fromString(dsEl.getAttribute(AccountConstants.A_TYPE));
    // Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager 
    if (isDomainAdminOnly(zsc)) {
        // yuck, can't really integrate into AdminDocumentHandler methods cleanly
        // have to check separately here
        AttributeClass klass = ModifyDataSource.getAttributeClassFromType(type);
        checkModifyAttrs(zsc, klass, attrs);
    }
    String name = dsEl.getAttribute(AccountConstants.A_NAME);
    DataSource ds = Provisioning.getInstance().createDataSource(account, type, name, attrs);
    Element response = zsc.createElement(AdminConstants.CREATE_DATA_SOURCE_RESPONSE);
    com.zimbra.cs.service.account.ToXML.encodeDataSource(response, ds);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) DataSourceType(com.zimbra.soap.admin.type.DataSourceType) AttributeClass(com.zimbra.cs.account.AttributeClass) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

DataSourceType (com.zimbra.soap.admin.type.DataSourceType)8 Account (com.zimbra.cs.account.Account)7 DataSource (com.zimbra.cs.account.DataSource)7 Provisioning (com.zimbra.cs.account.Provisioning)7 Element (com.zimbra.common.soap.Element)6 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)6 DbDataSource (com.zimbra.cs.db.DbDataSource)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 HashMap (java.util.HashMap)3 ServiceException (com.zimbra.common.service.ServiceException)2 AttributeClass (com.zimbra.cs.account.AttributeClass)2 ConcurrentLinkedHashMap (com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap)1 ZAttrProvisioning (com.zimbra.common.account.ZAttrProvisioning)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Folder (com.zimbra.cs.mailbox.Folder)1 ParsedMessageDataSource (com.zimbra.cs.mime.ParsedMessageDataSource)1 MailboxBlobDataSource (com.zimbra.cs.store.MailboxBlobDataSource)1 ModifyDataSourceRequest (com.zimbra.soap.admin.message.ModifyDataSourceRequest)1 DataSourceInfo (com.zimbra.soap.admin.type.DataSourceInfo)1 HashSet (java.util.HashSet)1