diff --git a/tools/aegis4j/build.gradle b/tools/aegis4j/build.gradle index 908e4980d0..b70ae385c2 100644 --- a/tools/aegis4j/build.gradle +++ b/tools/aegis4j/build.gradle @@ -42,8 +42,6 @@ compileTestJava.options.encoding = 'UTF-8' javadoc.options.encoding = 'UTF-8' java { - //withJavadocJar() - //withSourcesJar() } test { @@ -83,51 +81,3 @@ shadowJar { tasks.build.dependsOn tasks.shadowJar tasks.test.dependsOn tasks.shadowJar -/* -publishing { - publications { - mavenJava(MavenPublication) { publication -> - project.shadow.component(publication) - artifact sourcesJar - artifact javadocJar - pom { - groupId = 'net.gredler' - name = 'aegis4j' - url = 'https://github.com/gredler/aegis4j' - description = 'A Java agent which disables dangerous rarely-used runtime features.' - licenses { - license { - name = 'The Apache License, Version 2.0' - url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' - } - } - developers { - developer { - id = 'gredler' - name = 'Daniel Gredler' - email = 'daniel.gredler@gmail.com' - } - } - scm { - url = 'https://github.com/gredler/aegis4j' - connection = 'scm:git:git://github.com/gredler/aegis4j.git' - developerConnection = 'scm:git:ssh:git@github.com:gredler/aegis4j.git' - } - } - } - } - repositories { - maven { - url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' - credentials { - username = project.hasProperty('ossrhUsername') ? ossrhUsername : 'unknown' - password = project.hasProperty('ossrhPassword') ? ossrhPassword : 'unknown' - } - } - } -} - -signing { - sign publishing.publications.mavenJava -} -*/ diff --git a/tools/aegis4j/src/main/java/net/gredler/aegis4j/AegisAgent.java b/tools/aegis4j/src/main/java/net/gredler/aegis4j/AegisAgent.java index 48d13b8e91..ff9fbc95eb 100644 --- a/tools/aegis4j/src/main/java/net/gredler/aegis4j/AegisAgent.java +++ b/tools/aegis4j/src/main/java/net/gredler/aegis4j/AegisAgent.java @@ -36,6 +36,14 @@ public final class AegisAgent { */ public static void premain(String args, Instrumentation instr) { instrumentation = instr; + String argsProperty = System.getProperty("aegis4j.additional.args"); + if (argsProperty != null) { + if (args == null || args.trim().isEmpty()) { + args = argsProperty; + } else { + args += ";" + argsProperty; + } + } try { boolean started = false; Properties props = null; diff --git a/tools/aegis4j/src/test/java/net/gredler/aegis4j/AegisAgentSystemPropertyTest.java b/tools/aegis4j/src/test/java/net/gredler/aegis4j/AegisAgentSystemPropertyTest.java new file mode 100644 index 0000000000..2a357c3ed2 --- /dev/null +++ b/tools/aegis4j/src/test/java/net/gredler/aegis4j/AegisAgentSystemPropertyTest.java @@ -0,0 +1,40 @@ +/* Copyright (c) 2022, Daniel Gredler. All rights reserved. */ + +package net.gredler.aegis4j; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests {@link AegisAgent} monitoring via system properties. + */ +public class AegisAgentSystemPropertyTest { + @AfterAll + public static void uninstallAgent() throws Exception { + System.clearProperty("aegis4j.additional.args"); + TestUtils.installAgent("unblock=serialization"); + } + + @Test + public void testSystemPropertyWithNullExistingArgs() throws Exception { + System.setProperty("aegis4j.additional.args", "unblock=jndi,rmi,scripting"); + TestUtils.installAgent(null); + assertEquals("serialization,process,httpserver", System.getProperty("aegis4j.blocked.features")); + } + + @Test + public void testSystemPropertyWithEmptyExistingArgs() throws Exception { + System.setProperty("aegis4j.additional.args", "unblock=jndi,rmi,scripting"); + TestUtils.installAgent(""); + assertEquals("serialization,process,httpserver", System.getProperty("aegis4j.blocked.features")); + } + + @Test + public void testSystemPropertyWithNonEmptyExistingArgs() throws Exception { + System.setProperty("aegis4j.additional.args", "unblock=jndi,rmi,scripting"); + TestUtils.installAgent("path=../resources/main/net/gredler/aegis4j/mods.properties"); + assertEquals("serialization,process,httpserver", System.getProperty("aegis4j.blocked.features")); + } +}