Skip to content
Snippets Groups Projects
Verified Commit 4f1c5659 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Fix wrong url in filesystem response (when using proxies)

parent 6eb855d3
No related branches found
No related tags found
2 merge requests!103Release 0.11.0,!100F filesystem response url
Pipeline #39669 failed
This commit is part of merge request !100. Comments created here will be created in the context of that merge request.
...@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### ### Fixed ###
* Wrong url returned by FileSystem resource behind proxy.
* `NullPointerException` in GRPC API converters when executing SELECT query on * `NullPointerException` in GRPC API converters when executing SELECT query on
NULL values. NULL values.
......
...@@ -108,6 +108,7 @@ import org.restlet.data.Reference; ...@@ -108,6 +108,7 @@ import org.restlet.data.Reference;
import org.restlet.data.ServerInfo; import org.restlet.data.ServerInfo;
import org.restlet.data.Status; import org.restlet.data.Status;
import org.restlet.engine.Engine; import org.restlet.engine.Engine;
import org.restlet.routing.Redirector;
import org.restlet.routing.Route; import org.restlet.routing.Route;
import org.restlet.routing.Router; import org.restlet.routing.Router;
import org.restlet.routing.Template; import org.restlet.routing.Template;
...@@ -708,6 +709,9 @@ public class CaosDBServer extends Application { ...@@ -708,6 +709,9 @@ public class CaosDBServer extends Application {
protectedRouter.attach("/EntityPermissions/", EntityPermissionsResource.class); protectedRouter.attach("/EntityPermissions/", EntityPermissionsResource.class);
protectedRouter.attach("/EntityPermissions/{specifier}", EntityPermissionsResource.class); protectedRouter.attach("/EntityPermissions/{specifier}", EntityPermissionsResource.class);
protectedRouter.attach("/Owner/{specifier}", EntityOwnerResource.class); protectedRouter.attach("/Owner/{specifier}", EntityOwnerResource.class);
protectedRouter.attach(
"/FileSystem",
new Redirector(getContext(), "/FileSystem/", Redirector.MODE_CLIENT_PERMANENT));
protectedRouter.attach("/FileSystem/", FileSystemResource.class); protectedRouter.attach("/FileSystem/", FileSystemResource.class);
// FileSystem etc. needs to accept parameters which contain slashes and would otherwise be // FileSystem etc. needs to accept parameters which contain slashes and would otherwise be
// split at the first separator // split at the first separator
......
...@@ -87,12 +87,15 @@ public class FileSystemResource extends AbstractCaosDBServerResource { ...@@ -87,12 +87,15 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
if (file.isDirectory()) { if (file.isDirectory()) {
String path = (specifier.endsWith("/") ? specifier : specifier + "/"); String path = (specifier.endsWith("/") ? specifier : specifier + "/");
String referenceString = getUtils().getServerRootURI() + "/FileSystem/" + path; String url =
getUtils().getServerRootURI()
+ "/FileSystem"
+ (path.startsWith("/") ? path : ("/" + path));
final Element folder = new Element("dir"); final Element folder = new Element("dir");
folder.setAttribute("path", path); folder.setAttribute("path", path);
folder.setAttribute("name", file.getName()); folder.setAttribute("name", file.getName());
folder.setAttribute("url", referenceString); folder.setAttribute("url", url);
final boolean thumbnailsExist = final boolean thumbnailsExist =
new File(file.getAbsolutePath() + File.separator + ".thumbnails").exists(); new File(file.getAbsolutePath() + File.separator + ".thumbnails").exists();
...@@ -109,7 +112,7 @@ public class FileSystemResource extends AbstractCaosDBServerResource { ...@@ -109,7 +112,7 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
} }
if (thumbnailsExist) { if (thumbnailsExist) {
final Attribute thumbnailAttribute = getThumbnailAttribute(file, child, referenceString); final Attribute thumbnailAttribute = getThumbnailAttribute(file, child, url);
if (thumbnailAttribute != null) { if (thumbnailAttribute != null) {
celem.setAttribute(thumbnailAttribute); celem.setAttribute(thumbnailAttribute);
} }
......
...@@ -61,6 +61,23 @@ public class WebinterfaceUtils { ...@@ -61,6 +61,23 @@ public class WebinterfaceUtils {
private long buildNumberDate; private long buildNumberDate;
private static final Map<String, WebinterfaceUtils> instances = new HashMap<>(); private static final Map<String, WebinterfaceUtils> instances = new HashMap<>();
public static String getForwardedProto(Request request) {
String scheme = null;
String forwarded = request.getHeaders().getFirstValue("Forwarded", true);
if (forwarded != null) {
for (String directive : forwarded.split(";")) {
String[] s = directive.split("=", 2);
if (s.length == 2 && "proto".equalsIgnoreCase(s[0])) {
scheme = s[1];
}
}
}
if (scheme == null) {
scheme = request.getHeaders().getFirstValue("X-Forwarded-Proto", true);
}
return scheme;
}
/** /**
* Retrieve an instance of {@link WebinterfaceUtils} for the request. The instance can be shared * Retrieve an instance of {@link WebinterfaceUtils} for the request. The instance can be shared
* with other callers. * with other callers.
...@@ -70,7 +87,7 @@ public class WebinterfaceUtils { ...@@ -70,7 +87,7 @@ public class WebinterfaceUtils {
*/ */
public static WebinterfaceUtils getInstance(Request request) { public static WebinterfaceUtils getInstance(Request request) {
String hostStr = request.getHostRef().getHostIdentifier(); String hostStr = request.getHostRef().getHostIdentifier();
String scheme = request.getHeaders().getFirstValue("X-Forwarded-Proto", true); String scheme = getForwardedProto(request);
if (scheme != null) { if (scheme != null) {
hostStr = hostStr.replaceFirst("^" + request.getHostRef().getScheme(), scheme); hostStr = hostStr.replaceFirst("^" + request.getHostRef().getScheme(), scheme);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment