Search in sources :

Example 16 with Signature

use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.

the class TestLdapProvSignature method getAllSignatures.

@Test
public void getAllSignatures() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String SIGNATURE_NAME_1 = Names.makeSignatureName(genSignatureName("1"));
    String SIGNATURE_NAME_2 = Names.makeSignatureName(genSignatureName("2"));
    String SIGNATURE_NAME_3 = Names.makeSignatureName(genSignatureName("3"));
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    Signature signature1 = createSignature(acct, SIGNATURE_NAME_1);
    Signature signature2 = createSignature(acct, SIGNATURE_NAME_2);
    Signature signature3 = createSignature(acct, SIGNATURE_NAME_3);
    acct = getFresh(acct);
    List<Signature> allSignatures = prov.getAllSignatures(acct);
    assertEquals(3, allSignatures.size());
    Set<String> allSignatureIds = new HashSet<String>();
    for (Signature signature : allSignatures) {
        allSignatureIds.add(signature.getId());
    }
    assertTrue(allSignatureIds.contains(signature1.getId()));
    assertTrue(allSignatureIds.contains(signature2.getId()));
    assertTrue(allSignatureIds.contains(signature3.getId()));
    deleteSignature(acct, signature1);
    deleteSignature(acct, signature2);
    deleteSignature(acct, signature3);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) Signature(com.zimbra.cs.account.Signature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with Signature

use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.

the class CreateSignature method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    Element eReqSignature = request.getElement(AccountConstants.E_SIGNATURE);
    String name = eReqSignature.getAttribute(AccountConstants.A_NAME);
    String id = eReqSignature.getAttribute(AccountConstants.A_ID, null);
    List<Element> contents = eReqSignature.listElements(AccountConstants.E_CONTENT);
    Map<String, Object> attrs = new HashMap<String, Object>();
    for (Element eContent : contents) {
        String type = eContent.getAttribute(AccountConstants.A_TYPE);
        String attr = SignatureUtil.mimeTypeToAttrName(type);
        if (attr == null)
            throw ServiceException.INVALID_REQUEST("invalid type " + type, null);
        if (attrs.get(attr) != null)
            throw ServiceException.INVALID_REQUEST("only one " + type + " content is allowed", null);
        String content = eContent.getText();
        if (!StringUtil.isNullOrEmpty(content))
            attrs.put(attr, content);
    }
    if (id != null)
        attrs.put(Provisioning.A_zimbraSignatureId, id);
    Element eContactId = eReqSignature.getOptionalElement(AccountConstants.E_CONTACT_ID);
    if (eContactId != null)
        attrs.put(Provisioning.A_zimbraPrefMailSignatureContactId, eContactId.getText());
    Signature signature = Provisioning.getInstance().createSignature(account, name, attrs);
    Element response = zsc.createElement(AccountConstants.CREATE_SIGNATURE_RESPONSE);
    Element eRespSignature = response.addElement(AccountConstants.E_SIGNATURE);
    eRespSignature.addAttribute(AccountConstants.A_ID, signature.getId());
    eRespSignature.addAttribute(AccountConstants.A_NAME, signature.getName());
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Signature(com.zimbra.cs.account.Signature)

Example 18 with Signature

use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.

the class DeleteSignature method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    Provisioning prov = Provisioning.getInstance();
    Element eSignature = request.getElement(AccountConstants.E_SIGNATURE);
    // signature can be specified by name or by ID
    Signature signature = null;
    String sigStr = eSignature.getAttribute(AccountConstants.A_ID, null);
    if (sigStr != null) {
        signature = prov.get(account, Key.SignatureBy.id, sigStr);
    } else {
        sigStr = eSignature.getAttribute(AccountConstants.A_NAME);
        signature = prov.get(account, Key.SignatureBy.name, sigStr);
    }
    if (signature != null)
        Provisioning.getInstance().deleteSignature(account, signature.getId());
    else
        throw AccountServiceException.NO_SUCH_SIGNATURE(sigStr);
    Element response = zsc.createElement(AccountConstants.DELETE_SIGNATURE_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Signature(com.zimbra.cs.account.Signature) Provisioning(com.zimbra.cs.account.Provisioning)

Example 19 with Signature

use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.

the class TestAccess method ModifySignature.

public void ModifySignature(Role role, Perm perm) throws Exception {
    String signatureName = "signature-modify-" + random();
    Signature signature = mProvAdmin.createSignature(mProvAdmin.get(Key.AccountBy.id, ACCT_1_ID), signatureName, new HashMap<String, Object>());
    XMLElement req = new XMLElement(AccountConstants.MODIFY_SIGNATURE_REQUEST);
    Element identity = req.addElement(AccountConstants.E_SIGNATURE);
    identity.addAttribute(AccountConstants.A_ID, signature.getId());
    accessTest(role, perm, req);
}
Also used : Signature(com.zimbra.cs.account.Signature) XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 20 with Signature

use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.

the class TestAccess method DeleteSignature.

public void DeleteSignature(Role role, Perm perm) throws Exception {
    String signatureName = "signature-delete-" + random();
    Signature signature = mProvAdmin.createSignature(mProvAdmin.get(Key.AccountBy.id, ACCT_1_ID), signatureName, new HashMap<String, Object>());
    XMLElement req = new XMLElement(AccountConstants.DELETE_SIGNATURE_REQUEST);
    Element identity = req.addElement(AccountConstants.E_SIGNATURE);
    identity.addAttribute(AccountConstants.A_ID, signature.getId());
    accessTest(role, perm, req);
}
Also used : Signature(com.zimbra.cs.account.Signature) XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

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