use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestLdapProvSignature method createSignatureWithExistingId.
@Test
public void createSignatureWithExistingId() 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);
String id = signature.getAttr("zimbraSignatureId");
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("zimbraSignatureId", id);
try {
prov.createSignature(acct, SIGNATURE_NAME + "_NEW", attrs);
fail("Create signature should not have succeeded, as signatureId exists.");
} catch (AccountServiceException e) {
assertEquals(AccountServiceException.SIGNATURE_EXISTS, e.getCode());
}
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestLdapProvSignature method getSignature.
@Test
public void getSignature() 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);
String signatureId = signature.getId();
acct = getFresh(acct);
signature = prov.get(acct, Key.SignatureBy.id, signatureId);
assertNotNull(signature);
acct = getFresh(acct);
signature = prov.get(acct, Key.SignatureBy.name, SIGNATURE_NAME);
assertNotNull(signature);
deleteSignature(acct, signature);
deleteAccount(acct);
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestLdapProvSignature method renameSignature.
@Test
public void renameSignature() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
String SIGNATURE_NAME_ON_ACCOUNT_ENTRY = Names.makeSignatureName(genSignatureName("sig-on-account-entry"));
String SIGNATURE_NAME = Names.makeSignatureName(genSignatureName());
Account acct = createAccount(ACCT_NAME_LOCALPART);
Signature signatureOnAccountEntry = createSignature(acct, SIGNATURE_NAME_ON_ACCOUNT_ENTRY);
Signature signature = createSignature(acct, SIGNATURE_NAME);
/*
* rename the signature on account entry
*/
Map<String, Object> attrs = new HashMap<String, Object>();
// modifying zimbraSignatureName will rename the signature and trigger a LDAP moddn
String MODIFIED_ATTR_NAME = Provisioning.A_zimbraSignatureName;
String NEW_SIGNATURE_NAME = Names.makeSignatureName(genSignatureName("sig-on-account-entry-new"));
String MODIFIED_ATTR_VALUE = NEW_SIGNATURE_NAME;
attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
prov.modifySignature(acct, signatureOnAccountEntry.getId(), attrs);
acct = getFresh(acct);
signatureOnAccountEntry = prov.get(acct, Key.SignatureBy.name, NEW_SIGNATURE_NAME);
assertEquals(MODIFIED_ATTR_VALUE, signatureOnAccountEntry.getAttr(MODIFIED_ATTR_NAME));
/*
* rename the signature on signature entry
*/
attrs = new HashMap<String, Object>();
// modifying zimbraSignatureName will rename the signature and trigger a LDAP moddn
MODIFIED_ATTR_NAME = Provisioning.A_zimbraSignatureName;
NEW_SIGNATURE_NAME = Names.makeSignatureName(genSignatureName("new"));
MODIFIED_ATTR_VALUE = NEW_SIGNATURE_NAME;
attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
prov.modifySignature(acct, signature.getId(), attrs);
acct = getFresh(acct);
signature = prov.get(acct, Key.SignatureBy.name, NEW_SIGNATURE_NAME);
assertEquals(MODIFIED_ATTR_VALUE, signature.getAttr(MODIFIED_ATTR_NAME));
deleteSignature(acct, signatureOnAccountEntry);
deleteSignature(acct, signature);
deleteAccount(acct);
}
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);
}
}
}
Aggregations