use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ParseMimeMessageTest method attachZimbraDocument.
@Test
public void attachZimbraDocument() throws Exception {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
OperationContext octxt = new OperationContext(acct);
Document doc = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc", MimeConstants.CT_APPLICATION_ZIMBRA_DOC, "author", "description", new ByteArrayInputStream("test123".getBytes()));
Element el = new Element.JSONElement(MailConstants.E_MSG);
el.addAttribute(MailConstants.E_SUBJECT, "attach message");
el.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, "rcpt@zimbra.com");
el.addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, "This is the content.");
el.addElement(MailConstants.E_ATTACH).addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc.getId());
ZimbraSoapContext zsc = getMockSoapContext();
MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
MimeMultipart mmp = (MimeMultipart) mm.getContent();
MimeBodyPart part = (MimeBodyPart) mmp.getBodyPart(1);
Assert.assertEquals(MimeConstants.CT_TEXT_HTML, new ContentType(part.getContentType()).getContentType());
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class AutoCompleteGal method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(getZimbraSoapContext(context));
if (!canAccessAccount(zsc, account))
throw ServiceException.PERM_DENIED("can not access account");
String name = request.getAttribute(AccountConstants.E_NAME);
String typeStr = request.getAttribute(AccountConstants.A_TYPE, "account");
GalSearchType type = GalSearchType.fromString(typeStr);
boolean needCanExpand = request.getAttributeBool(AccountConstants.A_NEED_EXP, false);
String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
GalSearchParams params = new GalSearchParams(account, zsc);
params.setType(type);
params.setRequest(request);
params.setQuery(name);
params.setLimit(account.getContactAutoCompleteMaxResults());
params.setNeedCanExpand(needCanExpand);
params.setResponseName(AccountConstants.AUTO_COMPLETE_GAL_RESPONSE);
if (galAcctId != null) {
Account galAccount = Provisioning.getInstance().getAccountById(galAcctId);
if (galAccount != null && (!account.getDomainId().equals(galAccount.getDomainId()))) {
throw ServiceException.PERM_DENIED("can not access galsync account of different domain");
}
params.setGalSyncAccount(galAccount);
}
GalSearchControl gal = new GalSearchControl(params);
gal.autocomplete();
return params.getResultCallback().getResponse();
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class ChangePassword method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
if (!checkPasswordSecurity(context))
throw ServiceException.INVALID_REQUEST("clear text password is not allowed", null);
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
String namePassedIn = request.getAttribute(AccountConstants.E_ACCOUNT);
String name = namePassedIn;
Element virtualHostEl = request.getOptionalElement(AccountConstants.E_VIRTUAL_HOST);
String virtualHost = virtualHostEl == null ? null : virtualHostEl.getText().toLowerCase();
if (virtualHost != null && name.indexOf('@') == -1) {
Domain d = prov.get(Key.DomainBy.virtualHostname, virtualHost);
if (d != null)
name = name + "@" + d.getName();
}
Account acct = prov.get(AccountBy.name, name, zsc.getAuthToken());
if (acct == null)
throw AuthFailedServiceException.AUTH_FAILED(name, namePassedIn, "account not found");
// an auth token. Proxy here if this is not the home server of the account.
if (!Provisioning.onLocalServer(acct)) {
try {
return proxyRequest(request, context, acct.getId());
} catch (ServiceException e) {
// if something went wrong proxying the request, just execute it locally
if (ServiceException.PROXY_ERROR.equals(e.getCode())) {
ZimbraLog.account.warn("encountered proxy error", e);
} else {
// but if it's a real error, it's a real error
throw e;
}
}
}
String oldPassword = request.getAttribute(AccountConstants.E_OLD_PASSWORD);
String newPassword = request.getAttribute(AccountConstants.E_PASSWORD);
if (acct.isIsExternalVirtualAccount() && StringUtil.isNullOrEmpty(oldPassword) && !acct.isVirtualAccountInitialPasswordSet() && acct.getId().equals(zsc.getAuthtokenAccountId())) {
// need a valid auth token in this case
AuthProvider.validateAuthToken(prov, zsc.getAuthToken(), false);
prov.setPassword(acct, newPassword, true);
acct.setVirtualAccountInitialPasswordSet(true);
} else {
prov.changePassword(acct, oldPassword, newPassword);
}
AuthToken at = AuthProvider.getAuthToken(acct);
Element response = zsc.createElement(AccountConstants.CHANGE_PASSWORD_RESPONSE);
at.encodeAuthResp(response, false);
response.addAttribute(AccountConstants.E_LIFETIME, at.getExpires() - System.currentTimeMillis(), Element.Disposition.CONTENT);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class DeleteIdentity 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 eIdentity = request.getElement(AccountConstants.E_IDENTITY);
// identity can be specified by name or by ID
Identity ident = null;
String idStr = eIdentity.getAttribute(AccountConstants.A_ID, null);
if (idStr != null) {
ident = prov.get(account, Key.IdentityBy.id, idStr);
} else {
idStr = eIdentity.getAttribute(AccountConstants.A_NAME);
ident = prov.get(account, Key.IdentityBy.name, idStr);
}
if (ident != null)
Provisioning.getInstance().deleteIdentity(account, ident.getName());
else
throw AccountServiceException.NO_SUCH_IDENTITY(idStr);
Element response = zsc.createElement(AccountConstants.DELETE_IDENTITY_RESPONSE);
return response;
}
use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.
the class DiscoverRights method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canAccessAccount(zsc, account)) {
throw ServiceException.PERM_DENIED("can not access account");
}
RightManager rightMgr = RightManager.getInstance();
Set<Right> rights = Sets.newHashSet();
for (Element eRight : request.listElements(AccountConstants.E_RIGHT)) {
UserRight r = rightMgr.getUserRight(eRight.getText());
rights.add(r);
}
if (rights.size() == 0) {
throw ServiceException.INVALID_REQUEST("no right is specified", null);
}
Element response = zsc.createElement(AccountConstants.DISCOVER_RIGHTS_RESPONSE);
discoverRights(account, rights, response, true);
return response;
}
Aggregations