I would like to implement validation of training projects i.e. the teacher writes the assignment and check, the student completes the assignment, the student loads the java file (s), the system checks the assignments.
At the moment, the only solution that I see is: – Using Junit for tests – Compiling the provided student classes and loading them through their own classloader implementation with the rights set in the SecurityManager
- What is the best way to implement this in java. Are there any similar projects already?
- Do I understand correctly that with the help of the SecurityManager I can fully control the student's implementation (that the student will not get into the file system, the network, start the application execution and not get into the implemented code (do I also need to separate the regular classloader from the one I implement) )?
- I'm not familiar with docker, but as I understand it, it allows you to run isolated applications without eating away unnecessary resources, wouldn't it be a better solution than SecurityManager + classloader?
As a basis, I would do this:
- The student receives a .java file with an assignment template
- The junit test is already ready for this task.
- The student loads the completed tasks into any drop zone
- The program that checks the task, lifts the Docker container with java, connects to it via ssl, compiles this task there using javac, runs JUnit tests and writes a log
- The student receives a processed log
You can build all this using Spring Boot.
Docker is, in my opinion, the best option as it has all the benefits of a virtual machine without being one. For example, you can use this container: https://hub.docker.com/r/library/java/
If using docker causes problems, you can raise a virtual machine using Vagrant, download an image of some Ubuntu with OpenJDK, connect there via SSL and do everything the same as with docker.
Alternatively, you can still try to compile the code right in runtime: https://dzone.com/articles/how-to-compile-a-class-at-runtime-with-java-8-and But then you will definitely have to touch the SecurityManager …