简体   繁体   English

如何在Java中阻止读写和连接操作

[英]How to block read write and connect operation in Java

We are building online grader, a system which accepts some java code, runs it, gets results and verify that results are correct. 我们正在构建在线评分器,它是一个接受一些Java代码,运行它,获取结果并验证结果正确的系统。

Obviously, running untrusted code is unsafe, so we need to make sure code submitter does not break/compromise whole grader system. 显然,运行不受信任的代码是不安全的,因此我们需要确保代码提交者不会破坏/损害整个评分系统。

For example such sumbitter could read passwords and modify grading entry in database. 例如,这样的求位者可以读取密码并修改数据库中的评分条目。 Or even worse, it could fill out the whole file system, RAM or consume all threads and prevent grading for other submitters. 甚至更糟的是,它可能会填满整个文件系统,RAM或消耗所有线程,并妨碍其他提交者的评分。

Is there any API that allows me to block read write and connect operation. 是否有任何API允许我阻止读写和连接操作。

使用内置的安全管理器功能。

SecurityManager solved this issues. SecurityManager解决了此问题。

class MySecurityManager extends SecurityManager {
@Override
public void checkRead(FileDescriptor fd) {
    throw new SecurityException("File reading is not allowed");
}

@Override
public void checkWrite(FileDescriptor fd) {
    throw new SecurityException("File writing is not allowed");
}

@Override
public void checkConnect(String host, int port) {
    throw new SecurityException("Socket connections are not allowed");
  }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM