From 8f1dc607d135fd99d769a2dfd1e11e00d72d0506 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 19 Nov 2014 11:34:17 -0500
Subject: [PATCH] Merged #223 "Add support for image/svg+xml content type to raw servlet"
---
src/main/java/com/gitblit/wicket/pages/BasePage.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java
index 7d3d3a2..fbe5861 100644
--- a/src/main/java/com/gitblit/wicket/pages/BasePage.java
+++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java
@@ -35,6 +35,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.wicket.Application;
+import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RedirectToUrlException;
@@ -42,9 +43,12 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.markup.html.resources.JavascriptResourceReference;
+import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.protocol.http.RequestUtils;
import org.apache.wicket.protocol.http.WebResponse;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
+import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.apache.wicket.util.time.Duration;
import org.apache.wicket.util.time.Time;
import org.slf4j.Logger;
@@ -74,11 +78,13 @@
public BasePage() {
super();
+ add(new RepeatingView("bottomScripts").setRenderBodyOnly(true));
customizeHeader();
}
public BasePage(PageParameters params) {
super(params);
+ add(new RepeatingView("bottomScripts").setRenderBodyOnly(true));
customizeHeader();
}
@@ -98,6 +104,10 @@
}
}
+ protected String getContextUrl() {
+ return getRequest().getRelativePathPrefixToContextRoot();
+ }
+
protected String getCanonicalUrl() {
return getCanonicalUrl(getClass(), getPageParameters());
}
@@ -106,6 +116,15 @@
String relativeUrl = urlFor(clazz, params).toString();
String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
return canonicalUrl;
+ }
+
+ protected void redirectTo(Class<? extends BasePage> pageClass) {
+ redirectTo(pageClass, null);
+ }
+
+ protected void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
+ String absoluteUrl = getCanonicalUrl(pageClass, parameters);
+ getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
protected String getLanguageCode() {
@@ -162,6 +181,9 @@
// use default Wicket caching behavior
super.setHeaders(response);
}
+
+ // XRF vulnerability. issue-500 / ticket-166
+ response.setHeader("X-Frame-Options", "SAMEORIGIN");
}
/**
@@ -488,4 +510,39 @@
}
return sb.toString();
}
+
+ /**
+ * Adds a HTML script element loading the javascript designated by the given path.
+ *
+ * @param scriptPath
+ * page-relative path to the Javascript resource; normally starts with "scripts/"
+ */
+ protected void addBottomScript(String scriptPath) {
+ Component bottomScriptContainer = get("bottomScripts");
+ if (bottomScriptContainer instanceof RepeatingView) {
+ // Always true.
+ RepeatingView bottomScripts = (RepeatingView) bottomScriptContainer;
+ Label script = new Label(bottomScripts.newChildId(), "<script type='text/javascript' src='"
+ + urlFor(new JavascriptResourceReference(this.getClass(), scriptPath)) + "'></script>\n");
+ bottomScripts.add(script.setEscapeModelStrings(false).setRenderBodyOnly(true));
+ }
+ }
+
+ /**
+ * Adds a HTML script element containing the given code.
+ *
+ * @param code
+ * inline script code
+ */
+ protected void addBottomScriptInline(String code) {
+ Component bottomScriptContainer = get("bottomScripts");
+ if (bottomScriptContainer instanceof RepeatingView) {
+ // Always true.
+ RepeatingView bottomScripts = (RepeatingView) bottomScriptContainer;
+ Label script = new Label(bottomScripts.newChildId(),
+ "<script type='text/javascript'>/*<![CDATA[*/\n" + code + "\n//]]>\n</script>\n");
+ bottomScripts.add(script.setEscapeModelStrings(false).setRenderBodyOnly(true));
+ }
+ }
+
}
--
Gitblit v1.9.1