@Test public void test() { ClassLoaderPolicy policy = new TestPolicy(); assertFalse(policy.canLoad("notallowed")); assertTrue(policy.canLoad("package")); assertTrue(policy.canLoad("package.sub")); assertFalse(policy.canLoad("package2")); assertTrue(policy.canLoad("package2.sub")); assertTrue(policy.canLoad("package3.sub1")); assertTrue(policy.canLoad("package3.sub1.sub")); assertFalse(policy.canLoad("package3.sub")); assertFalse(policy.canLoad("package3.sub.sub")); ClassLoaderPolicy policy2 = new TestPolicy2(); assertTrue(policy2.canLoad("package2")); assertFalse(policy2.canLoad("package")); }
public boolean canLoad(String className) { if (deniedPaths.contains("")) { return false; } String[] split = className.split("\\."); String current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (deniedPaths.contains(current)) { return false; } } if (allowedPaths.contains("")) { return true; } current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (allowedPaths.contains(current)) { return true; } } return false; }
ClassLoaderPolicy { public boolean canLoad(String className) { if (deniedPaths.contains("")) { return false; } String[] split = className.split("\\."); String current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (deniedPaths.contains(current)) { return false; } } if (allowedPaths.contains("")) { return true; } current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (allowedPaths.contains(current)) { return true; } } return false; } }
ClassLoaderPolicy { public boolean canLoad(String className) { if (deniedPaths.contains("")) { return false; } String[] split = className.split("\\."); String current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (deniedPaths.contains(current)) { return false; } } if (allowedPaths.contains("")) { return true; } current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (allowedPaths.contains(current)) { return true; } } return false; }  }
ClassLoaderPolicy { public boolean canLoad(String className) { if (deniedPaths.contains("")) { return false; } String[] split = className.split("\\."); String current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (deniedPaths.contains(current)) { return false; } } if (allowedPaths.contains("")) { return true; } current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (allowedPaths.contains(current)) { return true; } } return false; }  boolean canLoad(String className); }
ClassLoaderPolicy { public boolean canLoad(String className) { if (deniedPaths.contains("")) { return false; } String[] split = className.split("\\."); String current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (deniedPaths.contains(current)) { return false; } } if (allowedPaths.contains("")) { return true; } current = ""; for (String part : split) { current += (current.equals("")) ? part : ("." + part); if (allowedPaths.contains(current)) { return true; } } return false; }  boolean canLoad(String className);  }