use of org.bedework.webdav.servlet.shared.WebdavProperty in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getPrincipals.
@Override
public Collection<CalPrincipalInfo> getPrincipals(String resourceUri, final PrincipalPropertySearch pps) throws WebdavException {
List<CalPrincipalInfo> principals = null;
if (pps.applyToPrincipalCollectionSet) {
/* I believe it's valid (if unhelpful) to return nothing
*/
return new ArrayList<>();
}
if (!resourceUri.endsWith("/")) {
resourceUri += "/";
}
try {
String proot = BwPrincipal.principalRoot;
if (!proot.endsWith("/")) {
proot += "/";
}
if (!resourceUri.equals(proot)) {
return new ArrayList<>();
}
} catch (final Throwable t) {
throw new WebdavException(t);
}
/* If we don't support any of the properties in the searches we don't match.
*
* Currently we only support calendarUserAddressSet or calendarHomeSet.
*
* For calendarUserAddressSet the value to match must be a valid CUA
*
* For calendarHomeSet it must be a valid home uri
*/
final List<WebdavProperty> props = new ArrayList<>();
String cutype = null;
for (final WebdavProperty prop : pps.props) {
if (debug) {
debug("Try to match " + prop);
}
final String pval = prop.getPval();
if (CaldavTags.calendarUserAddressSet.equals(prop.getTag())) {
principals = and(principals, getCalPrincipalInfo(caladdrToPrincipal(pval)));
} else if (CaldavTags.calendarHomeSet.equals(prop.getTag())) {
final String path = getUrlHandler().unprefix(pval);
final CalDAVCollection col = getCollection(path);
if (col != null) {
principals = and(principals, getCalPrincipalInfo(col.getOwner()));
}
} else if (CaldavTags.calendarUserType.equals(prop.getTag())) {
cutype = pval;
} else if (WebdavTags.displayname.equals(prop.getTag())) {
// Store for directory search
props.add(prop);
}
}
try {
if (props.size() != 0) {
// Directory search
final Holder<Boolean> truncated = new Holder<>();
if (principals == null) {
principals = new ArrayList<>();
}
final List<BwPrincipalInfo> pis = getSvci().getDirectories().find(props, pps.pr.props, cutype, truncated);
if (pis != null) {
for (final BwPrincipalInfo pi : pis) {
principals.add(getCalPrincipalInfo(pi));
}
}
}
} catch (final Throwable t) {
throw new WebdavException(t);
}
if (principals == null) {
return new ArrayList<>();
}
return principals;
}
use of org.bedework.webdav.servlet.shared.WebdavProperty in project bw-calendar-engine by Bedework.
the class AbstractDirImpl method matching.
private List<MatchResult> matching(final BasicHttpClient cl, final String url, final String addrDataCtype, final List<WebdavProperty> props) throws CalFacadeException {
try {
final XmlEmit xml = new XmlEmit();
xml.addNs(new NameSpace(WebdavTags.namespace, "DAV"), true);
xml.addNs(new NameSpace(CarddavTags.namespace, "C"), false);
final StringWriter sw = new StringWriter();
xml.startEmit(sw);
xml.openTag(CarddavTags.addressbookQuery);
xml.openTag(WebdavTags.prop);
xml.emptyTag(WebdavTags.getetag);
if (addrDataCtype == null) {
xml.emptyTag(CarddavTags.addressData);
} else {
xml.emptyTag(CarddavTags.addressData, "content-type", addrDataCtype);
}
xml.closeTag(WebdavTags.prop);
xml.openTag(CarddavTags.filter, "test", "anyof");
for (final WebdavProperty wd : props) {
if (wd.getTag().equals(CaldavTags.calendarUserType)) {
// Should match onto KIND
continue;
}
if (wd.getTag().equals(BedeworkServerTags.emailProp)) {
// Match Email
xml.openTag(CarddavTags.propFilter, "name", "EMAIL");
xml.startTagSameLine(CarddavTags.textMatch);
xml.attribute("collation", "i;unicode-casemap");
xml.attribute("match-type", "contains");
xml.endOpeningTag();
xml.value(wd.getPval());
xml.closeTagSameLine(CarddavTags.textMatch);
xml.closeTag(CarddavTags.propFilter);
continue;
}
if (wd.getTag().equals(WebdavTags.displayname)) {
// Match FN
xml.openTag(CarddavTags.propFilter, "name", "FN");
xml.startTagSameLine(CarddavTags.textMatch);
xml.attribute("collation", "i;unicode-casemap");
xml.attribute("match-type", "contains");
xml.endOpeningTag();
xml.value(wd.getPval());
xml.closeTagSameLine(CarddavTags.textMatch);
xml.closeTag(CarddavTags.propFilter);
// continue;
}
}
xml.closeTag(CarddavTags.filter);
xml.closeTag(CarddavTags.addressbookQuery);
final DavUtil du = new DavUtil();
final byte[] content = sw.toString().getBytes();
final int res = du.sendRequest(cl, "REPORT", url, new BasicHeader("depth", "infinity"), // contentType,
"text/xml", // contentLen,
content.length, content);
// not defined for some reason
final int SC_MULTI_STATUS = 207;
if (res != SC_MULTI_STATUS) {
if (debug) {
debug("Got response " + res + " for path " + url);
}
return null;
}
final List<MatchResult> mrs = new ArrayList<>();
final MultiStatusResponse msr = du.getMultiStatusResponse(cl.getResponseBodyAsStream());
for (final MultiStatusResponseElement msre : msr.responses) {
MatchResult mr = new MatchResult();
mrs.add(mr);
mr.href = msre.href;
for (final PropstatElement pe : msre.propstats) {
if (pe.status != HttpServletResponse.SC_OK) {
continue;
}
for (final Element e : pe.props) {
if (XmlUtil.nodeMatches(e, WebdavTags.getetag)) {
mr.etag = XmlUtil.getElementContent(e);
continue;
}
if (XmlUtil.nodeMatches(e, CarddavTags.addressData)) {
mr.card = XmlUtil.getElementContent(e);
}
}
}
}
return mrs;
} catch (final Throwable t) {
throw new CalFacadeException(t);
} finally {
try {
cl.release();
} catch (final Throwable ignored) {
}
}
}
use of org.bedework.webdav.servlet.shared.WebdavProperty in project bw-calendar-engine by Bedework.
the class AbstractDirImpl method find.
private List<BwPrincipalInfo> find(final BasicHttpClient cdc, final CardDavInfo cdi, final String cua, final String cutype) throws CalFacadeException {
/* Typically a group entry in a directory doesn't have a mail -
The cua is a uri which often looks like a mailto.
*/
final List<WebdavProperty> props = new ArrayList<>();
final CalAddr ca = new CalAddr(cua);
if ((cutype != null) && cutype.equalsIgnoreCase(CuType.GROUP.getValue())) {
final WebdavProperty fnProp = new WebdavProperty(WebdavTags.displayname, ca.getId());
props.add(fnProp);
}
final WebdavProperty emailProp = new WebdavProperty(BedeworkServerTags.emailProp, ca.getNoScheme());
props.add(emailProp);
final List<BwPrincipalInfo> pis = new ArrayList<>();
final List<MatchResult> mrs = matching(cdc, cdi.getContextPath() + getCutypePath(cutype, cdi), null, props);
if (mrs == null) {
return pis;
}
for (final MatchResult mr : mrs) {
final BwPrincipalInfo pi = new BwPrincipalInfo();
pi.setPropertiesFromVCard(mr.card, null);
pis.add(pi);
}
return pis;
}
use of org.bedework.webdav.servlet.shared.WebdavProperty in project bw-calendar-engine by Bedework.
the class AbstractDirImpl method find.
@Override
public List<BwPrincipalInfo> find(final List<WebdavProperty> props, final List<WebdavProperty> returnProps, final String cutype, final Holder<Boolean> truncated) throws CalFacadeException {
final CardDavInfo cdi = getCardDavInfo(false);
if ((cdi == null) || (cdi.getHost() == null)) {
return null;
}
BasicHttpClient cdc = null;
final String path = getCutypePath(cutype, cdi);
String addrCtype = null;
/* See if we want address data in any particular form */
for (final WebdavProperty wd : returnProps) {
if (!wd.getTag().equals(CarddavTags.addressData)) {
continue;
}
addrCtype = wd.getAttr("content-type");
break;
}
try {
cdc = new BasicHttpClient(cdi.getHost(), cdi.getPort(), null, 15 * 1000);
final List<MatchResult> mrs = matching(cdc, cdi.getContextPath() + path, addrCtype, props);
final List<BwPrincipalInfo> pis = new ArrayList<>();
if (mrs == null) {
return pis;
}
for (final MatchResult mr : mrs) {
final BwPrincipalInfo pi = new BwPrincipalInfo();
pi.setPropertiesFromVCard(mr.card, addrCtype);
pis.add(pi);
}
return pis;
} catch (final Throwable t) {
if (getLogger().isDebugEnabled()) {
error(t);
}
throw new CalFacadeException(t);
} finally {
if (cdc != null) {
cdc.close();
}
}
}
Aggregations