Search in sources :

Example 86 with Provisioning

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

the class BrowseWrapper method browseByType.

private List<DavResource> browseByType(DavContext ctxt) throws IOException, ServiceException {
    ArrayList<DavResource> res = new ArrayList<DavResource>();
    String user = ctxt.getUser();
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    List<BrowseTerm> terms = mbox.browse(ctxt.getOperationContext(), Mailbox.BrowseBy.attachments, "", 0);
    for (BrowseTerm term : terms) {
        String ctype = term.getText();
        int index = ctype.indexOf('/');
        if (index != -1 || ctype.equals("message") || ctype.equals("none")) {
            continue;
        // the client still gets confused about having a slash in the
        // path even after encoding
        //ctype = ctype.substring(0,index) + "%2F" + ctype.substring(index+1);
        }
        res.add(new BrowseWrapper(generateUri(ctype), getOwner()));
    }
    res.add(new BrowseWrapper(generateUri("word"), getOwner()));
    res.add(new BrowseWrapper(generateUri("excel"), getOwner()));
    res.add(new BrowseWrapper(generateUri("ppt"), getOwner()));
    res.add(new BrowseWrapper(generateUri("pdf"), getOwner()));
    return res;
}
Also used : Account(com.zimbra.cs.account.Account) DomainBrowseTerm(com.zimbra.cs.index.DomainBrowseTerm) BrowseTerm(com.zimbra.cs.index.BrowseTerm) Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning)

Example 87 with Provisioning

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

the class CalendarCollection method handlePost.

@Override
public void handlePost(DavContext ctxt) throws DavException, IOException, ServiceException {
    Provisioning prov = Provisioning.getInstance();
    DavResource rs = null;
    try {
        String user = ctxt.getUser();
        Account account = prov.get(AccountBy.name, user);
        if (account == null) {
            // Anti-account name harvesting.
            ZimbraLog.dav.info("Failing POST to Calendar - no such account '%s'", user);
            throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
        }
        List<Invite> invites = uploadToInvites(ctxt, account);
        String uid = findEventUid(invites);
        rs = createItemFromInvites(ctxt, account, uid + ".ics", invites, false);
        if (rs.isNewlyCreated()) {
            ctxt.getResponse().setHeader("Location", rs.getHref());
            ctxt.setStatus(HttpServletResponse.SC_CREATED);
        } else {
            ctxt.setStatus(HttpServletResponse.SC_NO_CONTENT);
        }
        if (rs.hasEtag()) {
            ctxt.getResponse().setHeader(DavProtocol.HEADER_ETAG, rs.getEtag());
            ctxt.getResponse().setHeader(ETagHeaderFilter.ZIMBRA_ETAG_HEADER, rs.getEtag());
        }
    } catch (ServiceException e) {
        if (e.getCode().equals(ServiceException.FORBIDDEN)) {
            throw new DavException(e.getMessage(), HttpServletResponse.SC_FORBIDDEN, e);
        } else {
            throw new DavException("cannot create icalendar item", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) DavException(com.zimbra.cs.dav.DavException) Provisioning(com.zimbra.cs.account.Provisioning) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 88 with Provisioning

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

the class DavResource method getTextContent.

protected String getTextContent(DavContext ctxt) throws IOException {
    StringBuilder buf = new StringBuilder();
    buf.append("Request\n\n");
    buf.append("\tAuthenticated user:\t").append(ctxt.getAuthAccount().getName()).append("\n");
    buf.append("\tCurrent date:\t\t").append(new Date(System.currentTimeMillis())).append("\n");
    buf.append("\nResource\n\n");
    buf.append("\tName:\t\t\t").append(getName()).append("\n");
    buf.append("\tPath:\t\t\t").append(getUri()).append("\n");
    buf.append("\tDate:\t\t\t").append(getLastModifiedDate()).append("\n");
    try {
        Provisioning prov = Provisioning.getInstance();
        Account account = prov.get(Key.AccountBy.name, getOwner());
        buf.append("\tOwner account name:\t").append(account.getName()).append("\n");
    } catch (ServiceException se) {
    }
    buf.append("\nProperties\n\n");
    buf.append(getPropertiesAsText(ctxt));
    return buf.toString();
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Date(java.util.Date) Provisioning(com.zimbra.cs.account.Provisioning)

Example 89 with Provisioning

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

the class AclReports method getAclPrincipals.

private ArrayList<DavResource> getAclPrincipals(DavContext ctxt) throws DavException, ServiceException {
    ArrayList<DavResource> ret = new ArrayList<DavResource>();
    DavResource res = ctxt.getRequestedResource();
    if (!(res instanceof MailItemResource))
        return ret;
    List<Ace> aces = ((MailItemResource) res).getAce(ctxt);
    Provisioning prov = Provisioning.getInstance();
    for (Ace ace : aces) {
        if (ace.hasHref()) {
            Account acct = prov.get(Key.AccountBy.id, ace.getZimbraId());
            if (acct != null)
                ret.add(UrlNamespace.getPrincipal(ctxt, acct));
        }
    }
    return ret;
}
Also used : Account(com.zimbra.cs.account.Account) Ace(com.zimbra.cs.dav.property.Acl.Ace) DavResource(com.zimbra.cs.dav.resource.DavResource) MailItemResource(com.zimbra.cs.dav.resource.MailItemResource) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning)

Example 90 with Provisioning

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

the class SearchWrapper method getChildren.

@Override
public Collection<DavResource> getChildren(DavContext ctxt) {
    ArrayList<DavResource> children = new ArrayList<DavResource>();
    String user = ctxt.getUser();
    Provisioning prov = Provisioning.getInstance();
    ZimbraQueryResults zqr = null;
    try {
        Account account = prov.get(AccountBy.name, user);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        SearchParams params = new SearchParams();
        params.setQueryString(mQuery.toString());
        params.setTypes(SEARCH_TYPES);
        params.setSortBy(SortBy.NAME_ASC);
        params.setFetchMode(SearchParams.Fetch.NORMAL);
        params.setPrefetch(true);
        params.setChunkSize(SEARCH_LIMIT);
        zqr = mbox.index.search(SoapProtocol.Soap12, ctxt.getOperationContext(), params);
        while (zqr.hasNext()) {
            ZimbraHit hit = zqr.getNext();
            if (hit instanceof MessageHit)
                addAttachmentResources((MessageHit) hit, children);
        }
    } catch (Exception e) {
        ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
    } finally {
        Closeables.closeQuietly(zqr);
    }
    return children;
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) Account(com.zimbra.cs.account.Account) SearchParams(com.zimbra.cs.index.SearchParams) Mailbox(com.zimbra.cs.mailbox.Mailbox) MessageHit(com.zimbra.cs.index.MessageHit) ArrayList(java.util.ArrayList) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

Provisioning (com.zimbra.cs.account.Provisioning)532 Account (com.zimbra.cs.account.Account)216 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)158 Element (com.zimbra.common.soap.Element)144 ServiceException (com.zimbra.common.service.ServiceException)96 BeforeClass (org.junit.BeforeClass)93 MockProvisioning (com.zimbra.cs.account.MockProvisioning)89 Server (com.zimbra.cs.account.Server)83 HashMap (java.util.HashMap)76 Domain (com.zimbra.cs.account.Domain)70 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)53 Mailbox (com.zimbra.cs.mailbox.Mailbox)50 Cos (com.zimbra.cs.account.Cos)32 Test (org.junit.Test)30 NamedEntry (com.zimbra.cs.account.NamedEntry)25 AuthToken (com.zimbra.cs.account.AuthToken)23 Group (com.zimbra.cs.account.Group)23 ArrayList (java.util.ArrayList)23 AccountServiceException (com.zimbra.cs.account.AccountServiceException)22 DistributionList (com.zimbra.cs.account.DistributionList)22