use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteSignature.
@Override
public void deleteSignature(Account account, String signatureId) throws ServiceException {
LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
if (ldapEntry == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
account.setCachedData(SIGNATURE_LIST_CACHE_KEY, null);
if (LdapSignature.isAccountSignature(account, signatureId)) {
LdapSignature.deleteAccountSignature(this, account);
} else {
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_SIGNATURE);
Signature signature = getSignatureById(account, ldapEntry, signatureId, zlc);
if (signature == null)
throw AccountServiceException.NO_SUCH_SIGNATURE(signatureId);
String dn = getSignatureDn(ldapEntry, signature.getName());
zlc.deleteEntry(dn);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to delete signarure: " + signatureId, e);
} finally {
LdapClient.closeContext(zlc);
}
}
if (signatureId.equals(account.getPrefDefaultSignatureId())) {
account.unsetPrefDefaultSignatureId();
}
}
use of com.zimbra.cs.account.Signature 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.Signature in project zm-mailbox by Zimbra.
the class TestLdapProvSignature method createSignature.
@Test
public void createSignature() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
String SIGNATURE_NAME = Names.makeSignatureName(genSignatureName());
Account acct = createAccount(ACCT_NAME_LOCALPART);
Signature signature = createSignature(acct, SIGNATURE_NAME);
assertEquals(acct.getId(), signature.getAccount().getId());
deleteSignature(acct, signature);
deleteAccount(acct);
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestLdapProvSignature method modifySignature.
@Test
public void modifySignature() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
String SIGNATURE_NAME = Names.makeSignatureName(genSignatureName());
Account acct = createAccount(ACCT_NAME_LOCALPART);
Signature signature = createSignature(acct, SIGNATURE_NAME);
Map<String, Object> attrs = new HashMap<String, Object>();
String MODIFIED_ATTR_NAME = Provisioning.A_zimbraPrefMailSignature;
String MODIFIED_ATTR_VALUE = "modifySignature";
attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
prov.modifySignature(acct, signature.getId(), attrs);
acct = getFresh(acct);
signature = prov.get(acct, Key.SignatureBy.name, SIGNATURE_NAME);
assertEquals(MODIFIED_ATTR_VALUE, signature.getAttr(MODIFIED_ATTR_NAME));
deleteSignature(acct, signature);
deleteAccount(acct);
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestLdapProvSignature method createSignatureAlreadyExists.
@Test
public void createSignatureAlreadyExists() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
String SIGNATURE_NAME = Names.makeSignatureName(genSignatureName());
Account acct = createAccount(ACCT_NAME_LOCALPART);
Signature signature = createSignature(acct, SIGNATURE_NAME);
boolean caughtException = false;
try {
createSignatureRaw(acct, SIGNATURE_NAME);
} catch (AccountServiceException e) {
if (AccountServiceException.SIGNATURE_EXISTS.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
deleteSignature(acct, signature);
deleteAccount(acct);
}
Aggregations