use of com.zimbra.cs.account.ldap.entry.LdapSignature in project zm-mailbox by Zimbra.
the class LdapProvisioning method modifySignature.
@Override
public void modifySignature(Account account, String signatureId, Map<String, Object> signatureAttrs) throws ServiceException {
removeAttrIgnoreCase("objectclass", signatureAttrs);
validateSignatureAttrs(signatureAttrs);
LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
if (ldapEntry == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
String newName = (String) signatureAttrs.get(A_zimbraSignatureName);
if (newName != null) {
newName = newName.trim();
// do not allow name to be wiped
if (newName.length() == 0)
throw ServiceException.INVALID_REQUEST("empty signature name is not allowed", null);
// check for duplicate names
List<Signature> sigs = getAllSignatures(account);
for (Signature sig : sigs) {
if (sig.getName().equalsIgnoreCase(newName) && !sig.getId().equals(signatureId))
throw AccountServiceException.SIGNATURE_EXISTS(newName);
}
}
// clear cache
account.setCachedData(SIGNATURE_LIST_CACHE_KEY, null);
if (LdapSignature.isAccountSignature(account, signatureId)) {
LdapSignature.modifyAccountSignature(this, account, signatureAttrs);
} else {
LdapSignature signature = (LdapSignature) getSignatureById(account, ldapEntry, signatureId, null);
if (signature == null)
throw AccountServiceException.NO_SUCH_SIGNATURE(signatureId);
boolean nameChanged = (newName != null && !newName.equals(signature.getName()));
if (nameChanged)
signatureAttrs.remove(A_zimbraSignatureName);
modifyAttrs(signature, signatureAttrs, true);
if (nameChanged) {
// the signature cache could've been loaded again if getAllSignatures
// were called in pre/poseModify callback, so we clear it again
account.setCachedData(SIGNATURE_LIST_CACHE_KEY, null);
renameSignature(ldapEntry, signature, newName);
}
}
}
use of com.zimbra.cs.account.ldap.entry.LdapSignature in project zm-mailbox by Zimbra.
the class LdapProvisioning method getSignaturesByQuery.
private List<Signature> getSignaturesByQuery(Account acct, LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc, List<Signature> result) throws ServiceException {
if (result == null) {
result = new ArrayList<Signature>();
}
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 LdapSignature(acct, sr.getDN(), sr.getAttributes(), this));
}
ne.close();
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup signature via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
}
return result;
}
Aggregations