Skip to content

Commit

Permalink
KNL-1435 Improve force.url.secure implementation (sakaiproject#2773)
Browse files Browse the repository at this point in the history
Improves the use of the force.url.secure property to reduce the chances
of an exception.
  • Loading branch information
master-bob authored and jonespm committed Jun 13, 2016
1 parent e661e5a commit af79477
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 4 additions & 0 deletions kernel/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,9 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project>
19 changes: 6 additions & 13 deletions kernel/api/src/main/java/org/sakaiproject/util/RequestFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sakaiproject.cluster.api.ClusterNode;
Expand Down Expand Up @@ -278,19 +279,11 @@ public static String serverUrl(HttpServletRequest req)

// if force.url.secure is set (to a https port number), use https and this port
String forceSecure = System.getProperty("sakai.force.url.secure");
if (forceSecure != null && !"".equals(forceSecure)) {
// allow the value to be forced to 0 or blank to disable this
int portNum;
try {
portNum = Integer.parseInt(forceSecure);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("force.url.secure must be set to the port number which should be a numeric value > 0 (or set it to 0 to disable secure urls)", e);
}
if (portNum > 0) {
transport = "https";
port = portNum;
secure = true;
}
int forceSecureInt = NumberUtils.toInt(forceSecure);
if (forceSecureInt > 0 && forceSecureInt <= 65535) {
transport = "https";
port = forceSecureInt;
secure = true;
} else {
// otherwise use the request scheme and port
transport = req.getScheme();
Expand Down
4 changes: 4 additions & 0 deletions rsf/sakai-rsf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package org.sakaiproject.rsf.copies;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.math.NumberUtils;

/**
* Copies of definitions in the utility class org.sakaiproject.util.Web which
Expand Down Expand Up @@ -61,12 +62,12 @@ public static String serverUrl(HttpServletRequest req) {
// if force.url.secure is set (to a https port number), use https and
// this port
String forceSecure = System.getProperty("sakai.force.url.secure");
if (forceSecure != null) {
int forceSecureInt = NumberUtils.toInt(forceSecure);
if (forceSecureInt > 0 && forceSecureInt <= 65535) {
transport = "https";
port = Integer.parseInt(forceSecure);
port = forceSecureInt;
secure = true;
}

// otherwise use the request scheme and port
else {
transport = req.getScheme();
Expand Down

0 comments on commit af79477

Please sign in to comment.