PluginClassLoader extends URLClassLoader { @Override protected PermissionCollection getPermissions(final CodeSource codesource) { final PermissionCollection permissionCollection = super.getPermissions(codesource); return permissionCollection; } PluginClassLoader(final URL jarFileUrl, final ClassLoader parent);   }
@Test public void testLoadingFilterPlugin() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { final URL jar = getClass().getClassLoader().getResource("testDeserializer/testPlugins.jar"); final String classPath = "examples.filter.LowOffsetFilter"; final PluginClassLoader pluginClassLoader = new PluginClassLoader(jar, getClass().getClassLoader()); final Class<? extends RecordFilter> filterPlugin = (Class<? extends RecordFilter>) pluginClassLoader.loadClass(classPath); assertNotNull("Should not be null", filterPlugin); final RecordFilter filter = filterPlugin.getDeclaredConstructor().newInstance(); final String topic = "MyTopic"; final int partition = 2; final long offset = 2423L; final Object key = "key"; final Object value = "{name='Bob', value='value'}"; filter.includeRecord(topic, partition, offset, key, value); assertTrue("Should have our parent class loader", filter.getClass().getClassLoader() instanceof PluginClassLoader); final ProtectionDomain protectionDomain = filter.getClass().getProtectionDomain(); final PermissionCollection permissionCollection = protectionDomain.getPermissions(); assertTrue("Should have read only permissions", permissionCollection.isReadOnly()); }