Search in sources :

Example 1 with LdapSignature

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);
        }
    }
}
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 2 with LdapSignature

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

Aggregations

Signature (com.zimbra.cs.account.Signature)2 LdapSignature (com.zimbra.cs.account.ldap.entry.LdapSignature)2 ServiceException (com.zimbra.common.service.ServiceException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)1 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)1 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)1