/** * Checks if testing is disabled. * @return true if testing is disabled; false is testing is enabled. */ public static boolean isTestingOff() { return !isTestingOn(); }
public boolean isDebugging() { return RobocodeProperties.isDebuggingOn(); }
@Override public boolean implies(ProtectionDomain domain, final Permission permission) { if (RobocodeProperties.isSecurityOff()) { return true; } final String source = domain.getCodeSource().getLocation().toString(); if (!untrustedCodeUrls.contains(source)) { return true; } return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { public Boolean run() { return impliesRobot(permission); } }); }
protected PermissionCollection getPermissions(CodeSource codesource) { if (RobocodeProperties.isSecurityOn()) { return EMPTY_PERMISSIONS; } return super.getPermissions(codesource); }
if (RobocodeProperties.isDebuggingOff() && bufferSize > MAX_BUFFER_SIZE) { return false; // not reallocated!
public RobocodeSecurityManager(IThreadManager threadManager) { super(); this.threadManager = threadManager; ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg != null) { threadManager.addSafeThreadGroup(tg); tg = tg.getParent(); } // We need to exercise it in order to load all used classes on this thread isSafeThread(Thread.currentThread()); if (RobocodeProperties.isSecurityOn()) { System.setSecurityManager(this); } }
private static void initStreams() { PrintStream sysout = new SecurePrintStream(Logger.realOut, true); PrintStream syserr = new SecurePrintStream(Logger.realErr, true); InputStream sysin = new SecureInputStream(System.in); System.setOut(sysout); if (RobocodeProperties.isDebuggingOff()) { System.setErr(syserr); } System.setIn(sysin); }
public Set<String> getFriendlyURLs() { Set<String> urls = new HashSet<String>(); if (itemUrl != null) { String url = itemUrl.toString(); String urlNoType = url.substring(0, url.lastIndexOf('.')); String path = itemUrl.getPath(); String pathNoType = path.substring(0, path.lastIndexOf('.')); urls.add(urlNoType); urls.add(pathNoType); } if (RobocodeProperties.isTestingOn()) { urls.add(getFullClassName()); } else { urls.add(getUniqueFullClassName()); } urls.add(getUniqueFullClassNameWithVersion()); return urls; }
private void testPackages(String name) throws ClassNotFoundException { if (name.startsWith("net.sf.robocode")) { String message = "Robots are not allowed to reference Robocode engine in package: net.sf.robocode"; punishSecurityViolation(message); throw new ClassNotFoundException(message); } if (name.startsWith("robocode.control")) { String message = "Robots are not allowed to reference Robocode engine in package: robocode.control"; punishSecurityViolation(message); throw new ClassNotFoundException(message); } if (RobocodeProperties.isSecurityOn() && name.startsWith("javax.swing")) { String message = "Robots are not allowed to reference Robocode engine in package: javax.swing"; punishSecurityViolation(message); throw new ClassNotFoundException(message); } }
@Override public PermissionCollection getPermissions(final CodeSource codeSource) { if (RobocodeProperties.isSecurityOff()) { return allPermissions; } final String source = codeSource.getLocation().toString(); if (untrustedCodeUrls.contains(source)) { return new Permissions(); } return AccessController.doPrivileged(new PrivilegedAction<PermissionCollection>() { public PermissionCollection run() { return parentPolicy.getPermissions(codeSource); } }); }
private boolean isOkToPrint() { synchronized (syncRoot) { if (RobocodeProperties.isDebuggingOn()) { // It is always allowed to print when debugging is enabled. return true; } if (count > MAX_CHARS) { if (!messaged) { text.append( "\nSYSTEM: This robot is printing too much between actions. Output stopped until next action.\n"); messaged = true; } return false; } messaged = false; return true; } }
File dir = FileUtil.getCwd(); if (RobocodeProperties.isTestingOn()) { dir = dir.getParentFile().getParentFile().getParentFile();
public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (name.startsWith("java.lang")) { // we always delegate java.lang stuff to parent loader return super.loadClass(name, resolve); } if (RobocodeProperties.isSecurityOn()) { testPackages(name); } if (!name.startsWith("robocode")) { Class<?> result = loadRobotClassLocaly(name, resolve); if (result != null) { // yes, it is in robot's class path // we loaded it locally return result; } } // it is robot API // or java class // or security is off // so we delegate to parent class loader return parent.loadClass(name); }
public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (RobocodeProperties.isSecurityOff() || name.startsWith("java.lang")) { return super.loadClass(name, resolve); } if (isEngineClass(name)) { return loadEngineClass(name, resolve); } return super.loadClass(name, resolve); }
if (RobocodeProperties.isTestingOn()) { urls.add(getFullClassName()); } else {
public RobocodeSecurityPolicy(IThreadManager threadManager) { this.parentPolicy = Policy.getPolicy(); this.allPermissions = new Permissions(); this.allPermissions.add(new AllPermission()); this.threadManager = threadManager; allowedPackages.add("robocode.util"); allowedPackages.add("robocode.robotinterfaces"); allowedPackages.add("robocode.robotpaint"); allowedPackages.add("robocode.robocodeGL"); if (isExperimental) { allowedPackages.add("robocode.robotinterfaces.peer"); } initUrls(); if (RobocodeProperties.isSecurityOn()) { Policy.setPolicy(this); } }
@Override public void checkAccess(ThreadGroup g) { if (RobocodeProperties.isSecurityOff()) { return;
if (RobocodeProperties.isSecurityOn()) { logError("Robot " + robotProxy.getStatics().getName() + " is not stopping. Forcing a stop.");
@Override public void checkAccess(Thread t) { if (RobocodeProperties.isSecurityOff()) { return;
realBattle.setBattleThread(battleThread); if (RobocodeProperties.isSecurityOn()) { hostManager.addSafeThread(battleThread);