Skip to content

Commit

Permalink
Merge pull request #32 from ical4j/develop
Browse files Browse the repository at this point in the history
Prepare release
  • Loading branch information
benfortuna authored Mar 23, 2018
2 parents d1f08d4 + 3bc9d63 commit 8ef11f9
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 80 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ repositories {

dependencies {
compileOnly 'javax.servlet:servlet-api:2.5'
compile 'org.mnode.ical4j:ical4j:2.1.0', 'org.mnode.ical4j:ical4j-extensions:1.0.2',

compile 'org.mnode.ical4j:ical4j:2.2.0', 'org.mnode.ical4j:ical4j-extensions:1.0.2',
'org.mnode.ical4j:ical4j-vcard:1.0.1',
'commons-io:commons-io:2.3', 'org.codehaus.groovy:groovy-all:2.3.6',
'commons-io:commons-io:2.3',
'org.apache.jackrabbit:jackrabbit-webdav:2.8.0',
'javax.jcr:jcr:2.0', 'org.jcrom:jcrom:2.0.0'

Expand Down
5 changes: 5 additions & 0 deletions gradle.properties.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
systemProp.sonar.host.url=https://sonar.mnode.org

sonatype_username=
sonatype_password=

bintray_user=
bintray_key=
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
*/
package net.fortuna.ical4j.connector.dav;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;

import net.fortuna.ical4j.connector.FailedOperationException;
import net.fortuna.ical4j.connector.ObjectCollection;
import net.fortuna.ical4j.connector.ObjectStore;
import net.fortuna.ical4j.connector.ObjectStoreException;
import net.fortuna.ical4j.connector.dav.enums.SupportedFeature;
import net.fortuna.ical4j.util.Configurator;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;

/**
* @param <C>
Expand All @@ -51,6 +52,8 @@
*/
public abstract class AbstractDavObjectStore<C extends ObjectCollection<?>> implements ObjectStore<C> {

private final DavClientFactory clientFactory;

private DavClient davClient;

private String username;
Expand All @@ -72,6 +75,7 @@ public abstract class AbstractDavObjectStore<C extends ObjectCollection<?>> impl
public AbstractDavObjectStore(URL url, PathResolver pathResolver) {
this.rootUrl = url;
this.pathResolver = pathResolver;
this.clientFactory = new DavClientFactory("true".equals(Configurator.getProperty("ical4j.connector.dav.preemptiveauth")));
}

/**
Expand All @@ -85,24 +89,18 @@ public final String getPath() {
* {@inheritDoc}
*/
public final boolean connect() throws ObjectStoreException {
// try {
// davClient = SardineFactory.begin();

final String principalPath = pathResolver.getPrincipalPath(getUserName());
final String userPath = pathResolver.getUserPath(getUserName());
davClient = new DavClient(rootUrl, principalPath, userPath);
davClient.begin();
// }
// catch (SardineException se) {
// throw new ObjectStoreException(se);
// }
final String principalPath = pathResolver.getPrincipalPath(getUserName());
final String userPath = pathResolver.getUserPath(getUserName());
davClient = clientFactory.newInstance(rootUrl, principalPath, userPath);
davClient.begin();

return true;
}


public final boolean connect( String bearerAuth ) throws ObjectStoreException {
try {
davClient = new DavClient( rootUrl, rootUrl.getFile(), rootUrl.getFile() );
davClient = clientFactory.newInstance(rootUrl, rootUrl.getFile(), rootUrl.getFile());
davClient.begin( bearerAuth );

this.bearerAuth = bearerAuth;
Expand All @@ -123,25 +121,19 @@ public final boolean connect( String bearerAuth ) throws ObjectStoreException {
*/
public final boolean connect(String username, char[] password) throws ObjectStoreException {
try {
// davClient = SardineFactory.begin(username, new String(password));
this.username = username;

final String principalPath = pathResolver.getPrincipalPath(username);
final String userPath = pathResolver.getUserPath(username);
davClient = new DavClient(rootUrl, principalPath, userPath);
davClient = clientFactory.newInstance(rootUrl, principalPath, userPath);
supportedFeatures = davClient.begin(username, password);


}
catch (IOException ioe) {
throw new ObjectStoreException(ioe);
}
catch (FailedOperationException foe) {
throw new ObjectStoreException(foe);
}
// catch (SardineException se) {
// throw new ObjectStoreException(se);
// }

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@
import org.apache.jackrabbit.webdav.version.report.ReportInfo;
import org.apache.jackrabbit.webdav.version.report.ReportType;
import org.apache.jackrabbit.webdav.xml.DomUtil;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import javax.swing.text.html.parser.Parser;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
Expand All @@ -86,7 +84,7 @@ public class CalDavCalendarCollection extends AbstractDavObjectCollection<Calend
* Only {@link CalDavCalendarStore} should be calling this, so default modifier is applied.
*
* @param calDavCalendarStore
* @param path
* @param id
*/
CalDavCalendarCollection(CalDavCalendarStore calDavCalendarStore, String id) {
this(calDavCalendarStore, id, null, null);
Expand Down Expand Up @@ -135,7 +133,7 @@ final void create() throws IOException, ObjectStoreException {
/**
* @return an array of calendar objects
* @deprecated Use the getEvents() method
* @see net.fortuna.ical4j.connector.CalendarCollection#getCalendars()
* @see CalendarCollection#getComponents()
*/
@Deprecated
public Calendar[] getCalendars() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
*/
package net.fortuna.ical4j.connector.dav;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import net.fortuna.ical4j.connector.CalendarCollection;
import net.fortuna.ical4j.connector.CalendarStore;
import net.fortuna.ical4j.connector.ObjectNotFoundException;
Expand All @@ -57,34 +43,18 @@
import net.fortuna.ical4j.model.component.VFreeBusy;
import net.fortuna.ical4j.model.parameter.Cn;
import net.fortuna.ical4j.model.parameter.CuType;
import net.fortuna.ical4j.model.property.Attendee;
import net.fortuna.ical4j.model.property.CalScale;
import net.fortuna.ical4j.model.property.DtEnd;
import net.fortuna.ical4j.model.property.DtStart;
import net.fortuna.ical4j.model.property.Method;
import net.fortuna.ical4j.model.property.Organizer;
import net.fortuna.ical4j.model.property.ProdId;
import net.fortuna.ical4j.model.property.Version;
import net.fortuna.ical4j.model.property.*;
import net.fortuna.ical4j.util.FixedUidGenerator;
import net.fortuna.ical4j.util.UidGenerator;

import org.apache.commons.httpclient.ChunkedInputStream;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavServletResponse;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.MultiStatusResponse;
import org.apache.jackrabbit.webdav.*;
import org.apache.jackrabbit.webdav.Status;
import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import org.apache.jackrabbit.webdav.client.methods.ReportMethod;
import org.apache.jackrabbit.webdav.property.DavProperty;
import org.apache.jackrabbit.webdav.property.DavPropertyIterator;
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
import org.apache.jackrabbit.webdav.property.*;
import org.apache.jackrabbit.webdav.security.SecurityConstants;
import org.apache.jackrabbit.webdav.version.DeltaVConstants;
import org.apache.jackrabbit.webdav.version.report.ReportInfo;
Expand All @@ -96,6 +66,19 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

/**
* $Id$
*
Expand Down Expand Up @@ -610,7 +593,7 @@ public ArrayList<ScheduleResponse> findFreeBusyInfoForAttendees(Organizer organi
postMethod.addRequestHeader(new Header("Recipient", strAttendee));
}

UidGenerator ug = new UidGenerator(ramdomizer.nextInt() + "");
UidGenerator ug = new FixedUidGenerator(ramdomizer.nextInt() + "");
fbComponent.getProperties().add(ug.generateUid());
calendar.getComponents().add(fbComponent);

Expand Down
29 changes: 14 additions & 15 deletions src/main/java/net/fortuna/ical4j/connector/dav/DavClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,10 @@
*/
package net.fortuna.ical4j.connector.dav;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import net.fortuna.ical4j.connector.FailedOperationException;
import net.fortuna.ical4j.connector.dav.enums.SupportedFeature;
import net.fortuna.ical4j.connector.dav.property.CSDavPropertyName;
import net.fortuna.ical4j.connector.dav.property.CalDavPropertyName;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HeaderElement;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthPolicy;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.protocol.Protocol;
Expand All @@ -57,6 +44,11 @@
import org.apache.jackrabbit.webdav.property.DavPropertyName;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class DavClient {

/**
Expand All @@ -68,14 +60,21 @@ public class DavClient {

private String userPath;

private final boolean preemptiveAuth;

/**
* The HTTP client configuration.
*/
protected HostConfiguration hostConfiguration;

public DavClient(URL url, String principalPath, String userPath) {
this(url, principalPath, userPath, false);
}

public DavClient(URL url, String principalPath, String userPath, boolean preemptiveAuth) {
this.principalPath = principalPath;
this.userPath = userPath;
this.preemptiveAuth = preemptiveAuth;

final Protocol protocol = Protocol.getProtocol(url.getProtocol());
hostConfiguration = new HostConfiguration();
Expand All @@ -84,7 +83,7 @@ public DavClient(URL url, String principalPath, String userPath) {

void begin() {
httpClient = new HttpClient();
httpClient.getParams().setAuthenticationPreemptive(false);
httpClient.getParams().setAuthenticationPreemptive(preemptiveAuth);
}

ArrayList<SupportedFeature> begin(String bearerAuth) throws IOException, FailedOperationException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.fortuna.ical4j.connector.dav;

import java.net.URL;

public class DavClientFactory {

private final boolean preemptiveAuth;

public DavClientFactory(boolean preemptiveAuth) {
this.preemptiveAuth = preemptiveAuth;
}

public DavClient newInstance(URL url, String principalPath, String userPath) {
return new DavClient(url, principalPath, userPath, preemptiveAuth);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.fortuna.ical4j.connector.dav

import spock.lang.Specification

class DavClientTest extends Specification {

def 'assert preemptive auth configuration'() {
given: 'a dav client factory configured for preemptive auth'
DavClientFactory clientFactory = [true]

when: 'a new client instance is created'
DavClient client = clientFactory.newInstance(URI.create('http://dav.example.com').toURL(), '', '');

and: 'a session is initated'
client.begin()

then: 'the client is configured for preemptive auth'
client.httpClient.params.authenticationPreemptive == true
}
}
4 changes: 3 additions & 1 deletion src/test/resources/ical4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@

ical4j.unfolding.relaxed=true

ical4j.parsing.relaxed=true
ical4j.parsing.relaxed=true

#ical4j.connector.dav.preemptiveauth={true|false}

0 comments on commit 8ef11f9

Please sign in to comment.