Search in sources :

Example 11 with Signature

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();
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) Signature(com.zimbra.cs.account.Signature) LdapSignature(com.zimbra.cs.account.ldap.entry.LdapSignature) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry)

Example 12 with Signature

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);
        }
    }
}
Also used : LdapSignature(com.zimbra.cs.account.ldap.entry.LdapSignature) Signature(com.zimbra.cs.account.Signature) LdapSignature(com.zimbra.cs.account.ldap.entry.LdapSignature) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry)

Example 13 with Signature

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);
}
Also used : Account(com.zimbra.cs.account.Account) Signature(com.zimbra.cs.account.Signature) Test(org.junit.Test)

Example 14 with Signature

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);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Signature(com.zimbra.cs.account.Signature) Test(org.junit.Test)

Example 15 with Signature

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);
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) Signature(com.zimbra.cs.account.Signature) Test(org.junit.Test)

Aggregations

Signature (com.zimbra.cs.account.Signature)25 Account (com.zimbra.cs.account.Account)14 Element (com.zimbra.common.soap.Element)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 AccountServiceException (com.zimbra.cs.account.AccountServiceException)5 LdapSignature (com.zimbra.cs.account.ldap.entry.LdapSignature)5 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 ServiceException (com.zimbra.common.service.ServiceException)3 XMLElement (com.zimbra.common.soap.Element.XMLElement)3 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)3 Identity (com.zimbra.cs.account.Identity)2 Provisioning (com.zimbra.cs.account.Provisioning)2 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 ArrayList (java.util.ArrayList)2 DataSource (com.zimbra.cs.account.DataSource)1 DistributionList (com.zimbra.cs.account.DistributionList)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)1