# Access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")

**URL:** https://discuss.elastic.co/t/access-denied-java-lang-runtimepermission-accessdeclaredmembers/108132
**Category:** Elasticsearch
**Created:** [November 17, 2017, 1:04pm UTC](https://discuss.elastic.co/t/access-denied-java-lang-runtimepermission-accessdeclaredmembers/108132 "2017-11-17T13:04:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Vivek\_Unni](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Vivek\_Unni](https://discuss.elastic.co/u/Vivek_Unni)
#### Post date: [November 17, 2017, 1:04pm UTC](https://discuss.elastic.co/t/access-denied-java-lang-runtimepermission-accessdeclaredmembers/108132/1 "2017-11-17T13:04:03Z")

</div>

I am trying to map the JSON response from other service to a POJO class(AMAUser class from an external jar ama-user-service.jar) using ObjectMapper.  
I have configured the policy file as below in /elasticsearch-5.6.0/plugins/x-pack/plugin-security.policy

permission java.lang.RuntimePermission "accessDeclaredMembers";

And also wrapped up the sensitive code (mapper.readValue()) in Custom Realm as below; however, I still keep getting this access denied error in my logs and therefore mapping is not happening at all.

Would be grateful if someone please let me know if there is any issues with the code below or if there's any configurations I had missed out.

```
           if (sm != null) {
               // unprivileged code such as scripts do not have SpecialPermission
               sm.checkPermission(new SpecialPermission());
              }
             userObj = AccessController.doPrivileged( 
               new PrivilegedExceptionAction<AMAUser>() { 
                   @Override 
                    public AMAUser run() 
                            throws IOException, JsonGenerationException, JsonParseException {
                      return mapper.readValue(responseResult, AMAUser.class);
                    } 
                } 
            );
```

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [November 17, 2017, 1:33pm UTC](https://discuss.elastic.co/t/access-denied-java-lang-runtimepermission-accessdeclaredmembers/108132/2 "2017-11-17T13:33:53Z")

</div>

Since this question is about X-Pack custom realms I'm going to move it to the X-Pack category. I think you will get better visibility by people that can help you there. Hope thats ok

---

<div class="post-metadata">

### Author: ![Albert\_Zaharovits](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/albert_zaharovits/32/24390_2.png) [@Albert\_Zaharovits](https://discuss.elastic.co/u/Albert_Zaharovits)
#### Post date: [November 17, 2017, 2:53pm UTC](https://discuss.elastic.co/t/access-denied-java-lang-runtimepermission-accessdeclaredmembers/108132/3 "2017-11-17T14:53:29Z")

</div>

Let me step back for a moment, and ask how did you configure the dependency on `ama-user-service.jar`?  
There should be no permissions required if the `AMAUser.class` is loaded by the same Classloader, ie add the dependency on `ama-user-service.jar` as a normal referenced jar library to your Custom Realm project.

For completeness check [https://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html](https://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html) : `If this class is in a package, java.lang.RuntimePermission "accessClassInPackage.{pkgName}" is also required.` but you really should not need this and you should NOT tinker with the permissions file for the whole X-Pack.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [December 15, 2017, 2:53pm UTC](https://discuss.elastic.co/t/access-denied-java-lang-runtimepermission-accessdeclaredmembers/108132/4 "2017-12-15T14:53:42Z")

</div>

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