Search in sources :

Example 1 with Identity

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

the class LdapProvisioning method deleteIdentity.

@Override
public void deleteIdentity(Account account, String identityName) throws ServiceException {
    LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
    if (ldapEntry == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
    if (identityName.equalsIgnoreCase(ProvisioningConstants.DEFAULT_IDENTITY_NAME))
        throw ServiceException.INVALID_REQUEST("can't delete default identity", null);
    account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_IDENTITY);
        Identity identity = getIdentityByName(ldapEntry, identityName, zlc);
        if (identity == null)
            throw AccountServiceException.NO_SUCH_IDENTITY(identityName);
        String dn = getIdentityDn(ldapEntry, identityName);
        zlc.deleteEntry(dn);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to delete identity: " + identityName, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
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) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) Identity(com.zimbra.cs.account.Identity)

Example 2 with Identity

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

the class LdapProvisioning method getIdentitiesByQuery.

private List<Identity> getIdentitiesByQuery(LdapEntry entry, ZLdapFilter filter, ZLdapContext initZlc) throws ServiceException {
    List<Identity> result = new ArrayList<Identity>();
    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 LdapIdentity((Account) entry, sr.getDN(), sr.getAttributes(), this));
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup identity via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return result;
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) Identity(com.zimbra.cs.account.Identity) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity)

Example 3 with Identity

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

the class ACLUtil method getSendOnBehalfOf.

/**
 * Returns {@link UserRights#R_sendOnBehalfOf} rights granted to the grantee.
 */
public static List<Identity> getSendOnBehalfOf(Account grantee) throws ServiceException {
    Multimap<Right, Entry> rights = getGrantedRights(grantee, Collections.singleton(Provisioning.A_displayName));
    ImmutableList.Builder<Identity> result = ImmutableList.<Identity>builder();
    for (Entry entry : rights.get(UserRights.R_sendOnBehalfOf)) {
        Account grantor = (Account) entry;
        String mail = grantor.getName();
        String name = MoreObjects.firstNonNull(grantor.getDisplayName(), mail);
        Map<String, Object> attrs = ImmutableMap.<String, Object>builder().put(Provisioning.A_zimbraPrefIdentityId, grantor.getId()).put(Provisioning.A_zimbraPrefIdentityName, name).put(Provisioning.A_zimbraPrefFromDisplay, name).put(Provisioning.A_zimbraPrefFromAddress, mail).put(Provisioning.A_objectClass, AttributeClass.OC_zimbraAclTarget).build();
        result.add(new Identity(grantee, name, grantor.getId(), attrs, grantee.getProvisioning()));
    }
    return result.build();
}
Also used : Account(com.zimbra.cs.account.Account) Entry(com.zimbra.cs.account.Entry) ImmutableList(com.google.common.collect.ImmutableList) Identity(com.zimbra.cs.account.Identity)

Example 4 with Identity

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

the class LdapProvisioning method getAllIdentities.

@Override
public List<Identity> getAllIdentities(Account account) throws ServiceException {
    LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
    if (ldapEntry == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
    @SuppressWarnings("unchecked") List<Identity> result = (List<Identity>) account.getCachedData(IDENTITY_LIST_CACHE_KEY);
    if (result != null) {
        return result;
    }
    result = getIdentitiesByQuery(ldapEntry, filterFactory.allIdentities(), null);
    for (Identity identity : result) {
        // gross hack for 4.5beta. should be able to remove post 4.5
        if (identity.getId() == null) {
            String id = LdapUtil.generateUUID();
            identity.setId(id);
            Map<String, Object> newAttrs = new HashMap<String, Object>();
            newAttrs.put(Provisioning.A_zimbraPrefIdentityId, id);
            try {
                modifyIdentity(account, identity.getName(), newAttrs);
            } catch (ServiceException se) {
                ZimbraLog.account.warn("error updating identity: " + account.getName() + " " + identity.getName() + " " + se.getMessage(), se);
            }
        }
    }
    result.add(getDefaultIdentity(account));
    result = Collections.unmodifiableList(result);
    account.setCachedData(IDENTITY_LIST_CACHE_KEY, result);
    return result;
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) ArrayList(java.util.ArrayList) List(java.util.List) AddressList(com.zimbra.cs.account.AddressList) DistributionList(com.zimbra.cs.account.DistributionList) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) Identity(com.zimbra.cs.account.Identity)

Example 5 with Identity

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

the class PlainTextSignature method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
    SingleValueMod mod = singleValueMod(attrName, value);
    if (mod.unsetting())
        return;
    Account account;
    if (entry instanceof Account) {
        account = (Account) entry;
    } else if (entry instanceof Identity) {
        account = ((Identity) entry).getAccount();
    } else if (entry instanceof DataSource) {
        account = ((DataSource) entry).getAccount();
    } else {
        return;
    }
    Signature sig = Provisioning.getInstance().get(account, Key.SignatureBy.id, mod.value());
    if (sig == null) {
        throw ServiceException.INVALID_REQUEST("No such signature " + mod.value() + " for account " + account.getName(), null);
    }
    String sigAttr = SignatureUtil.mimeTypeToAttrName(MimeConstants.CT_TEXT_PLAIN);
    String plainSig = sig.getAttr(sigAttr, null);
    if (StringUtil.isNullOrEmpty(plainSig)) {
        throw ServiceException.INVALID_REQUEST("Signature " + mod.value() + " must have plain text content", null);
    }
}
Also used : Account(com.zimbra.cs.account.Account) Signature(com.zimbra.cs.account.Signature) Identity(com.zimbra.cs.account.Identity) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

Identity (com.zimbra.cs.account.Identity)29 Account (com.zimbra.cs.account.Account)17 Test (org.junit.Test)7 ServiceException (com.zimbra.common.service.ServiceException)5 AccountServiceException (com.zimbra.cs.account.AccountServiceException)5 ArrayList (java.util.ArrayList)5 Element (com.zimbra.common.soap.Element)4 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)4 LdapIdentity (com.zimbra.cs.account.ldap.entry.LdapIdentity)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 HashMap (java.util.HashMap)4 Provisioning (com.zimbra.cs.account.Provisioning)3 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)3 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)2 Signature (com.zimbra.cs.account.Signature)2 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 Date (java.util.Date)2 Locale (java.util.Locale)2 Address (javax.mail.Address)2 InternetAddress (javax.mail.internet.InternetAddress)2