Skip to content

Commit

Permalink
Added support for overriding the default TZURL to use a secure connec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
benfortuna committed Apr 8, 2022
1 parent 8103bb7 commit 233ec40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/main/java/net/fortuna/ical4j/model/TimeZoneUpdater.java
Expand Up @@ -58,6 +58,7 @@ public class TimeZoneUpdater {
private static final String UPDATE_PROXY_TYPE = "net.fortuna.ical4j.timezone.update.proxy.type";
private static final String UPDATE_PROXY_HOST = "net.fortuna.ical4j.timezone.update.proxy.host";
private static final String UPDATE_PROXY_PORT = "net.fortuna.ical4j.timezone.update.proxy.port";
private static final String SECURE_CONNECTION_ENABLED = "net.fortuna.ical4j.timezone.update.connection.secure";

private Proxy proxy = null;

Expand Down Expand Up @@ -85,10 +86,19 @@ public URLConnection openConnection(URL url) throws IOException {
final int readTimeout = Configurator.getIntProperty(UPDATE_READ_TIMEOUT).orElse(0);

URLConnection connection;
if ("true".equals(Configurator.getProperty(UPDATE_PROXY_ENABLED).orElse("false")) && proxy != null) {
connection = url.openConnection(proxy);
if ("true".equals(Configurator.getProperty(SECURE_CONNECTION_ENABLED).orElse("false"))) {
URL secureUrl = new URL("https", url.getHost(), url.getFile());
if ("true".equals(Configurator.getProperty(UPDATE_PROXY_ENABLED).orElse("false")) && proxy != null) {
connection = secureUrl.openConnection(proxy);
} else {
connection = secureUrl.openConnection();
}
} else {
connection = url.openConnection();
if ("true".equals(Configurator.getProperty(UPDATE_PROXY_ENABLED).orElse("false")) && proxy != null) {
connection = url.openConnection(proxy);
} else {
connection = url.openConnection();
}
}

connection.setConnectTimeout(connectTimeout);
Expand All @@ -114,7 +124,7 @@ public VTimeZone updateDefinition(VTimeZone vTimeZone) {
return updatedVTimeZone;
}
} catch (IOException | ParserException e) {
LoggerFactory.getLogger(TimeZoneLoader.class).warn("Error updating timezone definition", e);
LoggerFactory.getLogger(TimeZoneUpdater.class).warn("Error updating timezone definition", e);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/ical4j.properties
Expand Up @@ -34,13 +34,14 @@

#net.fortuna.ical4j.timezone.registry=net.fortuna.ical4j.model.DefaultTimeZoneRegistryFactory

net.fortuna.ical4j.timezone.update.enabled=false
net.fortuna.ical4j.timezone.update.enabled=true
#net.fortuna.ical4j.timezone.update.timeout.connect ## - Connect timeout ( milliseconds, e.g. 10000 - 10s, unlimited by default )
#net.fortuna.ical4j.timezone.update.timeout.read ## - Read timeout ( milliseconds, e.g. 10000 - 10s, unlimited by default )
#net.fortuna.ical4j.timezone.update.proxy.enabled={true|false} ## - Use proxy ( true / false )
#net.fortuna.ical4j.timezone.update.proxy.type ## - Proxy type ( DIRECT / HTTP / SOCKS )
#net.fortuna.ical4j.timezone.update.proxy.host ## - Proxy server host name ( e.g. proxy.myorg.com )
#net.fortuna.ical4j.timezone.update.proxy.port=8080 ## - Proxy server port number ( e.g. 3128 )
net.fortuna.ical4j.timezone.update.connection.secure=true

#net.fortuna.ical4j.timezone.cache.impl=net.fortuna.ical4j.util.MapTimeZoneCache

Expand Down

0 comments on commit 233ec40

Please sign in to comment.