All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.voovan.tools.compiler.sandbox.SandboxControler Maven / Gradle / Ivy
package org.voovan.tools.compiler.sandbox;
import org.voovan.tools.TObject;
import org.voovan.tools.TProperties;
import java.util.ArrayList;
import java.util.List;
/**
* 沙盒控制对象
*
* @author: helyho
* Voovan Framework.
* WebSite: https://github.com/helyho/Voovan
* Licence: Apache v2 License
*/
public class SandboxControler {
private List forbiddenClasses; //null 全部允许访问, size=0为全部禁止
private List network; //null 全部允许访问, size=0为全部禁止
private List file; //null 全部允许访问, size=0为全部禁止
private List packageAccess; //null 全部允许访问, size=0为全部禁止
private List packageDefintion; //null 全部允许访问, size=0为全部禁止
private boolean thread;
private boolean link;
private boolean properties;
private boolean printJob;
private boolean exec;
private boolean exit;
private boolean factory;
private boolean securityAccess;
private boolean createClassLoader;
public SandboxControler(){
network = null;
file = null;
packageAccess = null;
packageDefintion = null;
thread = true;
link = true;
properties = true;
printJob= true;
exec = true;
exit = true;
securityAccess = true;
createClassLoader = true;
loadConfig();
}
/**
* 从配置文件读取配置信息
*/
public void loadConfig(){
this.forbiddenClasses = setControlField(ControlType.LIST, TProperties.getString("sandbox", "forbiddenClasses"));
this.network = setControlField(ControlType.LIST, TProperties.getString("sandbox", "network"));
this.file = setControlField(ControlType.LIST, TProperties.getString("sandbox", "file"));
this.packageAccess = setControlField(ControlType.LIST, TProperties.getString("sandbox", "packageAccess"));
this.packageDefintion = setControlField(ControlType.LIST, TProperties.getString("sandbox", "packageDefintion"));
this.thread = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "thread"));
this.link = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "link"));
this.properties = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "properties"));
this.printJob = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "printJob"));
this.exec = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "exec"));
this.exit = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "exit"));
this.factory = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "factory"));
this.securityAccess = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "securityAccess"));
this.createClassLoader = setControlField(ControlType.BOOLEAN, TProperties.getString("sandbox", "createClassLoader"));
}
/**
* 配置控制类型美居
*/
public enum ControlType{
LIST, BOOLEAN
}
/**
* 设置控制参数
* @param controlType 控制类型
* @param value 文本数据
* @param 范型
* @return 配置参数值
*/
private T setControlField(ControlType controlType, String value){
Object result = null;
if(value == null){
if(controlType == ControlType.LIST){
result = null;
}else if(controlType == ControlType.BOOLEAN){
result = true;
}
} else if(value.equals("ALL_ALLOW")){
if(controlType == ControlType.LIST){
result = null;
}else if(controlType == ControlType.BOOLEAN){
result = true;
}
} else if(value.equals("ALL_DENY")){
if(controlType == ControlType.LIST){
result = new ArrayList();
}else if(controlType == ControlType.BOOLEAN){
result = false;
}
} else {
if(controlType == ControlType.LIST){
result = TObject.asList(value.split(","));
}
}
return (T)result;
}
public List getForbiddenClasses() {
return forbiddenClasses;
}
public void setForbiddenClasses(List forbiddenClasses) {
this.forbiddenClasses = forbiddenClasses;
}
public List getNetwork() {
return network;
}
public void setNetwork(List network) {
this.network = network;
}
public List getFile() {
return file;
}
public void setFile(List file) {
this.file = file;
}
public boolean isThread() {
return thread;
}
public void setThread(boolean thread) {
this.thread = thread;
}
public boolean isLink() {
return link;
}
public void setLink(boolean link) {
this.link = link;
}
public boolean isProperties() {
return properties;
}
public void setProperties(boolean properties) {
this.properties = properties;
}
public boolean isPrintJob() {
return printJob;
}
public void setPrintJob(boolean printJob) {
this.printJob = printJob;
}
public boolean isExec() {
return exec;
}
public void setExec(boolean exec) {
this.exec = exec;
}
public boolean isExit() {
return exit;
}
public void setExit(boolean exit) {
this.exit = exit;
}
public boolean isFactory() {
return factory;
}
public void setFactory(boolean factory) {
this.factory = factory;
}
public boolean isSecurityAccess() {
return securityAccess;
}
public void setSecurityAccess(boolean securityAccess) {
this.securityAccess = securityAccess;
}
public boolean isCreateClassLoader() {
return createClassLoader;
}
public void setCreateClassLoader(boolean createClassLoader) {
this.createClassLoader = createClassLoader;
}
public List getPackageAccess() {
return packageAccess;
}
public void setPackageAccess(List packageAccess) {
this.packageAccess = packageAccess;
}
public List getPackageDefintion() {
return packageDefintion;
}
public void setPackageDefintion(List packageDefintion) {
this.packageDefintion = packageDefintion;
}
}