use of com.zimbra.cs.account.ldap.entry.LdapIdentity in project zm-mailbox by Zimbra.
the class LdapProvisioning method getIdentitiesByQuery.
private List<Identity> getIdentitiesByQuery(LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
List<Identity> result = new ArrayList<Identity>();
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 LdapIdentity((Account) entry, sr.getDN(), sr.getAttributes(), this));
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup identity via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
}
return result;
}
use of com.zimbra.cs.account.ldap.entry.LdapIdentity in project zm-mailbox by Zimbra.
the class LdapProvisioning method modifyIdentity.
@Override
public void modifyIdentity(Account account, String identityName, Map<String, Object> identityAttrs) throws ServiceException {
removeAttrIgnoreCase("objectclass", identityAttrs);
validateIdentityAttrs(identityAttrs);
LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
if (ldapEntry == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
// clear cache
account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
if (identityName.equalsIgnoreCase(ProvisioningConstants.DEFAULT_IDENTITY_NAME)) {
modifyAttrs(account, identityAttrs);
} else {
LdapIdentity identity = (LdapIdentity) getIdentityByName(ldapEntry, identityName, null);
if (identity == null)
throw AccountServiceException.NO_SUCH_IDENTITY(identityName);
String name = (String) identityAttrs.get(A_zimbraPrefIdentityName);
boolean newName = (name != null && !name.equals(identityName));
if (newName)
identityAttrs.remove(A_zimbraPrefIdentityName);
modifyAttrs(identity, identityAttrs, true);
if (newName) {
// the identity cache could've been loaded again if getAllIdentities were called in pre/poseModify callback, so we clear it again
account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
renameIdentity(ldapEntry, identity, name);
}
}
}
Aggregations