Skip to content

Commit

Permalink
Feature/ids9941 301 return v3 (#166)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
brentjk and Brent J Knickerbocker authored Aug 2, 2023
1 parent fa8eef4 commit 648e4f6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void doFilter(
// FIXME: add similar logic as above to redirect Camunda login pages..

chain.doFilter(request, resp); // continue onwards with chain
statusOverride(resp);
statusOverride(resp, req);
return;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void doFilter(
// FIXME: add similar logic as above to redirect Camunda login pages..

chain.doFilter(request, resp); // continue onwards with chain
statusOverride(resp);
statusOverride(resp, req);
return;
}
else {
Expand Down
18 changes: 15 additions & 3 deletions cws-core/src/main/java/jpl/cws/core/web/CwsSecurityFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ public abstract class CwsSecurityFilter implements javax.servlet.Filter {
protected AuthorizationService authorizationService;

protected String cwsSecurityScheme;


private String cwsWebPort;
private String cwsSSLPort;

public void init(FilterConfig filterConfig) {
try {
cwsSecurityScheme = filterConfig.getInitParameter("identityPluginType");
cwsWebPort = filterConfig.getInitParameter("cwsWebPort");
cwsSSLPort = filterConfig.getInitParameter("cwsSSLPort");
log.debug("CWS Security scheme is: " + cwsSecurityScheme);
log.debug("CWS cwsWebPort is: " + cwsWebPort);
log.debug("CWS cwsSSLPort is: " + cwsSSLPort);


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

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

// Simple override of http return for redirect code when http request is valid
protected void statusOverride(HttpServletResponse resp){
protected void statusOverride(HttpServletResponse resp, HttpServletRequest req){
if (resp.getStatus() == 200){
resp.setStatus(301);
String newURL = getBaseUrl(req);
newURL = newURL.replaceFirst("http:", "https:");
newURL = newURL.replaceFirst(cwsWebPort, cwsSSLPort);
resp.setHeader("Location", newURL);
}
}

protected void logRequestInfo(HttpServletRequest req) {
// Log all of the headers
Enumeration<String> reqHeaderNames = req.getHeaderNames();
Expand Down
8 changes: 7 additions & 1 deletion cws-installer/src/main/java/jpl/cws/task/CwsInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ private static void setIdentityPluginType() throws UnsupportedOperationException
}
}


private static void setupDatabase() {
cws_db_type = getPreset("database_type");

Expand Down Expand Up @@ -2578,6 +2577,9 @@ private static void updateFiles() throws IOException {
content = content.replace("__CWS_SECURITY_FILTER_CLASS__", cws_security_filter_class);
content = content.replace("__CWS_ADMIN_USERNAME__", cws_user);
content = content.replace("__CWS_TOKEN_EXPIRATION_MINUTES__", Integer.toString(Integer.parseInt(cws_token_expiration_hours) * 60));
content = content.replace("__CWS_WEB_PORT__", cws_tomcat_connector_port);
content = content.replace("__CWS_SSL_PORT__", cws_tomcat_ssl_port);


if (cws_auth_scheme.equals("CAMUNDA")) {
content = content.replace("__CWS_ADMIN_FIRSTNAME__", cws_user_firstname);
Expand Down Expand Up @@ -2608,6 +2610,8 @@ private static void updateFiles() throws IOException {
content = getFileContents(filePath);
content = content.replace("__CWS_IDENTITY_PLUGIN_TYPE__", cws_auth_scheme);
content = content.replace("__CWS_SECURITY_FILTER_CLASS__", cws_security_filter_class);
content = content.replace("__CWS_WEB_PORT__", cws_tomcat_connector_port);
content = content.replace("__CWS_SSL_PORT__", cws_tomcat_ssl_port);

writeToFile(filePath, content);
copy(
Expand All @@ -2620,6 +2624,8 @@ private static void updateFiles() throws IOException {
content = getFileContents(filePath);
content = content.replace("__CWS_IDENTITY_PLUGIN_TYPE__", cws_auth_scheme);
content = content.replace("__CWS_SECURITY_FILTER_CLASS__", cws_security_filter_class);
content = content.replace("__CWS_WEB_PORT__", cws_tomcat_connector_port);
content = content.replace("__CWS_SSL_PORT__", cws_tomcat_ssl_port);
writeToFile(filePath, content);
copy(
Paths.get(config_work_dir + SEP + "engine-rest_mods" + SEP + "web.xml"),
Expand Down
8 changes: 8 additions & 0 deletions install/camunda_mods/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
<param-name>identityPluginType</param-name>
<param-value>__CWS_IDENTITY_PLUGIN_TYPE__</param-value>
</init-param>
<init-param>
<param-name>cwsWebPort</param-name>
<param-value>__CWS_WEB_PORT__</param-value>
</init-param>
<init-param>
<param-name>cwsSSLPort</param-name>
<param-value>__CWS_SSL_PORT__</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CwsSecurityFilter</filter-name>
Expand Down
8 changes: 8 additions & 0 deletions install/tomcat_conf/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@
<param-name>identityPluginType</param-name>
<param-value>__CWS_IDENTITY_PLUGIN_TYPE__</param-value>
</init-param>
<init-param>
<param-name>cwsWebPort</param-name>
<param-value>__CWS_WEB_PORT__</param-value>
</init-param>
<init-param>
<param-name>cwsSSLPort</param-name>
<param-value>__CWS_SSL_PORT__</param-value>
</init-param>
<init-param>
<param-name>adminUserId</param-name>
<param-value>__CWS_ADMIN_USERNAME__</param-value>
Expand Down

0 comments on commit 648e4f6

Please sign in to comment.