在Elasticsearch插件中读取文件 [英] Reading a file in an Elasticsearch plugin

查看:403
本文介绍了在Elasticsearch插件中读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个弹性搜索插件,它依赖于从磁盘上的文件读取数据。当我尝试在我的代码中访问这个文件时,我得到以下异常。

 导致:java.security.AccessControlException:访问被拒绝(java.io.FilePermissionpatient_similarity / codes.txtread)
在java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
在java.security.AccessController .checkPermission(AccessController.java:884)
在java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
在java.lang.SecurityManager.checkRead(SecurityManager.java:888)
在java.io.FileInputStream。< init>(FileInputStream.java:127)
在org.gatech.lucene.search.store.DotProductStore。< init>(DotProductStore.java:22)
在org.gatech.lucene.search.store.DotProductStore.newInstance(DotProductStore.java:71)
在org.gatech.elasticsearch.CommonsPlugin.onModule(CommonsPlugin.java:39)

有没有推荐使用弹性搜索插件访问文件的方法?有没有任何快速解决方法来访问我的插件中的文件?

解决方案

一种方法是启动Elasticsearch进程禁用安全管理器,如下所示:

  bin / elasticsearch -Dsecurity.manager.enabled = false 

由于ES 2.x,默认情况下启用Java安全管理器,所以它早期被禁用。请注意,此选项将在2.3 因为它使您的ES过程变得脆弱。



正确的方法是自定义您的安全策略,并使用政策文件

  grant {
permission java.io.FilePermission/tmp/patient_similarity/codes.txt,read,write;
};

您可以在四个不同的位置添加此政策:


  1. 系统范围内的 $ JAVA_HOME / lib / security / java.policy

  2. 或仅用于 /home/elasticsearch/.java.policy

  3. 中的弹性搜索用户,或从命令行上指定的文件: code> -Djava.security.policy = someURL

  4. plugin-security.policy 文件包含在您的插件中

由于您正在开发一个插件,您当然应该使用选项4。


I am writing an elasticsearch plugin which relies on reading data from a file on disk. When I try to access this file in my code, I get the following exception.

Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "patient_similarity/codes.txt" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
at java.io.FileInputStream.<init>(FileInputStream.java:127)
at org.gatech.lucene.search.store.DotProductStore.<init>(DotProductStore.java:22)
at org.gatech.lucene.search.store.DotProductStore.newInstance(DotProductStore.java:71)
at org.gatech.elasticsearch.CommonsPlugin.onModule(CommonsPlugin.java:39)

Is there any recommended method of accessing files in elasticsearch plugins? Is there any quick workaround to access the file in my plugin?

解决方案

One way to do this is to start the Elasticsearch process by disabling the security manager, like this:

 bin/elasticsearch -Dsecurity.manager.enabled=false

Since ES 2.x, the Java security manager is enabled by default, it was disabled earlier. Note, though, that this option will be removed in 2.3 because it makes your ES process vulnerable.

The correct way of doing this is to customize your security policy and specify the file(s) you want to access using policy files:

grant { 
    permission java.io.FilePermission "/tmp/patient_similarity/codes.txt", "read,write";
};

You can add this policy in four different locations:

  1. either system wide in $JAVA_HOME/lib/security/java.policy
  2. or for just the elasticsearch user in /home/elasticsearch/.java.policy
  3. or from a file specified on the command line: -Djava.security.policy=someURL
  4. or in the plugin-security.policy file included in your plugin.

Since you're developing a plugin, you should of course use option 4.

这篇关于在Elasticsearch插件中读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆