Skip to content

Commit

Permalink
Add Endpoint route in Servlet-3.0 Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
IshikaDawda committed Jun 7, 2024
1 parent 0576b23 commit 3911256
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ private void preprocessSecurityHook(ServletRequest request, ServletResponse resp
securityAgentMetaData.getIps().add(securityRequest.getClientIP());
securityRequest.setClientPort(String.valueOf(httpServletRequest.getRemotePort()));
}
// route detection
securityAgentMetaData.setFramework(Framework.SERVLET);
securityRequest.setRoute(httpServletRequest.getServletPath());

HttpServletHelper.processHttpRequestHeader(httpServletRequest, securityRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ private void preprocessSecurityHook(ServletRequest request, ServletResponse resp
securityAgentMetaData.getIps().add(securityRequest.getClientIP());
securityRequest.setClientPort(String.valueOf(httpServletRequest.getRemotePort()));
}
// route detection
securityAgentMetaData.setFramework(Framework.SERVLET);
securityRequest.setRoute(httpServletRequest.getServletPath());

HttpServletHelper.processHttpRequestHeader(httpServletRequest, securityRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ private void preprocessSecurityHook(ServletRequest_Instrumentation request, Serv
securityAgentMetaData.getIps().add(securityRequest.getClientIP());
securityRequest.setClientPort(String.valueOf(httpServletRequest.getRemotePort()));
}
// route detection
securityAgentMetaData.setFramework(Framework.SERVLET);
securityRequest.setRoute(httpServletRequest.getServletPath());

HttpServletHelper.processHttpRequestHeader(httpServletRequest, securityRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
import com.newrelic.api.agent.security.NewRelicSecurity;
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.AgentMetaData;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.Framework;
import com.newrelic.api.agent.security.schema.HttpRequest;
import com.newrelic.api.agent.security.utils.logging.LogLevel;

import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;
import javax.servlet.http.HttpServletMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.MappingMatch;
import java.util.Collection;
import java.util.Map;

Expand Down Expand Up @@ -48,4 +54,13 @@ else if(path.endsWith(".jsp") || path.endsWith(".jspx") || path.endsWith(".JSP")
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, SERVLET_3_0, e.getMessage()), e, HttpServletHelper.class.getName());
}
}
public static void setRoute(HttpServletRequest request, HttpRequest securityRequest, AgentMetaData metaData){
HttpServletMapping mapping = request.getHttpServletMapping();
if (!mapping.getMappingMatch().equals(MappingMatch.EXTENSION)){
securityRequest.setRoute(mapping.getPattern());
} else {
securityRequest.setRoute(request.getServletPath());
}
metaData.setFramework(Framework.SERVLET);
}
}

0 comments on commit 3911256

Please sign in to comment.