Search in sources :

Example 1 with LdapDataSource

use of com.zimbra.cs.account.ldap.entry.LdapDataSource in project zm-mailbox by Zimbra.

the class LdapProvisioning method getDataSourcesByQuery.

private List<DataSource> getDataSourcesByQuery(LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
    List<DataSource> result = new ArrayList<DataSource>();
    try {
        String base = entry.getDN();
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), initZlc, LdapServerType.REPLICA);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            result.add(new LdapDataSource((Account) entry, sr.getDN(), sr.getAttributes(), this));
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup data source via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return result;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) LdapDataSource(com.zimbra.cs.account.ldap.entry.LdapDataSource) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) DataSource(com.zimbra.cs.account.DataSource) LdapDataSource(com.zimbra.cs.account.ldap.entry.LdapDataSource) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 2 with LdapDataSource

use of com.zimbra.cs.account.ldap.entry.LdapDataSource in project zm-mailbox by Zimbra.

the class LdapProvisioning method modifyDataSource.

@Override
public void modifyDataSource(Account account, String dataSourceId, Map<String, Object> attrs) throws ServiceException {
    removeAttrIgnoreCase("objectclass", attrs);
    LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
    if (ldapEntry == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
    LdapDataSource ds = (LdapDataSource) getDataSourceById(ldapEntry, dataSourceId, null);
    if (ds == null)
        throw AccountServiceException.NO_SUCH_DATA_SOURCE(dataSourceId);
    account.setCachedData(DATA_SOURCE_LIST_CACHE_KEY, null);
    attrs.remove(A_zimbraDataSourceId);
    String name = (String) attrs.get(A_zimbraDataSourceName);
    boolean newName = (name != null && !name.equals(ds.getName()));
    if (newName)
        attrs.remove(A_zimbraDataSourceName);
    String password = (String) attrs.get(A_zimbraDataSourcePassword);
    if (password != null) {
        attrs.put(A_zimbraDataSourcePassword, DataSource.encryptData(ds.getId(), password));
    }
    String oauthToken = (String) attrs.get(A_zimbraDataSourceOAuthToken);
    if (oauthToken != null) {
        attrs.put(A_zimbraDataSourceOAuthToken, DataSource.encryptData(ds.getId(), oauthToken));
    }
    String clientSecret = (String) attrs.get(A_zimbraDataSourceOAuthClientSecret);
    if (clientSecret != null) {
        attrs.put(A_zimbraDataSourceOAuthClientSecret, DataSource.encryptData(ds.getId(), clientSecret));
    }
    String smtpPassword = (String) attrs.get(A_zimbraDataSourceSmtpAuthPassword);
    if (smtpPassword != null) {
        attrs.put(A_zimbraDataSourceSmtpAuthPassword, DataSource.encryptData(ds.getId(), smtpPassword));
    }
    modifyAttrs(ds, attrs, true);
    if (newName) {
        // the datasoruce cache could've been loaded again if getAllDataSources were called in pre/poseModify callback, so we clear it again
        account.setCachedData(DATA_SOURCE_LIST_CACHE_KEY, null);
        ZLdapContext zlc = null;
        try {
            zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_DATASOURCE);
            String newDn = getDataSourceDn(ldapEntry, name);
            zlc.renameEntry(ds.getDN(), newDn);
        } catch (ServiceException e) {
            throw ServiceException.FAILURE("unable to rename datasource: " + name, e);
        } finally {
            LdapClient.closeContext(zlc);
        }
    }
}
Also used : LdapDataSource(com.zimbra.cs.account.ldap.entry.LdapDataSource) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)2 LdapDataSource (com.zimbra.cs.account.ldap.entry.LdapDataSource)2 Account (com.zimbra.cs.account.Account)1 DataSource (com.zimbra.cs.account.DataSource)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)1 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)1 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)1 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)1 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)1 ArrayList (java.util.ArrayList)1