SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new SpecialPermission());
sm.checkPermission(
new SpecialPermission("org.joda.time.JodaTimePermission","DateTimeZone.setDefault"));
}
myObject = AccessController.doPrivileged(new PrivilegedAction<MyObject>() {
public MyObject run() {
// privileged code goes here
logger.info("getScriptEngine() privileged");
return MyObject.getInstance();
}
});
Also, I have excluded the joda-time library from the plugin jar, because it was creating a jar hell issue during installation, but I don't think it is related.
What is the actual stacktrace you receive? And why are you using SpecialPermission? That class is intended to reduce permissions of script invocations. By doing a check for it outside a doPrivileged, you would not have the permission granted. Finally, while I'm not sure what you are doing with DateTimeZone, be aware that we are removing joda time from Elasticsearch in 7.0 (and moving to the Java 8 time api).
Ok, I don't think this can work because the joda jar is provided by elasticsearch server. The permission is only granted to your plugin jar and the dependencies it provides.
Taking a step back, why are you trying to force the timezone programmatically? This could be done through java system properties by passing -Duser.timezone=UTC.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.