Skip to content

Commit

Permalink
Merge pull request #340 from newrelic/support/graphql-userclass-NR-31…
Browse files Browse the repository at this point in the history
…9863

NR-319863: User Class detection support for Graphql
  • Loading branch information
IshikaDawda authored Nov 5, 2024
2 parents 60debfe + f126ef0 commit d151dd8
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class JavaxWsRsApi_Instrumentation {
@WeaveIntoAllMethods
public static void preprocessSecurityHook() {
ServletHelper.registerUserLevelCode("jax-rs");
ServletHelper.setFoundAnnotedUserLevelServiceMethod();
ServletHelper.setFoundAnnotatedUserLevelServiceMethod(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public class JavaxWsRsApi_Subresource_Instrumentation {
@WeaveIntoAllMethods
public static void preprocessSecurityHook() {
ServletHelper.registerUserLevelCode("jax-rs");
ServletHelper.setFoundAnnotedUserLevelServiceMethod();
ServletHelper.setFoundAnnotatedUserLevelServiceMethod(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class JakartaWsRsApi_Instrumentation {
@WeaveIntoAllMethods
public static void preprocessSecurityHook() {
ServletHelper.registerUserLevelCode("jax-rs");
ServletHelper.setFoundAnnotedUserLevelServiceMethod();
ServletHelper.setFoundAnnotatedUserLevelServiceMethod(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public class JakartaWsRsApi_Subresource_Instrumentation {
@WeaveIntoAllMethods
public static void preprocessSecurityHook() {
ServletHelper.registerUserLevelCode("jax-rs");
ServletHelper.setFoundAnnotedUserLevelServiceMethod();
ServletHelper.setFoundAnnotatedUserLevelServiceMethod(true);
}
}
4 changes: 3 additions & 1 deletion instrumentation-security/spring-web/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}")
implementation("org.springframework:spring-context:4.3.0.RELEASE")
implementation("org.springframework:spring-web:4.3.0.RELEASE")
implementation("org.springframework.graphql:spring-graphql:1.0.0")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.20")
}

Expand All @@ -19,7 +20,8 @@ jar {
}

verifyInstrumentation {
passesOnly 'org.springframework:spring-web:[0,)'
passes 'org.springframework:spring-web:[0,)'
passes 'org.springframework.graphql:spring-graphql:[0,)'

excludeRegex 'org.springframework:spring-web:.*(RC|SEC|M)[0-9]*$'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/

package com.newrelic.agent.security.instrumentation.springweb;

import com.newrelic.api.agent.security.instrumentation.helpers.ServletHelper;
Expand All @@ -24,11 +17,18 @@ public class SpringController_Instrumentation {
"org.springframework.web.bind.annotation.PutMapping",
"org.springframework.web.bind.annotation.GetMapping",
"org.springframework.web.bind.annotation.PostMapping",
"org.springframework.web.bind.annotation.DeleteMapping"})
"org.springframework.web.bind.annotation.DeleteMapping",
"org.springframework.graphql.data.method.annotation.MutationMapping",
"org.springframework.graphql.data.method.annotation.QueryMapping",
"org.springframework.graphql.data.method.annotation.SchemaMapping",
"org.springframework.graphql.data.method.annotation.SubscriptionMapping",
"org.springframework.graphql.data.method.annotation.BatchMapping"
})
@WeaveIntoAllMethods
private static void requestMapping() {
ServletHelper.setFoundAnnotatedUserLevelServiceMethod(false);
ServletHelper.registerUserLevelCode("spring-annotation");
ServletHelper.setFoundAnnotedUserLevelServiceMethod();
ServletHelper.setFoundAnnotatedUserLevelServiceMethod(true);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.nr.agent.security.instrumentation.springweb.springweb.app;

import com.newrelic.api.agent.Trace;
Expand All @@ -16,7 +10,7 @@ public static String requestMapping() {
TestMappings path = new TestMappings();
return path.testRequest();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -27,7 +21,7 @@ public static String getMapping() {
TestMappings path = new TestMappings();
return path.testGet();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -38,7 +32,7 @@ public static String postMapping() {
TestMappings path = new TestMappings();
return path.testPost();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -49,7 +43,7 @@ public static String patchMapping() {
TestMappings path = new TestMappings();
return path.testPatch();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -60,7 +54,7 @@ public static String putMapping() {
TestMappings path = new TestMappings();
return path.testPut();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -71,7 +65,7 @@ public static String deleteMapping() {
TestMappings path = new TestMappings();
return path.testDelete();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -82,7 +76,7 @@ public static String requestMappingWithRest() {
TestMappingsWithRest path = new TestMappingsWithRest();
return path.testRequest();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -93,7 +87,7 @@ public static String getMappingWithRest() {
TestMappingsWithRest path = new TestMappingsWithRest();
return path.testGet();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -104,7 +98,7 @@ public static String postMappingWithRest() {
TestMappingsWithRest path = new TestMappingsWithRest();
return path.testPost();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -115,7 +109,7 @@ public static String patchMappingWithRest() {
TestMappingsWithRest path = new TestMappingsWithRest();
return path.testPatch();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -126,7 +120,7 @@ public static String putMappingWithRest() {
TestMappingsWithRest path = new TestMappingsWithRest();
return path.testPut();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}
Expand All @@ -137,8 +131,98 @@ public static String deleteMappingWithRest() {
TestMappingsWithRest path = new TestMappingsWithRest();
return path.testDelete();
} catch (RuntimeException caught) {
System.out.printf("Caught exception");
System.out.print("Caught exception");
}
return null;
}

@Trace(dispatcher = true)
public static void batchMappingWithRest() {
try {
new TestMappingsWithRest().testBatchMapping();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void mutationWithRest() {
try {
new TestMappingsWithRest().testMutation();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void queryWithRest() {
try {
new TestMappingsWithRest().testQuery();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void schemaMappingWithRest() {
try {
new TestMappingsWithRest().testSchemaMapping();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void subscriptionMappingWithRest() {
try {
new TestMappingsWithRest().testSubscriptionMapping();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void batchMapping() {
try {
new TestMappings().testBatchMapping();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void mutation() {
try {
new TestMappings().testMutation();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void query() {
try {
new TestMappings().testQuery();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void schemaMapping() {
try {
new TestMappings().testSchemaMapping();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}

@Trace(dispatcher = true)
public static void subscriptionMapping() {
try {
new TestMappings().testSubscriptionMapping();
} catch (RuntimeException caught) {
System.out.print("Caught exception");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.nr.agent.security.instrumentation.springweb.springweb.app;/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.nr.agent.security.instrumentation.springweb.springweb.app;

import org.springframework.graphql.data.method.annotation.BatchMapping;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -46,4 +46,29 @@ public String testPut() {
public String testDelete() {
return "From Delete Mapping";
}

@MutationMapping
public void testMutation() {
// mutation mapping
}

@QueryMapping
public void testQuery() {
// Query mapping
}

@SchemaMapping
public void testSchemaMapping() {
// SchemaMapping
}

@SubscriptionMapping
public void testSubscriptionMapping() {
// SubscriptionMapping
}

@BatchMapping
public void testBatchMapping() {
// BatchMapping
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.nr.agent.security.instrumentation.springweb.springweb.app;/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.nr.agent.security.instrumentation.springweb.springweb.app;

import org.springframework.graphql.data.method.annotation.BatchMapping;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
Expand Down Expand Up @@ -46,4 +46,30 @@ public String testPut() {
public String testDelete() {
return "From Delete RestMapping";
}

@MutationMapping
public void testMutation() {
// mutation mapping
}

@QueryMapping
public void testQuery() {
// Query mapping
}

@SchemaMapping
public void testSchemaMapping() {
// SchemaMapping
}

@SubscriptionMapping
public void testSubscriptionMapping() {
// SubscriptionMapping
}

@BatchMapping
public void testBatchMapping() {
// BatchMapping
}

}
Loading

0 comments on commit d151dd8

Please sign in to comment.