Skip to content

Commit

Permalink
Merge pull request #325 from newrelic/fix/api-endpoint/jsp-NR-233199
Browse files Browse the repository at this point in the history
[NR-303615]: Fix for API Endpoint reported giving 404 error code
  • Loading branch information
IshikaDawda authored Sep 20, 2024
2 parents 4ffd609 + 1851f70 commit ef922cb
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;

import jakarta.servlet.ServletContext;
Expand Down Expand Up @@ -37,6 +38,10 @@ private static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if (StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;

import javax.servlet.ServletContext;
Expand Down Expand Up @@ -36,6 +37,10 @@ private static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if (StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.HttpRequest;
import com.newrelic.api.agent.security.schema.SecurityMetaData;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityException;
import com.newrelic.api.agent.security.schema.operation.RXSSOperation;
import com.newrelic.api.agent.security.schema.policy.AgentPolicy;
Expand Down Expand Up @@ -224,6 +225,10 @@ private static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if (StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.HttpRequest;
import com.newrelic.api.agent.security.schema.SecurityMetaData;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.schema.exceptions.NewRelicSecurityException;
import com.newrelic.api.agent.security.schema.operation.RXSSOperation;
import com.newrelic.api.agent.security.schema.policy.AgentPolicy;
Expand Down Expand Up @@ -226,6 +227,10 @@ private static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if (StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.newrelic.api.agent.security.schema.AgentMetaData;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.HttpRequest;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.schema.policy.AgentPolicy;
import com.newrelic.api.agent.security.utils.logging.LogLevel;

Expand All @@ -13,7 +14,6 @@
import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;

public class HttpServletHelper {
Expand Down Expand Up @@ -142,6 +142,10 @@ public static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if ( StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;

import javax.servlet.ServletContext;
Expand Down Expand Up @@ -36,6 +37,10 @@ public static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if ( StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.newrelic.api.agent.security.schema.AgentMetaData;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.HttpRequest;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.schema.policy.AgentPolicy;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import jakarta.servlet.ServletContext;
Expand Down Expand Up @@ -142,6 +143,10 @@ public static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if ( StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.newrelic.api.agent.security.schema.AgentMetaData;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.HttpRequest;
import com.newrelic.api.agent.security.schema.StringUtils;
import com.newrelic.api.agent.security.schema.policy.AgentPolicy;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import jakarta.servlet.ServletContext;
Expand Down Expand Up @@ -142,6 +143,10 @@ public static void getJSPMappings(ServletContext servletContext, String dir) {
if(dir.endsWith(SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
String entry = StringUtils.removeStart(StringUtils.removeEnd(path, SEPARATOR), StringUtils.SEPARATOR);
if ( StringUtils.equalsAny(entry, "META-INF", "WEB-INF")) {
continue;
}
if(path.endsWith(SEPARATOR)) {
getJSPMappings(servletContext, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,5 +1381,68 @@ public static boolean endsWithAny(final CharSequence sequence, final CharSequenc
return false;
}

/**
* Removes a char only if it is at the beginning of a source string,
* otherwise returns the source string.
*
* <p>A {@code null} source string will return {@code null}.
* An empty ("") source string will return the empty string.
* A {@code null} search char will return the source string.</p>
*
* <pre>
* StringUtils.removeStart(null, *) = null
* StringUtils.removeStart("", *) = ""
* StringUtils.removeStart(*, null) = *
* StringUtils.removeStart("/path", '/') = "path"
* StringUtils.removeStart("path", '/') = "path"
* StringUtils.removeStart("path", 0) = "path"
* </pre>
*
* @param str the source String to search, may be null.
* @param remove the char to search for and remove.
* @return the substring with the char removed if found,
* {@code null} if null String input.
* @since 3.13.0
*/
public static String removeStart(final String str, final char remove) {
if (isEmpty(str)) {
return str;
}
return str.charAt(0) == remove ? str.substring(1) : str;
}

/**
* Removes a substring only if it is at the beginning of a source string,
* otherwise returns the source string.
*
* <p>A {@code null} source string will return {@code null}.
* An empty ("") source string will return the empty string.
* A {@code null} search string will return the source string.</p>
*
* <pre>
* StringUtils.removeStart(null, *) = null
* StringUtils.removeStart("", *) = ""
* StringUtils.removeStart(*, null) = *
* StringUtils.removeStart("www.domain.com", "www.") = "domain.com"
* StringUtils.removeStart("domain.com", "www.") = "domain.com"
* StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
* StringUtils.removeStart("abc", "") = "abc"
* </pre>
*
* @param str the source String to search, may be null
* @param remove the String to search for and remove, may be null
* @return the substring with the string removed if found,
* {@code null} if null String input
* @since 2.1
*/
public static String removeStart(final String str, final String remove) {
if (isEmpty(str) || isEmpty(remove)) {
return str;
}
if (str.startsWith(remove)) {
return str.substring(remove.length());
}
return str;
}

}

0 comments on commit ef922cb

Please sign in to comment.