Skip to content

Commit aa2743a

Browse files
committed
Working to remove 'leaving secure site' redirect page from Spring Boot project
1 parent 323a850 commit aa2743a

6 files changed

Lines changed: 14 additions & 40 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import goc.webtemplate.Constants;
99

1010
public final class BaseUtil {
11-
public static void doLeaveSecureSite(HttpServletRequest req, HttpServletResponse res) throws Exception {
11+
public static void doLeaveSecureSite(HttpServletRequest req, HttpServletResponse res) throws Exception { //TODO: Remove this once no longer referenced
1212
String redirectUrl = URLDecoder.decode(req.getParameter("targetUrl"), "UTF-8");
1313
res.sendRedirect(redirectUrl);
1414
}
@@ -24,6 +24,10 @@ public static void doLocaleSwitch(HttpServletRequest req, HttpServletResponse re
2424
}
2525

2626
String prevUrl = URLDecoder.decode(req.getParameter(Constants.QUERYSTRING_KEY), "UTF-8");
27+
28+
// Validate that the redirect link is relative to the host and NOT absolute or relative to scheme
29+
if ((!prevUrl.startsWith("/")) || prevUrl.startsWith("//")) throw new Exception("Unauthorized return URL specified for language switching.");
30+
2731
res.sendRedirect(prevUrl);
2832
}
2933

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.List;
66

77
import goc.webtemplate.LeavingSecureSiteWarning;
8-
import goc.webtemplate.Utility;
98
import goc.webtemplate.WebAnalyticsInfo;
109

1110
/**
@@ -39,7 +38,7 @@ public SetupBase(String subTheme, String jqueryEnv, LeavingSecureSiteWarning lss
3938
this.subTheme = subTheme;
4039
this.jqueryEnv = jqueryEnv;
4140
this.exitSecureSite = null;
42-
if ((lssw != null) && lssw.isEnabled() && !Utility.isNullOrEmpty(lssw.getRedirectUrl())) {
41+
if ((lssw != null) && lssw.isEnabled()) {
4342
this.exitSecureSite = new ExitSecureSite(lssw);
4443
}
4544
this.webAnalytics = webAnalytics;

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-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");

gocwebtemplate-sample-spring/src/main/resources/samples/LeavingSecureSiteSample.html

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ <h2>Leaving Secure Site Warning</h2>
2020
<ul>
2121
<li>display the message to the user in the form of a modal window</li>
2222
<li>display the message your application provides</li>
23-
<li>allow your application to execute any clean up code (ex: close session, gracefully logout user etc...)</li>
24-
<li>allow your application to exlude any domains from raising the warning</li>
23+
<li>allow your application to exlude any domains from raising the warning</li>
24+
<li>optionally, allow your application to execute any clean up code (ex: close session, gracefully logout user etc...)</li>
2525
</ul>
2626
<h2>How it works</h2>
2727
<ul>
@@ -32,16 +32,11 @@ <h2>How it works</h2>
3232
<li>A "Yes" button appears on the window to allow the user to continue with the redirection to the selected link.</li>
3333
</ul>
3434
</li>
35-
<li>if the "Yes" button is clicked:
36-
<ul>
37-
<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>
38-
<li>the info of the linked that was clicked is part of the querystring to that url</li>
39-
<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>
40-
<li>execute any clean up code your application requires</li>
41-
<li>once executed the custom method will redirect the user to the url of the clicked link</li>
42-
<li>the leave secure site feature is already provided by default as part of the GoC Web Template package</li>
43-
<li>by default the leave secure site redirect url will invoke the <code class="wb-prettify">LeaveSecureSiteRedirect</code> method found in the controller.</li>
44-
</ul>
35+
<li>if the "Yes" button is clicked, the browser will be directed to the external link</li>
36+
<li>optionally, a redirect url can be set in <code class="wb-prettify">"leavingSecureSiteRedirectUrl"</code> via either the cdn.properties file or programmatically.
37+
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.
38+
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.
39+
An example of "middle page" is available in the <a href="https://wet-boew.github.io/wet-boew/docs/ref/exitscript/exiturl-en.html?exturl=http%3A%2F%2Fcsszengarden.com%2F219">WET Documentation</a>.
4540
</li>
4641
</ul>
4742
<p>Here is a local link that will not display the warning: <a href="BaseSettingsSample">Link to Local Page</a></p>
@@ -51,7 +46,6 @@ <h3>Enable the leaving secure site feature</h3>
5146
<ul>
5247
<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>
5348
<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>
54-
<li>Set, via the cdn.properties file or programmatically in your custom bean class, <code class="wb-prettify">"RedirectUrl"</code> to your page which will execute your clean up code and then redirect to the selected url.</li>
5549
<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>
5650
</ul>
5751
<div class="wb-prettify all-pre lang-vb linenums">
@@ -63,7 +57,6 @@ <h3>Enable the leaving secure site feature</h3>
6357

6458
lssw.setEnabled(true);
6559
lssw.setMessage("You are about to leave a secure site, do you wish to continue?");
66-
lssw.setRedirectUrl("gocwebtemplate_leavesecuresiteredirect");
6760
lssw.setExcludedDomains("www.esdc.gc.ca,www.jobbank.gc.ca,www.readseal.ca");
6861
lssw.setCancelMessage("Don't leave");
6962
lssw.setYesMessage("Yes, leave this site");
@@ -74,20 +67,6 @@ <h3>Enable the leaving secure site feature</h3>
7467
}
7568
</pre>
7669
</div>
77-
<h3>Map your "redirect" url in the controller</h3>
78-
<ul>
79-
<li>The relative url <code class="wb-prettify">/gocwebtemplate_leavesecuresiteredirect</code> will map to the method that can be used to perform the redirect.</li>
80-
</ul>
81-
<div class="wb-prettify all-pre lang-vb linenums">
82-
<h4>Code Sample for your Redirect Controller method</h4>
83-
<pre>
84-
@GetMapping("/gocwebtemplate_leavesecuresiteredirect")
85-
public void LeaveSecureSiteRedirect(HttpServletRequest request, HttpServletResponse response) throws Exception {
86-
//Custom processing would go here
87-
BaseUtil.doLeaveSecureSite(request, response);
88-
}
89-
</pre>
90-
</div>
9170
<div th:replace="_samplelist :: samplelist"></div>
9271
</section>
9372
</body>

0 commit comments

Comments
 (0)