Read file from Elasticsearch plugin

Hi,

I'm trying to read a file inside my custom plugin like this:

JsonReader reader = new JsonReader(new FileReader(getClass().getClassLoader().getResource(
            "myplugin/es/plugin/file.json").getFile()));

but I got:

access denied (\"java.io.FilePermission\" \"file:/usr/share/elasticsearch/plugins/myplugin/myplugin-1.0.0.jar!/myplugin/es/plugin/file.json\" \"read\"

I tried to add:

permission java.io.FilePermission "/usr/share/elasticsearch/plugins/myplugin/*", "read,write";

or

permission java.io.FilePermission "*", "read,write";`

to my plugin-security.policy file, but same error.

Any help please?

Thanks.
Regards

All plugins automatically have permission to read their own jars. The problem is by trying to read this as a file directly, you have a path which is not given permission. Instead, try reading the resource as an InputStream:

JsonReader reader = new JsonReader(
    new InputStreamReader(getClass().getResourceAsStream("/myplugin/es/plugin/file.json"), StandardCharsets.UTF_8)));

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.