}
// Ok, we need to figure out who our robot is.
Thread c = Thread.currentThread();
IHostedThread robotProxy = threadManager.getLoadedOrLoadingRobotProxy(c);
if (robotProxy == null) {
Logger.logError("Preventing unknown thread " + Thread.currentThread().getName() + " from access: " + perm);
return false;
}
// Attempt to stop the window from displaying
if (perm instanceof java.awt.AWTPermission) {
final String message = "Preventing " + robotProxy.getStatics().getName() + " from access: " + perm;
robotProxy.punishSecurityViolation(message);
// this is hack, because security exception is not enough
throw new ThreadDeath();
}
// FilePermission access request.
if (perm instanceof FilePermission) {
FilePermission filePermission = (FilePermission) perm;
// Get the fileSystemManager
RobotFileSystemManager fileSystemManager = robotProxy.getRobotFileSystemManager();
// Robot wants access to read something
if (filePermission.getActions().equals("read")) {
return impliesRobotFileRead(robotProxy, fileSystemManager, filePermission);
} // Robot wants access to write something
else if (filePermission.getActions().equals("write")) {
return impliesRobotFileWrite(robotProxy, fileSystemManager, filePermission);
} // Robot wants access to write something
else if (filePermission.getActions().equals("delete")) {
return impliesRobotFileDelete(robotProxy, fileSystemManager, filePermission);
}
}
// check package access
if (perm instanceof RuntimePermission && name.startsWith("accessClassInPackage.")) {
return impliesRobotPackageAccess(robotProxy, name.substring(21));
}
// Permission denied.
final String message = "Preventing " + robotProxy.getStatics().getName() + " from access: " + perm;
robotProxy.punishSecurityViolation(message);
return false;
}