Skip to content

Commit 648e4f6

Browse files
brentjkBrent J Knickerbocker
andauthored
Feature/ids9941 301 return v3 (#166)
* changes to add redirect header; not yet tested * has header change. but port is not dynamic. hard codded * grabs ports from filter config. updates filter config during installation program * now will fully install the config setting into the filter --------- Co-authored-by: Brent J Knickerbocker <[email protected]>
1 parent fa8eef4 commit 648e4f6

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

cws-core/src/main/java/jpl/cws/core/web/CwsCamundaSecurityFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void doFilter(
112112
// FIXME: add similar logic as above to redirect Camunda login pages..
113113

114114
chain.doFilter(request, resp); // continue onwards with chain
115-
statusOverride(resp);
115+
statusOverride(resp, req);
116116
return;
117117
}
118118
else {

cws-core/src/main/java/jpl/cws/core/web/CwsLdapSecurityFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void doFilter(
7777
// FIXME: add similar logic as above to redirect Camunda login pages..
7878

7979
chain.doFilter(request, resp); // continue onwards with chain
80-
statusOverride(resp);
80+
statusOverride(resp, req);
8181
return;
8282
}
8383
else {

cws-core/src/main/java/jpl/cws/core/web/CwsSecurityFilter.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,19 @@ public abstract class CwsSecurityFilter implements javax.servlet.Filter {
5151
protected AuthorizationService authorizationService;
5252

5353
protected String cwsSecurityScheme;
54-
54+
55+
private String cwsWebPort;
56+
private String cwsSSLPort;
57+
5558
public void init(FilterConfig filterConfig) {
5659
try {
5760
cwsSecurityScheme = filterConfig.getInitParameter("identityPluginType");
61+
cwsWebPort = filterConfig.getInitParameter("cwsWebPort");
62+
cwsSSLPort = filterConfig.getInitParameter("cwsSSLPort");
5863
log.debug("CWS Security scheme is: " + cwsSecurityScheme);
64+
log.debug("CWS cwsWebPort is: " + cwsWebPort);
65+
log.debug("CWS cwsSSLPort is: " + cwsSSLPort);
66+
5967

6068
this.contextPath = filterConfig.getServletContext().getContextPath();
6169

@@ -305,12 +313,16 @@ else if (path.toLowerCase().endsWith("/logout")) {
305313
}
306314

307315
// Simple override of http return for redirect code when http request is valid
308-
protected void statusOverride(HttpServletResponse resp){
316+
protected void statusOverride(HttpServletResponse resp, HttpServletRequest req){
309317
if (resp.getStatus() == 200){
310318
resp.setStatus(301);
319+
String newURL = getBaseUrl(req);
320+
newURL = newURL.replaceFirst("http:", "https:");
321+
newURL = newURL.replaceFirst(cwsWebPort, cwsSSLPort);
322+
resp.setHeader("Location", newURL);
311323
}
312324
}
313-
325+
314326
protected void logRequestInfo(HttpServletRequest req) {
315327
// Log all of the headers
316328
Enumeration<String> reqHeaderNames = req.getHeaderNames();

cws-installer/src/main/java/jpl/cws/task/CwsInstaller.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,6 @@ private static void setIdentityPluginType() throws UnsupportedOperationException
634634
}
635635
}
636636

637-
638637
private static void setupDatabase() {
639638
cws_db_type = getPreset("database_type");
640639

@@ -2578,6 +2577,9 @@ private static void updateFiles() throws IOException {
25782577
content = content.replace("__CWS_SECURITY_FILTER_CLASS__", cws_security_filter_class);
25792578
content = content.replace("__CWS_ADMIN_USERNAME__", cws_user);
25802579
content = content.replace("__CWS_TOKEN_EXPIRATION_MINUTES__", Integer.toString(Integer.parseInt(cws_token_expiration_hours) * 60));
2580+
content = content.replace("__CWS_WEB_PORT__", cws_tomcat_connector_port);
2581+
content = content.replace("__CWS_SSL_PORT__", cws_tomcat_ssl_port);
2582+
25812583

25822584
if (cws_auth_scheme.equals("CAMUNDA")) {
25832585
content = content.replace("__CWS_ADMIN_FIRSTNAME__", cws_user_firstname);
@@ -2608,6 +2610,8 @@ private static void updateFiles() throws IOException {
26082610
content = getFileContents(filePath);
26092611
content = content.replace("__CWS_IDENTITY_PLUGIN_TYPE__", cws_auth_scheme);
26102612
content = content.replace("__CWS_SECURITY_FILTER_CLASS__", cws_security_filter_class);
2613+
content = content.replace("__CWS_WEB_PORT__", cws_tomcat_connector_port);
2614+
content = content.replace("__CWS_SSL_PORT__", cws_tomcat_ssl_port);
26112615

26122616
writeToFile(filePath, content);
26132617
copy(
@@ -2620,6 +2624,8 @@ private static void updateFiles() throws IOException {
26202624
content = getFileContents(filePath);
26212625
content = content.replace("__CWS_IDENTITY_PLUGIN_TYPE__", cws_auth_scheme);
26222626
content = content.replace("__CWS_SECURITY_FILTER_CLASS__", cws_security_filter_class);
2627+
content = content.replace("__CWS_WEB_PORT__", cws_tomcat_connector_port);
2628+
content = content.replace("__CWS_SSL_PORT__", cws_tomcat_ssl_port);
26232629
writeToFile(filePath, content);
26242630
copy(
26252631
Paths.get(config_work_dir + SEP + "engine-rest_mods" + SEP + "web.xml"),

install/camunda_mods/web.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
<param-name>identityPluginType</param-name>
4949
<param-value>__CWS_IDENTITY_PLUGIN_TYPE__</param-value>
5050
</init-param>
51+
<init-param>
52+
<param-name>cwsWebPort</param-name>
53+
<param-value>__CWS_WEB_PORT__</param-value>
54+
</init-param>
55+
<init-param>
56+
<param-name>cwsSSLPort</param-name>
57+
<param-value>__CWS_SSL_PORT__</param-value>
58+
</init-param>
5159
</filter>
5260
<filter-mapping>
5361
<filter-name>CwsSecurityFilter</filter-name>

install/tomcat_conf/web.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@
474474
<param-name>identityPluginType</param-name>
475475
<param-value>__CWS_IDENTITY_PLUGIN_TYPE__</param-value>
476476
</init-param>
477+
<init-param>
478+
<param-name>cwsWebPort</param-name>
479+
<param-value>__CWS_WEB_PORT__</param-value>
480+
</init-param>
481+
<init-param>
482+
<param-name>cwsSSLPort</param-name>
483+
<param-value>__CWS_SSL_PORT__</param-value>
484+
</init-param>
477485
<init-param>
478486
<param-name>adminUserId</param-name>
479487
<param-value>__CWS_ADMIN_USERNAME__</param-value>

0 commit comments

Comments
 (0)