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-293077] API Endpoint support for resin #309

Open
wants to merge 4 commits into
base: develop
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
22 changes: 22 additions & 0 deletions instrumentation-security/resin-4/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
dependencies {
implementation(project(":newrelic-security-api"))
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}")
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}")
implementation("javax.servlet:javax.servlet-api:3.0.1")
implementation("com.caucho:resin:4.0.66")
}

jar {
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.resin-4' }
}

verifyInstrumentation {
passes 'com.caucho:resin:[4.0.52,)'
verifyClasspath = false
}

site {
title 'Resin'
type 'Appserver'
versionOverride '[4.0.0,)'
}
2 changes: 2 additions & 0 deletions instrumentation-security/resin-4/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.caucho.server.webapp;

import com.newrelic.api.agent.weaver.Weave;

@Weave
public class WebApp extends ServletContextImpl {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.caucho.server.webapp;

import com.newrelic.agent.security.instrumentation.resin4.HttpServletHelper;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type = MatchType.BaseClass)
public class WebAppContainer {

public WebAppController[] getWebAppList() {
return Weaver.callOriginal();
}

public void start() {
Weaver.callOriginal();
HttpServletHelper.gatherURLMappings(getWebAppList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.newrelic.agent.security.instrumentation.resin4;


import com.caucho.server.webapp.WebAppController;
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.ApplicationURLMapping;
import com.newrelic.api.agent.security.utils.logging.LogLevel;

import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;
import java.util.Collection;
import java.util.Map;

public class HttpServletHelper {
public static final String RESIN_40 = "RESIN-4.0";

private static void gatherURLMappings(ServletContext servletContext) {
try {
Map<String, ? extends ServletRegistration> servletRegistrations = servletContext.getServletRegistrations();
getJSPMappings(servletContext, URLMappingsHelper.SEPARATOR);

for (ServletRegistration servletRegistration : servletRegistrations.values()) {
for (String s : servletRegistration.getMappings()) {
URLMappingsHelper.addApplicationURLMapping(new ApplicationURLMapping(URLMappingsHelper.WILDCARD, s, servletRegistration.getClassName()));
}
}
} catch (Exception e){
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, RESIN_40, e.getMessage()), e, HttpServletHelper.class.getName());
}
}

private static void getJSPMappings(ServletContext servletContext, String dir) {
try {
if(dir.endsWith(URLMappingsHelper.SEPARATOR)){
Collection<String> resourcePaths = servletContext.getResourcePaths(dir);
for (String path : resourcePaths) {
if(path.endsWith(URLMappingsHelper.SEPARATOR)) {
getJSPMappings(servletContext, path);
}
else if(path.endsWith(".jsp") || path.endsWith(".jspx") || path.endsWith(".JSP") || path.endsWith(".JSPX")) {
URLMappingsHelper.addApplicationURLMapping(new ApplicationURLMapping(URLMappingsHelper.WILDCARD, path));
}
}
}
} catch (Exception e){
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, RESIN_40, e.getMessage()), e, HttpServletHelper.class.getName());
}
}

public static void gatherURLMappings(WebAppController[] webAppList) {
if (webAppList == null){
return;
}
for (WebAppController webAppController : webAppList) {
if (webAppController.getWebApp() == null){
continue;
}
gatherURLMappings(webAppController.getWebApp());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ public class URLMappingsHelper {
add("org.apache.catalina.servlets.DefaultServlet");
add("org.eclipse.jetty.servlet.DefaultServlet");
add("grails.plugin.databasemigration.DbdocController");
add("org.apache.cxf.transport.servlet.CXFServlet");
add("javax.faces.webapp.FacesServlet");
add("jakarta.faces.webapp.FacesServlet");
add("weblogic.servlet.JSPServlet");
add("weblogic.servlet.FileServlet");
add("weblogic.management.rest.JerseyServlet");
add("com.caucho.jsp.XtpServlet");
add("com.caucho.jsp.JspServlet");
add("com.caucho.xtpdoc.ResinDocServlet");
add("com.caucho.quercus.servlet.QuercusServlet");
add("com.caucho.servlets.FileServlet");
add("com.caucho.doc.JavadocRedirectServlet");
add("com.caucho.xtpdoc.ReferenceServlet");
add("com.caucho.doc.ViewFileServlet");
}};

public static Set<ApplicationURLMapping> getApplicationURLMappings() {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ include 'instrumentation:weblogic-12.2'
include 'instrumentation:jedis-4.0.0'
include 'instrumentation:jedis-3.0.0'
include 'instrumentation:jedis-2.7.1_2.7.2'
include 'instrumentation:resin-4'
Loading