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());
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations