Skip to content

Commit

Permalink
Deepthi M|Trello-332|Updated as per the review comments-Renamed vari…
Browse files Browse the repository at this point in the history
…ables,updated description in config.xml and added spaces after comma.
  • Loading branch information
deepthi-mantena committed Sep 25, 2023
1 parent ef7ff26 commit 35dd26c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ public class RestConstants {
*/
public static final String PRIV_GET_SERVER_LOGS = "Get Server Logs";
/**
* Constants used for the StackTrace Details in error response
* Global property name used to enable or disable the inclusion of stack trace details
* in the error response.
*
* When this property is set to 'true', stack trace details will be included in error
* responses. When set to 'false', stack trace details will be omitted.
*/
public static String ENABLE_STACK_TRACE_DETAILS_GLOBAL_PROPERTY_NAME = MODULE_ID + ".enableStackTraceDetails";
}
Original file line number Diff line number Diff line change
Expand Up @@ -828,13 +828,13 @@ public static SimpleObject wrapErrorResponse(Exception ex, String reason) {
} else {
map.put("message", "[" + message + "]");
}
StackTraceElement[] steElements = ex.getStackTrace();
if (steElements.length > 0) {
StackTraceElement ste = ex.getStackTrace()[0];
String stackTraceDetailsenabled_gp = Context.getAdministrationService()
StackTraceElement[] stackTraceElements = ex.getStackTrace();
if (stackTraceElements.length > 0) {
StackTraceElement stackTraceElement = ex.getStackTrace()[0];
String stackTraceDetailsEnabledGp = Context.getAdministrationService()
.getGlobalPropertyValue(RestConstants.ENABLE_STACK_TRACE_DETAILS_GLOBAL_PROPERTY_NAME, "false");
map.put("code", ste.getClassName() + ":" + ste.getLineNumber());
if ("true".equalsIgnoreCase(stackTraceDetailsenabled_gp)) {
map.put("code", stackTraceElement.getClassName() + ":" + stackTraceElement.getLineNumber());
if ("true".equalsIgnoreCase(stackTraceDetailsEnabledGp)) {
map.put("detail", ExceptionUtils.getStackTrace(ex));
} else {
map.put("detail", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void wrapErrorResponse_shouldSetStackTraceDetailsIfGlobalPropEnabled() th
SimpleObject returnObject = RestUtil.wrapErrorResponse(ex, "wraperrorresponsemessage");

LinkedHashMap errorResponseMap = (LinkedHashMap) returnObject.get("error");
Assert.assertNotEquals("",errorResponseMap.get("detail"));
Assert.assertNotEquals("", errorResponseMap.get("detail"));
}
@Test
public void wrapErrorResponse_shouldSetNoStackTraceDetailsIfGlobalPropDisabled() throws Exception {
Expand All @@ -222,6 +222,6 @@ public void wrapErrorResponse_shouldSetNoStackTraceDetailsIfGlobalPropDisabled()
SimpleObject returnObject = RestUtil.wrapErrorResponse(ex, "wraperrorresponsemessage");

LinkedHashMap errorResponseMap = (LinkedHashMap) returnObject.get("error");
Assert.assertEquals("",errorResponseMap.get("detail"));
Assert.assertEquals("", errorResponseMap.get("detail"));
}
}
2 changes: 1 addition & 1 deletion omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<globalProperty>
<property>@[email protected]</property>
<defaultValue>true</defaultValue>
<description>If the value of this setting is "true",then details of stackTrace would be shown in the error response,However recommendation is to keep it as "false" from Security perspective, to avoid leaking implementation details.</description>
<description>If the value of this setting is "true", then the details of the stackTrace would be shown in the error response. However, the recommendation is to keep it as "false", from the Security perspective, to avoid leaking implementation details.</description>
</globalProperty>

<!-- DWR -->
Expand Down

0 comments on commit 35dd26c

Please sign in to comment.