Skip to content

Commit

Permalink
Merge pull request #176 from NASA-AMMOS/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jamesfwood authored Aug 23, 2023
2 parents d54ed7d + adbfa3b commit fbb0113
Show file tree
Hide file tree
Showing 360 changed files with 298,228 additions and 4,938 deletions.
3,109 changes: 1,596 additions & 1,513 deletions cws-core/src/main/java/jpl/cws/core/db/SchedulerDbService.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public void doFilter(

log.trace("doFilter path " + req.getContextPath());



if (log.isTraceEnabled()) {
log.trace("PATH = " + path);
Enumeration<String> reqHeaderNames = req.getHeaderNames();
Expand All @@ -91,6 +93,8 @@ public void doFilter(
}
}



// If skipping resource...
//
if (isSecurityExemptResource(path)) {
Expand All @@ -108,6 +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, req);
return;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public void doFilter(
return;
}



// If skipping resource...
//
if (isSecurityExemptResource(path)) {
Expand All @@ -75,6 +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, req);
return;
}
else {
Expand Down
26 changes: 23 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 @@ -41,6 +41,7 @@ public abstract class CwsSecurityFilter implements javax.servlet.Filter {
private static final Logger log = LoggerFactory.getLogger(CwsSecurityFilter.class);

public static final String CWS_TOKEN_COOKIE_NAME = "cwsToken";
public static final String CWS_USERNAME_COOKIE_NAME = "cwsUsername";

static final String COOKIES_HEADER = "Set-Cookie";

Expand All @@ -51,11 +52,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 @@ -303,8 +312,18 @@ else if (path.toLowerCase().endsWith("/logout")) {

return false; // DON'T skip
}



// Simple override of http return for redirect code when http request is valid
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 Expand Up @@ -546,6 +565,7 @@ else if (resourceId.startsWith("process/")) {
protected void setCwsTokenCookie(HttpServletRequest req, HttpServletResponse resp) {
String cwsToken = req.getSession().getId();
WebUtils.addCookie(CWS_TOKEN_COOKIE_NAME, cwsToken, null, "/", resp);
WebUtils.addUnsecureCookie(CWS_USERNAME_COOKIE_NAME, getUsernameFromReq(req), null, "/", resp);
cwsSecurityService.addNewCwsTokenToDb(cwsToken, getUsernameFromReq(req));
//addCwsSessionId(getUsernameFromReq(req), req.getSession().getId());
}
Expand Down
5 changes: 4 additions & 1 deletion cws-core/src/main/java/jpl/cws/core/web/JsonResponse.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jpl.cws.core.web;

import com.google.gson.GsonBuilder;
import org.apache.commons.lang.StringEscapeUtils;

public class JsonResponse {
public enum Status {
Expand All @@ -25,6 +26,8 @@ public String getMessage() {
}

public String toString() {
return new GsonBuilder().setPrettyPrinting().create().toJson(this);
String json = new GsonBuilder().setPrettyPrinting().create().toJson(this);

return StringEscapeUtils.unescapeJava(json);
}
}
11 changes: 10 additions & 1 deletion cws-core/src/main/java/jpl/cws/core/web/WebUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static RestCallResult restCall(String urlString, String method, String da
*
*/
public static RestCallResult restCall(String urlString, String method, String data, String cookie, String acceptType, String contentType, Boolean allowInsecureRequests, String username, String password) throws Exception {
log.trace("urlString = " + urlString);
log.debug("urlString = " + urlString);
HttpURLConnection connection = null;
try {

Expand Down Expand Up @@ -212,6 +212,15 @@ public static void addCookie(String name, String value, String domain, String pa
Cookie cookie = constructCookie(name, value, domain, path);
resp.addCookie(cookie);
}

public static void addUnsecureCookie(String name, String value, String domain, String path, HttpServletResponse resp) {
if (!isValidCookieString(name) || !isValidCookieString(value)) {
throw new IllegalArgumentException("Cookie name and/or value is invalid (contains unacceptable characters)!");
}
Cookie cookie = constructCookie(name, value, domain, path);
cookie.setHttpOnly(false);
resp.addCookie(cookie);
}



Expand Down
Loading

0 comments on commit fbb0113

Please sign in to comment.