Search in sources :

Example 11 with ZimbraSoapContext

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());
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ContentType(com.zimbra.common.mime.ContentType) Element(com.zimbra.common.soap.Element) Document(com.zimbra.cs.mailbox.Document) Mailbox(com.zimbra.cs.mailbox.Mailbox) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) MimeBodyPart(javax.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 12 with ZimbraSoapContext

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();
}
Also used : Account(com.zimbra.cs.account.Account) GalSearchControl(com.zimbra.cs.gal.GalSearchControl) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 13 with ZimbraSoapContext

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;
}
Also used : Account(com.zimbra.cs.account.Account) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) AuthToken(com.zimbra.cs.account.AuthToken) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning)

Example 14 with ZimbraSoapContext

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;
}
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) Provisioning(com.zimbra.cs.account.Provisioning)

Example 15 with ZimbraSoapContext

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;
}
Also used : Account(com.zimbra.cs.account.Account) UserRight(com.zimbra.cs.account.accesscontrol.UserRight) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) RightManager(com.zimbra.cs.account.accesscontrol.RightManager) Element(com.zimbra.common.soap.Element) UserRight(com.zimbra.cs.account.accesscontrol.UserRight) Right(com.zimbra.cs.account.accesscontrol.Right)

Aggregations

ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)410 Element (com.zimbra.common.soap.Element)322 Account (com.zimbra.cs.account.Account)175 Provisioning (com.zimbra.cs.account.Provisioning)164 Mailbox (com.zimbra.cs.mailbox.Mailbox)126 OperationContext (com.zimbra.cs.mailbox.OperationContext)95 ItemId (com.zimbra.cs.service.util.ItemId)60 Server (com.zimbra.cs.account.Server)48 ServiceException (com.zimbra.common.service.ServiceException)43 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)43 HashMap (java.util.HashMap)42 Domain (com.zimbra.cs.account.Domain)34 ArrayList (java.util.ArrayList)27 HashSet (java.util.HashSet)26 IOException (java.io.IOException)24 Test (org.junit.Test)20 Message (com.zimbra.cs.mailbox.Message)18 Group (com.zimbra.cs.account.Group)17 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)17 MimeMessage (javax.mail.internet.MimeMessage)16