access denied ("org.joda.time.JodaTimePermission" "DateTimeZone.setDefault")

Hi all, hope someone can help me with a permission issue

I can't seem to get access for permission: "org.joda.time.JodaTimePermission" "DateTimeZone.setDefault" in the plugin I am developing.

I have a plugin-security.policy (the other permissions granted work fine)

grant {
  permission java.lang.RuntimePermission "accessClassInPackage.sun.misc";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
  permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
  permission org.joda.time.JodaTimePermission "DateTimeZone.setDefault";

All the code is included in the snippet

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
      sm.checkPermission(new SpecialPermission());
          new SpecialPermission("org.joda.time.JodaTimePermission","DateTimeZone.setDefault"));
    myObject = AccessController.doPrivileged(new PrivilegedAction<MyObject>() {
      public MyObject run() {
        // privileged code goes here"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).

Thank you for your response.

I was using a special permission by taking example on
I am using elasticsearch 6.0.1 at the moment (This is the version for the plugin), thanks for the heads up regarding java time api.

This is the stack trace:

search-6_1                            | [2018-12-18T19:44:54,520][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [] fatal error in thread [main], exiting
search-6_1                            | java.lang.ExceptionInInitializerError: null
search-6_1                            | 	[…]
search-6_1                            | 	at com.poitevinpm.elasticsearch.plugin.elasticsearch.Plugin$ ~[?:?]
search-6_1                            | 	at com.poitevinpm.elasticsearch.plugin.elasticsearch.Plugin$ ~[?:?]
search-6_1                            | 	at Method) ~[?:1.8.0_151]
search-6_1                            | 	at com.poitevinpm.elasticsearch.plugin.elasticsearch.Plugin.getScriptEngine( ~[?:?]
search-6_1                            | 	at org.elasticsearch.script.ScriptModule.<init>( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.node.Node.<init>( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.node.Node.<init>( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.bootstrap.Bootstrap$5.<init>( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.bootstrap.Bootstrap.setup( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.bootstrap.Bootstrap.init( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.bootstrap.Elasticsearch.init( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.bootstrap.Elasticsearch.execute( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.cli.EnvironmentAwareCommand.execute( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.cli.Command.mainWithoutErrorHandling( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.cli.Command.main( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.bootstrap.Elasticsearch.main( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | 	at org.elasticsearch.bootstrap.Elasticsearch.main( ~[elasticsearch-6.0.1.jar:6.0.1]
search-6_1                            | Caused by: access denied ("org.joda.time.JodaTimePermission" "DateTimeZone.setDefault")
search-6_1                            | 	at ~[?:1.8.0_151]
search-6_1                            | 	at ~[?:1.8.0_151]
search-6_1                            | 	at java.lang.SecurityManager.checkPermission( ~[?:1.8.0_151]
search-6_1                            | 	at org.joda.time.DateTimeZone.setDefault( ~[joda-time-2.9.5.jar:2.9.5]
search-6_1                            | 	at com.poitevinpm.AppObjectMapper.<init>( ~[?:?]
search-6_1                            | 	at com.poitevinpm.AppObjectMapper.<clinit>( ~[?:?]
search-6_1                            | 	... 22 more
search-6_1 exited with code 1

This is as I expected. Don't do the check on special permission.

The logs I put were the ones I got when removing the SpecialPermission check. It fails at runtime because somewhere in my code there is:


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.

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