From 536233d015a2c0e3d2406c071a91f7d30d7077bf Mon Sep 17 00:00:00 2001 From: sarps Date: Tue, 26 Nov 2024 23:46:19 +0100 Subject: [PATCH] Change file constant names --- .../java/FileHandlerConstants.java | 14 ++++++------ .../JavaArchUnitSecurityTestCase.java | 18 +++++++-------- ...va => JavaArchUnitTestCaseCollection.java} | 22 +++++++++---------- .../JavaWalaSecurityTestCaseCollection.java | 4 ++-- 4 files changed, 29 insertions(+), 29 deletions(-) rename src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/{JavaArchitectureTestCaseCollection.java => JavaArchUnitTestCaseCollection.java} (87%) diff --git a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/FileHandlerConstants.java b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/FileHandlerConstants.java index 9974342..db62f88 100644 --- a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/FileHandlerConstants.java +++ b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/FileHandlerConstants.java @@ -14,13 +14,13 @@ public class FileHandlerConstants { // - public static final Path JAVA_FILESYSTEM_INTERACTION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "file-system-access-methods.txt"); - public static final Path JAVA_NETWORK_ACCESS_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "network-access-methods.txt"); - public static final Path JAVA_JVM_TERMINATION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "jvm-termination-methods.txt"); - public static final Path JAVA_REFLECTION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "reflection-methods.txt"); - public static final Path JAVA_COMMAND_EXECUTION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "command-execution-methods.txt"); - public static final Path JAVA_THREAD_MANIPULATION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "thread-manipulation-methods.txt"); - public static final Path JAVA_SERIALIZATION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "serializable-methods.txt"); + public static final Path ARCHUNIT_FILESYSTEM_INTERACTION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "file-system-access-methods.txt"); + public static final Path ARCHUNIT_NETWORK_ACCESS_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "network-access-methods.txt"); + public static final Path ARCHUNIT_JVM_TERMINATION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "jvm-termination-methods.txt"); + public static final Path ARCHUNIT_REFLECTION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "reflection-methods.txt"); + public static final Path ARCHUNIT_COMMAND_EXECUTION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "command-execution-methods.txt"); + public static final Path ARCHUNIT_THREAD_MANIPULATION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "thread-manipulation-methods.txt"); + public static final Path ARCHUNIT_SERIALIZATION_METHODS = FileTools.resolveOnResources("templates", "architecture" , "java", "archunit", "methods", "serializable-methods.txt"); // // diff --git a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchUnitSecurityTestCase.java b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchUnitSecurityTestCase.java index b6ca9e8..4950e19 100644 --- a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchUnitSecurityTestCase.java +++ b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchUnitSecurityTestCase.java @@ -12,7 +12,7 @@ import java.util.stream.Collectors; import static de.tum.cit.ase.ares.api.architecture.java.JavaArchitectureTestCase.parseErrorMessage; -import static de.tum.cit.ase.ares.api.architecture.java.archunit.JavaArchitectureTestCaseCollection.getArchitectureRuleFileContent; +import static de.tum.cit.ase.ares.api.architecture.java.archunit.JavaArchUnitTestCaseCollection.getArchitectureRuleFileContent; import static de.tum.cit.ase.ares.api.localization.Messages.localized; // @@ -78,35 +78,35 @@ public void executeArchitectureTestCase(JavaClasses javaClasses) { try { switch (this.javaArchitectureTestCaseSupported) { case FILESYSTEM_INTERACTION -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .NO_CLASS_SHOULD_ACCESS_FILE_SYSTEM .check(javaClasses); case NETWORK_CONNECTION -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .NO_CLASSES_SHOULD_ACCESS_NETWORK .check(javaClasses); case THREAD_CREATION -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .NO_CLASSES_SHOULD_CREATE_THREADS .check(javaClasses); case COMMAND_EXECUTION -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .NO_CLASSES_SHOULD_EXECUTE_COMMANDS .check(javaClasses); case PACKAGE_IMPORT -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .noClassesShouldImportForbiddenPackages(allowedPackages) .check(javaClasses); case REFLECTION -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .NO_CLASSES_SHOULD_USE_REFLECTION .check(javaClasses); case TERMINATE_JVM -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .NO_CLASSES_SHOULD_TERMINATE_JVM .check(javaClasses); case SERIALIZATION -> - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .NO_CLASSES_SHOULD_SERIALIZE .check(javaClasses); // Classloading included in the Reflection test case diff --git a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchitectureTestCaseCollection.java b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchUnitTestCaseCollection.java similarity index 87% rename from src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchitectureTestCaseCollection.java rename to src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchUnitTestCaseCollection.java index 1261d26..7b681d9 100644 --- a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchitectureTestCaseCollection.java +++ b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/archunit/JavaArchUnitTestCaseCollection.java @@ -23,11 +23,11 @@ /** * This class runs the security rules on the architecture for the post-compile mode. */ -public class JavaArchitectureTestCaseCollection { +public class JavaArchUnitTestCaseCollection { // - private JavaArchitectureTestCaseCollection() { - throw new IllegalArgumentException("Ares Security Error (Reason: Ares-Code; Stage: Execution): JavaArchitectureTestCaseCollection is a utility class and should not be instantiated."); + private JavaArchUnitTestCaseCollection() { + throw new SecurityException(localize("security.general.utility.initialization", JavaArchUnitTestCaseCollection.class.getName())); } // @@ -41,7 +41,7 @@ public static String getArchitectureRuleFileContent(String key) { "templates", "architecture", "java", "archunit", "rules", key + ".txt"); // Read the file content - try (InputStream sourceStream = JavaArchitectureTestCaseCollection.class.getResourceAsStream("/" + resolvedPath)) { + try (InputStream sourceStream = JavaArchUnitTestCaseCollection.class.getResourceAsStream("/" + resolvedPath)) { if (sourceStream == null) { throw new IOException("Resource not found: " + resolvedPath); } @@ -87,7 +87,7 @@ public boolean test(JavaAccess javaAccess) { */ public static final ArchRule NO_CLASS_SHOULD_ACCESS_FILE_SYSTEM = createNoClassShouldHaveMethodRule( localize("security.architecture.file.system.access"), - FileHandlerConstants.JAVA_FILESYSTEM_INTERACTION_METHODS + FileHandlerConstants.ARCHUNIT_FILESYSTEM_INTERACTION_METHODS ); // @@ -97,21 +97,21 @@ public boolean test(JavaAccess javaAccess) { */ public static final ArchRule NO_CLASSES_SHOULD_ACCESS_NETWORK = createNoClassShouldHaveMethodRule( localize("security.architecture.network.access"), - FileHandlerConstants.JAVA_NETWORK_ACCESS_METHODS + FileHandlerConstants.ARCHUNIT_NETWORK_ACCESS_METHODS ); // // public static final ArchRule NO_CLASSES_SHOULD_CREATE_THREADS = createNoClassShouldHaveMethodRule( localize("security.architecture.manipulate.threads"), - FileHandlerConstants.JAVA_THREAD_MANIPULATION_METHODS + FileHandlerConstants.ARCHUNIT_THREAD_MANIPULATION_METHODS ); // // public static final ArchRule NO_CLASSES_SHOULD_EXECUTE_COMMANDS = createNoClassShouldHaveMethodRule( localize("security.architecture.execute.command"), - FileHandlerConstants.JAVA_COMMAND_EXECUTION_METHODS + FileHandlerConstants.ARCHUNIT_COMMAND_EXECUTION_METHODS ); // @@ -138,7 +138,7 @@ public boolean test(JavaClass javaClass) { */ public static final ArchRule NO_CLASSES_SHOULD_USE_REFLECTION = createNoClassShouldHaveMethodRule( localize("security.architecture.reflection.uses"), - FileHandlerConstants.JAVA_REFLECTION_METHODS + FileHandlerConstants.ARCHUNIT_REFLECTION_METHODS ); // @@ -148,14 +148,14 @@ public boolean test(JavaClass javaClass) { */ public static final ArchRule NO_CLASSES_SHOULD_TERMINATE_JVM = createNoClassShouldHaveMethodRule( localize("security.architecture.terminate.jvm"), - FileHandlerConstants.JAVA_JVM_TERMINATION_METHODS + FileHandlerConstants.ARCHUNIT_JVM_TERMINATION_METHODS ); // // public static final ArchRule NO_CLASSES_SHOULD_SERIALIZE = createNoClassShouldHaveMethodRule( localize("security.architecture.serialize"), - FileHandlerConstants.JAVA_SERIALIZATION_METHODS + FileHandlerConstants.ARCHUNIT_SERIALIZATION_METHODS ); // } \ No newline at end of file diff --git a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCaseCollection.java b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCaseCollection.java index b4ba376..598999b 100644 --- a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCaseCollection.java +++ b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCaseCollection.java @@ -6,7 +6,7 @@ import com.ibm.wala.shrike.shrikeCT.InvalidClassFileException; import com.tngtech.archunit.core.domain.JavaClasses; import de.tum.cit.ase.ares.api.architecture.java.FileHandlerConstants; -import de.tum.cit.ase.ares.api.architecture.java.archunit.JavaArchitectureTestCaseCollection; +import de.tum.cit.ase.ares.api.architecture.java.archunit.JavaArchUnitTestCaseCollection; import java.nio.file.Path; import java.util.List; @@ -125,7 +125,7 @@ public static void noCommandExecution(CallGraph cg) { // public static void restrictPackageImport(JavaClasses javaClasses, Set allowedPackages) { - JavaArchitectureTestCaseCollection + JavaArchUnitTestCaseCollection .noClassesShouldImportForbiddenPackages(allowedPackages) .check(javaClasses); }