Search in sources :

Example 16 with Identity

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

the class TestJaxbProvisioning method testIdentities.

@Test
public void testIdentities() throws Exception {
    ZimbraLog.test.debug("Starting testIdentities");
    Account acct = ensureAccountExists(testAcctEmail);
    List<Identity> identities = prov.getAllIdentities(acct);
    assertEquals("Number of identities for new acct", 1, identities.size());
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put("zimbraPrefFromAddress", testAcctIdentity);
    Identity newId = prov.createIdentity(acct, "altIdentity", attrs);
    assertNotNull("New identity", newId);
    identities = prov.getAllIdentities(acct);
    assertEquals("Number of identities after add", 2, identities.size());
    prov.deleteIdentity(acct, "altIdentity");
    identities = prov.getAllIdentities(acct);
    assertEquals("Number of identities after delete", 1, identities.size());
}
Also used : Account(com.zimbra.cs.account.Account) Identity(com.zimbra.cs.account.Identity) Test(org.junit.Test)

Example 17 with Identity

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

the class LdapProvisioning method createIdentity.

private Identity createIdentity(Account account, String identityName, Map<String, Object> identityAttrs, boolean restoring) throws ServiceException {
    removeAttrIgnoreCase("objectclass", identityAttrs);
    validateIdentityAttrs(identityAttrs);
    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 AccountServiceException.IDENTITY_EXISTS(identityName);
    List<Identity> existing = getAllIdentities(account);
    if (existing.size() >= account.getLongAttr(A_zimbraIdentityMaxNumEntries, 20))
        throw AccountServiceException.TOO_MANY_IDENTITIES();
    account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
    boolean checkImmutable = !restoring;
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(identityAttrs, null, callbackContext, checkImmutable);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_IDENTITY);
        String dn = getIdentityDn(ldapEntry, identityName);
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.setDN(dn);
        entry.mapToAttrs(identityAttrs);
        entry.setAttr(A_objectClass, "zimbraIdentity");
        if (!entry.hasAttribute(A_zimbraPrefIdentityId)) {
            String identityId = LdapUtil.generateUUID();
            entry.setAttr(A_zimbraPrefIdentityId, identityId);
        }
        entry.setAttr(Provisioning.A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        zlc.createEntry(entry);
        Identity identity = getIdentityByName(ldapEntry, identityName, zlc);
        AttributeManager.getInstance().postModify(identityAttrs, identity, callbackContext);
        return identity;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.IDENTITY_EXISTS(identityName);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create identity " + identityName, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) Date(java.util.Date) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) Identity(com.zimbra.cs.account.Identity) LdapException(com.zimbra.cs.ldap.LdapException)

Example 18 with Identity

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

the class CreateIdentity method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account)) {
        throw ServiceException.PERM_DENIED("can not modify options");
    }
    Element identityEl = request.getElement(AccountConstants.E_IDENTITY);
    String name = identityEl.getAttribute(AccountConstants.A_NAME);
    Map<String, Object> attrs = AccountService.getAttrs(identityEl, true, AccountConstants.A_NAME);
    Identity identity = Provisioning.getInstance().createIdentity(account, name, attrs);
    Element response = zsc.createElement(AccountConstants.CREATE_IDENTITY_RESPONSE);
    ToXML.encodeIdentity(response, identity);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Identity(com.zimbra.cs.account.Identity)

Example 19 with Identity

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

the class SoapProvisioning method getAllIdentities.

@Override
public List<Identity> getAllIdentities(Account account) throws ServiceException {
    List<Identity> result = new ArrayList<Identity>();
    GetIdentitiesResponse response = invokeJaxbOnTargetAccount(new GetIdentitiesRequest(), account.getId());
    for (com.zimbra.soap.account.type.Identity identity : response.getIdentities()) {
        result.add(new SoapIdentity(account, identity, this));
    }
    return result;
}
Also used : GetIdentitiesRequest(com.zimbra.soap.account.message.GetIdentitiesRequest) GetIdentitiesResponse(com.zimbra.soap.account.message.GetIdentitiesResponse) ArrayList(java.util.ArrayList) Identity(com.zimbra.cs.account.Identity)

Example 20 with Identity

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

the class CalendarMailSender method createCalendarInviteDeniedMessage.

private static MimeMessage createCalendarInviteDeniedMessage(Account fromAccount, Account senderAccount, boolean onBehalfOf, boolean allowPrivateAccess, Address toAddr, Invite inv, MsgKey bodyTextKey) throws ServiceException {
    Locale locale = !onBehalfOf ? fromAccount.getLocale() : senderAccount.getLocale();
    Identity fromIdentity = getTargetedIdentity(fromAccount, inv);
    StringBuilder replyText = new StringBuilder();
    String sigText = getSignatureText(fromAccount, fromIdentity, Provisioning.A_zimbraPrefCalendarAutoDenySignatureId);
    if (sigText == null || sigText.length() < 1)
        sigText = L10nUtil.getMessage(bodyTextKey, locale);
    if (sigText != null && sigText.length() > 0)
        replyText.append(sigText).append("\r\n");
    attachInviteSummary(replyText, inv, null, locale);
    String subject = L10nUtil.getMessage(MsgKey.calendarReplySubjectDecline, locale) + ": " + inv.getName();
    String uid = inv.getUid();
    ParsedDateTime exceptDt = null;
    if (inv.hasRecurId())
        exceptDt = inv.getRecurId().getDt();
    Invite replyInv = replyToInvite(fromAccount, senderAccount, onBehalfOf, allowPrivateAccess, inv, VERB_DECLINE, subject, exceptDt);
    ZVCalendar iCal = replyInv.newToICalendar(true);
    Address fromAddr = fromIdentity.getFriendlyEmailAddress();
    Address senderAddr = null;
    if (onBehalfOf)
        senderAddr = AccountUtil.getFriendlyEmailAddress(senderAccount);
    List<Address> toAddrs = new ArrayList<Address>(1);
    toAddrs.add(toAddr);
    return createCalendarMessage(senderAccount, fromAddr, senderAddr, toAddrs, subject, replyText.toString(), null, uid, iCal);
}
Also used : Locale(java.util.Locale) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ArrayList(java.util.ArrayList) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) Identity(com.zimbra.cs.account.Identity)

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