Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NR-340947 : Do not collect API Endpoints if Security Agent is disabled #358

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class StrutsHelper {

public static void gatherURLMappings(RuntimeConfiguration runtimeConfig) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, Map<String, ActionConfig>> namespaces = runtimeConfig.getActionConfigs();
for (Map.Entry<String, Map<String, ActionConfig>> namespace : namespaces.entrySet()) {
String url = namespace.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class HttpServletHelper {

public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class HttpServletHelper {

public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.agent.security.instrumentation.apache.wicket6;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;

Expand All @@ -13,6 +14,9 @@ public class WicketHelper {

public static void getMappings(String path, String handler, boolean isPackageMapper) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
String finalPath = path + (isPackageMapper ? SEPARATOR + WILDCARD : "");
URLMappingsHelper.addApplicationURLMapping(new ApplicationURLMapping(WILDCARD, finalPath, handler));
} catch (Exception ignored){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.agent.security.instrumentation.apache.wicket7;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;

Expand All @@ -10,6 +11,9 @@ public class WicketHelper {

public static void getMappings(String path, String handler, boolean isPackageMapper) {
try{
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
if(!path.startsWith(SEPARATOR)) {
path = SEPARATOR + path;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.agent.security.instrumentation.apache.wicket8;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;

Expand All @@ -10,6 +11,9 @@ public class WicketHelper {

public static void getMappings(String path, String handler, boolean isPackageMapper) {
try{
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
if(!path.startsWith(SEPARATOR)) {
path = SEPARATOR + path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class CXFHelper {

public static void gatherURLMapping(List<ClassResourceInfo> classResourceInfo) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
for (ClassResourceInfo classResource: classResourceInfo){
resources(classResource.getURITemplate().getValue(), classResource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class GrailsHelper {

public static void gatherUrlMappings(Map<String, String> uri2viewMap, String handler) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
for (String path : uri2viewMap.keySet()) {
URLMappingsHelper.addApplicationURLMapping(new ApplicationURLMapping(WILDCARD, path, handler));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class GrailsHelper {

public static void gatherUrlMappings( Map<String, String> uri2viewMap, String handler) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
for (String path : uri2viewMap.keySet()) {
URLMappingsHelper.addApplicationURLMapping(new ApplicationURLMapping(URLMappingsHelper.WILDCARD, path, handler));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class GrailsHelper {

public static void gatherUrlMappings(Map<String, Method> actions, String handler, String controller) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
String path = StringUtils.prependIfMissing(controller, StringUtils.SEPARATOR);
for (String action : actions.keySet()) {
String finalPath = StringUtils.appendIfMissing(path, StringUtils.SEPARATOR) + action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class BindableService_Instrumentation {
public ServerServiceDefinition bindService() {
ServerServiceDefinition returnValue = Weaver.callOriginal();

if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return returnValue;
}
try {
String handler = this.getClass().getName();
for (ServerMethodDefinition<?, ?> serverMethod : returnValue.getMethods()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class BindableService_Instrumentation {
public ServerServiceDefinition bindService() {
ServerServiceDefinition returnValue = Weaver.callOriginal();

if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return returnValue;
}
try {
String handler = this.getClass().getName();
for (ServerMethodDefinition<?, ?> serverMethod : returnValue.getMethods()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class BindableService_Instrumentation {
public ServerServiceDefinition bindService() {
ServerServiceDefinition returnValue = Weaver.callOriginal();

if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return returnValue;
}
try {
String handler = this.getClass().getName();
for (ServerMethodDefinition<?, ?> serverMethod : returnValue.getMethods()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class JerseyHelper {

public static void gatherUrlMappings(ResourceModel resourceModel) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
List<Resource> resources = resourceModel.getResources();
if(resources != null){
extractMappingsFromResources(resources, EMPTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ public static void postProcessSecurityHook(HttpServletRequest request, HttpServl
}
public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public static void postProcessSecurityHook(HttpServletRequest request, HttpServl
}
public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public static String getNrSecCustomAttribName() {

public static void gatherURLMappings(HttpListener messageSource, List<MessageProcessor> messageProcessors) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
String path = messageSource.getPath();
String handlerClass = null;
for (MessageProcessor processor: messageProcessors){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public static String getNrSecCustomAttribName(String customAttribute) {

public static void gatherURLMappings(HttpListener messageSource, List<MessageProcessor> messageProcessors) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
String path = messageSource.getPath();
String handlerClass = null;
for (MessageProcessor processor: messageProcessors){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public HttpServerRoutes_Instrumentation route( Predicate<? super HttpServerReque
}
private void addURLMapping(Predicate<? super HttpServerRequest> condition, String className){
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
className = StringUtils.substringBefore(className, URLMappingsHelper.SEPARATOR);
ApplicationURLMapping mapping;
if (condition instanceof HttpPredicate){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public HttpServerRoutes_Instrumentation route(Predicate<? super HttpServerReques
}
private void addURLMapping(Predicate<? super HttpServerRequest> condition, String className){
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
className = StringUtils.substringBefore(className, URLMappingsHelper.SEPARATOR);
ApplicationURLMapping mapping;
if (condition instanceof HttpPredicate){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.agent.security.instrumentation.play2_13

import com.newrelic.api.agent.security.NewRelicSecurity
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper
import com.newrelic.api.agent.security.schema.{ApplicationURLMapping, StringUtils}
import com.newrelic.api.agent.weaver.{MatchType, Weave, Weaver}
Expand All @@ -21,6 +22,9 @@ abstract class GeneratedRouter_Instrumentation {
}

private def gatherURLMappings(): Unit = {
if (!NewRelicSecurity.getAgent.isSecurityEnabled) {
return
}
val iterator = documentation.iterator
while (iterator.hasNext) {
val doc = iterator.next
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.agent.security.instrumentation.play24

import com.newrelic.api.agent.security.NewRelicSecurity
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper
import com.newrelic.api.agent.security.schema.{ApplicationURLMapping, StringUtils}
import com.newrelic.api.agent.weaver.{MatchType, Weave, Weaver}
Expand All @@ -19,6 +20,9 @@ abstract class GeneratedRouter_Instrumentation {
}

private def gatherURLMappings(): Unit = {
if (!NewRelicSecurity.getAgent.isSecurityEnabled) {
return
}
val iterator = documentation.iterator
while (iterator.hasNext) {
val doc = iterator.next
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.agent.security.instrumentation.play26

import com.newrelic.api.agent.security.NewRelicSecurity
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper
import com.newrelic.api.agent.security.schema.{ApplicationURLMapping, StringUtils}
import com.newrelic.api.agent.weaver.{MatchType, Weave, Weaver}
Expand All @@ -20,6 +21,9 @@ abstract class GeneratedRouter_Instrumentation {
}

private def gatherURLMappings(): Unit = {
if (!NewRelicSecurity.getAgent.isSecurityEnabled) {
return
}
val iterator = documentation.iterator
while (iterator.hasNext) {
val doc = iterator.next
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
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 com.newrelic.api.agent.security.schema.SecurityMetaData;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import org.jboss.resteasy.core.ResourceInvoker;
import org.jboss.resteasy.core.ResourceLocator;
import org.jboss.resteasy.core.ResourceMethod;
Expand All @@ -22,6 +20,9 @@ public class RestEasyHelper {

public static void gatherUrlMappings(String path, ResourceInvoker invoker) {
try{
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
List<String> subResourceList = Collections.emptyList();
if (NewRelicSecurity.isHookProcessingActive()) {
subResourceList = NewRelicSecurity.getAgent().getSecurityMetaData().getCustomAttribute(RESTEASY_SUB_RESOURCE_LIST, List.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class RestEasyHelper {
private static final String ROUTE_DETECTION_COMPLETED = "ROUTE_DETECTION_COMPLETED";
public static void gatherUrlMappings(String path, ResourceInvoker invoker) {
try{
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
if(invoker instanceof ResourceMethodInvoker) {
ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) invoker;
String handler = methodInvoker.getResourceClass().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class RestEasyHelper {
private static final String ROUTE_DETECTION_COMPLETED = "ROUTE_DETECTION_COMPLETED";
public static void gatherUrlMappings(String path, ResourceInvoker invoker) {
try{
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
if(invoker instanceof ResourceMethodInvoker) {
ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) invoker;
String handler = methodInvoker.getResourceClass().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ private static String getNrSecCustomAttribName() {

public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class HttpServletHelper {
public static final String SERVLET_3_0 = "SERVLET-3.0";
public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;

public class HttpServletHelper {
Expand Down Expand Up @@ -125,6 +124,9 @@ private static String getNrSecCustomAttribName() {

public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ private static String getNrSecCustomAttribName() {

public static void gatherURLMappings(ServletContext servletContext) {
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, SEPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class SpringHelper {
public static final String SPRING_WEBFLUX = "SPRING-WEBFLUX";
public static <T> void gatherURLMappings(T mapping, Method method){
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
RequestMappingInfo mappingInfo = (RequestMappingInfo) mapping;
PatternsRequestCondition patternsCondition = mappingInfo.getPatternsCondition();
if (patternsCondition != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class SpringHelper {
public static final String SPRING_WEBMVC_310 = "SPRING-WEBMVC-3.1.0";
public static <T> void gatherURLMappings(T mapping, Method method){
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
RequestMappingInfo mappingInfo = (RequestMappingInfo) mapping;
PatternsRequestCondition patternsCondition = mappingInfo.getPatternsCondition();
if (patternsCondition != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class SpringHelper {
public static final String SPRING_WEBMVC_530 = "SPRING-WEBMVC-5.3.0";
public static <T> void gatherURLMappings(T mapping, Method method){
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
RequestMappingInfo mappingInfo = (RequestMappingInfo) mapping;
PatternsRequestCondition patternsCondition = mappingInfo.getPatternsCondition();
PathPatternsRequestCondition pathPatternsCondition = mappingInfo.getPathPatternsCondition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class SpringHelper {
public static final String SPRING_WEBMVC_600 = "SPRING-WEBMVC-6.0.0";
public static <T> void gatherURLMappings(T mapping, Method method){
try {
if (!NewRelicSecurity.getAgent().isSecurityEnabled()) {
return;
}
RequestMappingInfo mappingInfo = (RequestMappingInfo) mapping;
PatternsRequestCondition patternsCondition = mappingInfo.getPatternsCondition();
PathPatternsRequestCondition pathPatternsCondition = mappingInfo.getPathPatternsCondition();
Expand Down
Loading
Loading