Skip to content

Commit fbb0113

Browse files
authored
Merge pull request #176 from NASA-AMMOS/develop
Develop
2 parents d54ed7d + adbfa3b commit fbb0113

File tree

360 files changed

+298228
-4938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+298228
-4938
lines changed

cws-core/src/main/java/jpl/cws/core/db/SchedulerDbService.java

Lines changed: 1596 additions & 1513 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public void doFilter(
7070

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

73+
74+
7375
if (log.isTraceEnabled()) {
7476
log.trace("PATH = " + path);
7577
Enumeration<String> reqHeaderNames = req.getHeaderNames();
@@ -91,6 +93,8 @@ public void doFilter(
9193
}
9294
}
9395

96+
97+
9498
// If skipping resource...
9599
//
96100
if (isSecurityExemptResource(path)) {
@@ -108,6 +112,7 @@ public void doFilter(
108112
// FIXME: add similar logic as above to redirect Camunda login pages..
109113

110114
chain.doFilter(request, resp); // continue onwards with chain
115+
statusOverride(resp, req);
111116
return;
112117
}
113118
else {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public void doFilter(
5858
return;
5959
}
6060

61+
62+
6163
// If skipping resource...
6264
//
6365
if (isSecurityExemptResource(path)) {
@@ -75,6 +77,7 @@ public void doFilter(
7577
// FIXME: add similar logic as above to redirect Camunda login pages..
7678

7779
chain.doFilter(request, resp); // continue onwards with chain
80+
statusOverride(resp, req);
7881
return;
7982
}
8083
else {

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public abstract class CwsSecurityFilter implements javax.servlet.Filter {
4141
private static final Logger log = LoggerFactory.getLogger(CwsSecurityFilter.class);
4242

4343
public static final String CWS_TOKEN_COOKIE_NAME = "cwsToken";
44+
public static final String CWS_USERNAME_COOKIE_NAME = "cwsUsername";
4445

4546
static final String COOKIES_HEADER = "Set-Cookie";
4647

@@ -51,11 +52,19 @@ public abstract class CwsSecurityFilter implements javax.servlet.Filter {
5152
protected AuthorizationService authorizationService;
5253

5354
protected String cwsSecurityScheme;
54-
55+
56+
private String cwsWebPort;
57+
private String cwsSSLPort;
58+
5559
public void init(FilterConfig filterConfig) {
5660
try {
5761
cwsSecurityScheme = filterConfig.getInitParameter("identityPluginType");
62+
cwsWebPort = filterConfig.getInitParameter("cwsWebPort");
63+
cwsSSLPort = filterConfig.getInitParameter("cwsSSLPort");
5864
log.debug("CWS Security scheme is: " + cwsSecurityScheme);
65+
log.debug("CWS cwsWebPort is: " + cwsWebPort);
66+
log.debug("CWS cwsSSLPort is: " + cwsSSLPort);
67+
5968

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

@@ -303,8 +312,18 @@ else if (path.toLowerCase().endsWith("/logout")) {
303312

304313
return false; // DON'T skip
305314
}
306-
307-
315+
316+
// Simple override of http return for redirect code when http request is valid
317+
protected void statusOverride(HttpServletResponse resp, HttpServletRequest req){
318+
if (resp.getStatus() == 200){
319+
resp.setStatus(301);
320+
String newURL = getBaseUrl(req);
321+
newURL = newURL.replaceFirst("http:", "https:");
322+
newURL = newURL.replaceFirst(cwsWebPort, cwsSSLPort);
323+
resp.setHeader("Location", newURL);
324+
}
325+
}
326+
308327
protected void logRequestInfo(HttpServletRequest req) {
309328
// Log all of the headers
310329
Enumeration<String> reqHeaderNames = req.getHeaderNames();
@@ -546,6 +565,7 @@ else if (resourceId.startsWith("process/")) {
546565
protected void setCwsTokenCookie(HttpServletRequest req, HttpServletResponse resp) {
547566
String cwsToken = req.getSession().getId();
548567
WebUtils.addCookie(CWS_TOKEN_COOKIE_NAME, cwsToken, null, "/", resp);
568+
WebUtils.addUnsecureCookie(CWS_USERNAME_COOKIE_NAME, getUsernameFromReq(req), null, "/", resp);
549569
cwsSecurityService.addNewCwsTokenToDb(cwsToken, getUsernameFromReq(req));
550570
//addCwsSessionId(getUsernameFromReq(req), req.getSession().getId());
551571
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jpl.cws.core.web;
22

33
import com.google.gson.GsonBuilder;
4+
import org.apache.commons.lang.StringEscapeUtils;
45

56
public class JsonResponse {
67
public enum Status {
@@ -25,6 +26,8 @@ public String getMessage() {
2526
}
2627

2728
public String toString() {
28-
return new GsonBuilder().setPrettyPrinting().create().toJson(this);
29+
String json = new GsonBuilder().setPrettyPrinting().create().toJson(this);
30+
31+
return StringEscapeUtils.unescapeJava(json);
2932
}
3033
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static RestCallResult restCall(String urlString, String method, String da
7171
*
7272
*/
7373
public static RestCallResult restCall(String urlString, String method, String data, String cookie, String acceptType, String contentType, Boolean allowInsecureRequests, String username, String password) throws Exception {
74-
log.trace("urlString = " + urlString);
74+
log.debug("urlString = " + urlString);
7575
HttpURLConnection connection = null;
7676
try {
7777

@@ -212,6 +212,15 @@ public static void addCookie(String name, String value, String domain, String pa
212212
Cookie cookie = constructCookie(name, value, domain, path);
213213
resp.addCookie(cookie);
214214
}
215+
216+
public static void addUnsecureCookie(String name, String value, String domain, String path, HttpServletResponse resp) {
217+
if (!isValidCookieString(name) || !isValidCookieString(value)) {
218+
throw new IllegalArgumentException("Cookie name and/or value is invalid (contains unacceptable characters)!");
219+
}
220+
Cookie cookie = constructCookie(name, value, domain, path);
221+
cookie.setHttpOnly(false);
222+
resp.addCookie(cookie);
223+
}
215224

216225

217226

0 commit comments

Comments
 (0)