Skip to content

Commit 8a938b5

Browse files
committed
Removing default redirect action for 'leaving secure site' and fixing language switch redirect
1 parent 0b51e2f commit 8a938b5

11 files changed

Lines changed: 35 additions & 112 deletions

File tree

gocwebtemplate-core/gocwebtemplate-core-base/src/main/java/goc/webtemplate/component/BaseUtil.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
import goc.webtemplate.Constants;
99

1010
public final class BaseUtil {
11-
public static void doLeaveSecureSite(HttpServletRequest req, HttpServletResponse res) throws Exception {
12-
String redirectUrl = URLDecoder.decode(req.getParameter("targetUrl"), "UTF-8");
13-
res.sendRedirect(redirectUrl);
14-
}
15-
1611
public static void doLocaleSwitch(HttpServletRequest req, HttpServletResponse res) throws Exception {
1712
String currLang = req.getSession().getAttribute(Constants.CURRENT_LANG_SESSION_KEY) == null ?
1813
req.getLocale().getLanguage() :
@@ -24,6 +19,10 @@ public static void doLocaleSwitch(HttpServletRequest req, HttpServletResponse re
2419
}
2520

2621
String prevUrl = URLDecoder.decode(req.getParameter(Constants.QUERYSTRING_KEY), "UTF-8");
22+
23+
// Validate that the redirect link is relative to the host and NOT absolute or relative to scheme
24+
if ((!prevUrl.startsWith("/")) || prevUrl.startsWith("//")) throw new Exception("Unauthorized return URL specified for language switching.");
25+
2726
res.sendRedirect(prevUrl);
2827
}
2928

gocwebtemplate-core/gocwebtemplate-core-base/src/main/java/goc/webtemplate/component/jsonentities/RefFooter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
import goc.webtemplate.LeavingSecureSiteWarning;
66

7-
import goc.webtemplate.Utility;
87
import goc.webtemplate.WebAnalyticsInfo;
98

10-
import goc.webtemplate.component.JsonValueUtils;
11-
129
/**
1310
* Objects of this class are meant to be serialized to a JSON object to be passed
1411
* as parameter to the 'wet.builder.refFooter' JavaScript function in the template
@@ -39,7 +36,7 @@ public RefFooter(String cdnEnv, ExitSecureSite exitSecureSite, String jqueryEnv,
3936
public RefFooter(String cdnEnv, LeavingSecureSiteWarning lssw, String jqueryEnv, String localPath, WebAnalyticsInfo webAnalyticsInfo, boolean isApplication) {
4037
this.cdnEnv = cdnEnv;
4138
this.exitSecureSite = null;
42-
if ((lssw != null) && lssw.isEnabled() && !Utility.isNullOrEmpty(lssw.getRedirectUrl())) {
39+
if ((lssw != null) && lssw.isEnabled()) {
4340
this.exitSecureSite = new ExitSecureSite(lssw);
4441
}
4542
this.jqueryEnv = jqueryEnv;

gocwebtemplate-core/gocwebtemplate-core-jsp/src/main/java/goc/webtemplate/component/jsp/BaseCoreBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected String getDefaultLanguageLinkUrl() {
3535

3636
@Override
3737
protected String getDefaultLeaveSecureSiteRedirectUrl() {
38-
return "leavesecuresiteredirect.action";
38+
return null;
3939
}
4040

4141
@Override

gocwebtemplate-core/gocwebtemplate-core-jsp/src/main/java/goc/webtemplate/component/jsp/LeaveSecureSiteAction.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

gocwebtemplate-core/gocwebtemplate-core-spring/src/main/java/goc/webtemplate/component/spring/BaseCoreBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected String getDefaultLanguageLinkUrl() {
3535

3636
@Override
3737
protected String getDefaultLeaveSecureSiteRedirectUrl() {
38-
return "gocwebtemplate_leavesecuresiteredirect";
38+
return null;
3939
}
4040

4141
@Override

gocwebtemplate-core/gocwebtemplate-core-spring/src/main/java/goc/webtemplate/component/spring/controller/CoreController.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@
1010

1111
@Controller
1212
public class CoreController {
13-
1413
@GetMapping("/gocwebtemplate_switchlocale")
1514
public void SwitchLocale(HttpServletRequest request, HttpServletResponse response) throws Exception {
1615
BaseUtil.doLocaleSwitch(request, response);
1716
}
18-
19-
@GetMapping("/gocwebtemplate_leavesecuresiteredirect")
20-
public void LeaveSecureSiteRedirect(HttpServletRequest request, HttpServletResponse response) throws Exception {
21-
//Custom processing would go here
22-
BaseUtil.doLeaveSecureSite(request, response);
23-
}
2417
}

gocwebtemplate-sample-jsp/src/main/java/goc/webtemplate/jsp/samplebeans/LeaveSecureSiteSampleBean.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public void onWebTemplateInitialize() {
1212

1313
lssw.setEnabled(true);
1414
lssw.setMessage("You are about to leave a secure site, do you wish to continue?");
15-
lssw.setRedirectUrl("leavesecuresiteredirect.action");
1615
lssw.setExcludedDomains("www.esdc.gc.ca,www.jobbank.gc.ca,www.readseal.ca");
1716
lssw.setCancelMessage("Don't leave");
1817
lssw.setYesMessage("Yes, leave this site");

gocwebtemplate-sample-jsp/src/main/resources/struts.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<result-types>
1414
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
1515
</result-types>
16-
<action name="leavesecuresiteredirect" class="goc.webtemplate.component.jsp.LeaveSecureSiteAction" method="execute"></action>
1716
<action name="switchlocale" class="goc.webtemplate.component.jsp.SwitchLocaleAction" method="execute"></action>
1817
<!-- ============================================================== -->
1918

gocwebtemplate-sample-jsp/src/main/webapp/samplecontents/leavesecuresitesamplecontent.jsp

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<ul>
1818
<li>display the message to the user in the form of a modal window</li>
1919
<li>display the message your application provides</li>
20-
<li>allow your application to execute any clean up code (ex: close session, gracefully logout user etc...)</li>
2120
<li>allow your application to exlude any domains from raising the warning</li>
21+
<li>optionally, allow your application to execute any clean up code (ex: close session, gracefully logout user etc...)</li>
2222
</ul>
2323
<h2>How it works</h2>
2424
<ul>
@@ -29,29 +29,21 @@
2929
<li>A "Yes" button appears on the window to allow the user to continue with the redirection to the selected link. (Text can be customized, see below.)</li>
3030
</ul>
3131
</li>
32-
<li>if the "Yes" button is clicked:
33-
<ul>
34-
<li>the user will first be redirect to the url set in <code class="wb-prettify">"leavingSecureSiteRedirectUrl"</code> via either the cdn.properties file or programmatically</li>
35-
<li>the info of the linked that was clicked is part of the querystring to that url</li>
36-
<li>in the redirect url provided earlier, attach the preRenderView event to the page and execute a custom bean method to perform the redirect</li>
37-
<li>execute any clean up code your application requires</li>
38-
<li>once executed the custom bean class will redirect the user to the url of the clicked link</li>
39-
<li>the leave secure site feature is already provided by default as part of the GoC Web Template package, by default it will use the templates/leavesecuresiteredirect.xhtml page</li>
40-
<li>by default the leave secure site redirect page will invoke the <code class="wb-prettify">leavesecuresiteredirect.action</code> Struts Action already pre-registered in struts.xml</li>
41-
</ul>
32+
<li>if the "Yes" button is clicked, the browser will be directed to the external link</li>
33+
<li>optionally, a redirect url can be set in <code class="wb-prettify">"leavingSecureSiteRedirectUrl"</code> via either the cdn.properties file or programmatically.
34+
If this is used, the browser will be directed to this page before leaving, where the application can terminate the user's session and let them proceed to the external link.
35+
The external link will be presented to the user by placing an element <code class="wb-prettify">&lt;span class="wb-exitscript wb-exitscript-exiturlparam"&gt;&lt;/span&gt;</code> on the page.
36+
For an example of a "middle page", refer to <a href="https://wet-boew.github.io/wet-boew/demos/exitscript/exitscript-en.html#wb-auto-3">scenario 3 link in the WET Documentation</a>.
4237
</li>
4338
</ul>
4439
<p>Here is a local link that will not display the warning: <a href="basesettingssample.action">Link to Local Page</a></p>
45-
<p>Here is an external link that will display the warning:<a href="https://gccode.ssc-spc.gc.ca/iitb-dgiit/sds/GOCWebTemplates/JavaTemplates/wikis/Redirect-Page">Link to External Page</a></p>
40+
<p>Here is an external link that will display the warning:<a href="https://github.com/wet-boew/cdts-JavaTemplates/wiki/Redirect-Page">Link to External Page</a></p>
4641
<h2>Steps to implement:</h2>
4742
<h3>Enable the leaving secure site feature</h3>
4843
<ul>
4944
<li>Set, via the cdn.properties file or programmatically in your custom bean class, <code class="wb-prettify">"Enabled"</code> to <strong>"true"</strong></li>
5045
<li>Provide the message to be displayed by setting the <code class="wb-prettify">"Message"</code> programmatically via the <code class="wb-prettify">setLeavingSecureSiteWarning</code> method in your custom bean class.</li>
51-
<li>Set, via the cdn.properties file or programmatically in your custom bean class, <code class="wb-prettify">"RedirectUrl"</code> to your action class which will execute your clean up code and then redirect to the selected url.</li>
5246
<li>Set, via the cdn.properties or programmatically in your custom bean class, <code class="wb-prettify">"ExcludedDomain"</code> the list of domains you do not want to raise the warning</li>
53-
<li>Optionally, provide a cancel message by setting the <code class="wb-prettify">"CancelMessage"</code> programmatically via the <code class="wb-prettify">setLeavingSecureSiteWarning</code> method in your custom bean class.</li>
54-
<li>Optionally, provide a yes message by setting the <code class="wb-prettify">"YesMessage"</code> programmatically via the <code class="wb-prettify">setLeavingSecureSiteWarning</code> method in your custom bean class.</li>
5547
</ul>
5648
<div class="wb-prettify all-pre lang-vb linenums">
5749
<pre>
@@ -62,7 +54,6 @@ public void onWebTemplateInitialize() {
6254

6355
lssw.setEnabled(true);
6456
lssw.setMessage("You are about to leave a secure site, do you wish to continue?");
65-
lssw.setRedirectUrl("leavesecuresiteredirect.action");
6657
lssw.setExcludedDomains("www.esdc.gc.ca,www.jobbank.gc.ca,www.readseal.ca");
6758
lssw.setCancelMessage("Don't leave");
6859
lssw.setYesMessage("Yes, leave this site");
@@ -73,26 +64,4 @@ public void onWebTemplateInitialize() {
7364
}
7465
</pre>
7566
</div>
76-
<h3>Created your custom "redirect" class</h3>
77-
<ul>
78-
<li>Create a class and a public method will be invoked by the preRenderView event of the redirect url</li>
79-
<li>enter your clean up code if required</li>
80-
<li>redirect to the <code class="wb-prettify">"targetURL"</code> parameter value in the querystring</li>
81-
</ul>
82-
<div class="wb-prettify all-pre lang-vb linenums">
83-
<h3>Code Sample for your Redirect action class</h3>
84-
<pre>
85-
import java.net.URLDecoder;
86-
import javax.servlet.http.HttpServletRequest;
87-
import org.apache.struts2.ServletActionContext;
88-
89-
public class LeaveSecureSiteAction {
90-
public void execute() throws Exception {
91-
HttpServletRequest currentReq = ServletActionContext.getRequest();
92-
String redirectUrl = URLDecoder.decode(currentReq.getParameter("targetUrl"), "UTF-8");
93-
ServletActionContext.getResponse().sendRedirect(redirectUrl);
94-
}
95-
}
96-
</pre>
97-
</div>
9867
<%@ include file="_sampleslist.jsp" %>

gocwebtemplate-sample-spring/src/main/java/goc/webtemplate/spring/samplebeans/LeavingSecureSiteSampleBean.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public void onWebTemplateInitialize() {
1414

1515
lssw.setEnabled(true);
1616
lssw.setMessage("You are about to leave a secure site, do you wish to continue?");
17-
lssw.setRedirectUrl("gocwebtemplate_leavesecuresiteredirect");
1817
lssw.setExcludedDomains("www.esdc.gc.ca,www.jobbank.gc.ca,www.readseal.ca");
1918
lssw.setCancelMessage("Don't leave");
2019
lssw.setYesMessage("Yes, leave this site");

0 commit comments

Comments
 (0)