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;
}
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);
}
}
}
Aggregations