# java.net.SocketPermission access denied for custom plugin for ES 6.1.2

**URL:** https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895
**Category:** Elasticsearch
**Created:** [February 28, 2018, 4:37pm UTC](https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895 "2018-02-28T16:37:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ropal](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ropal](https://discuss.elastic.co/u/ropal)
#### Post date: [February 28, 2018, 4:37pm UTC](https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895/1 "2018-02-28T16:37:53Z")

</div>

I am using apache httpcore-nio to make an http request from my ES plugin to another application. Even after adding permission in plugin security policy file and wrapping the call with AccessController.doPrivileged in my plugin, I am getting the below error.

I/O reactor terminated abnormally  
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:8000" "connect,resolve")  
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) ~[?:1.8.0\_144]  
at java.security.AccessController.checkPermission(AccessController.java:884) ~[?:1.8.0\_144]  
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) ~[?:1.8.0\_144]  
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051) ~[?:1.8.0\_144]  
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:625) ~[?:?]  
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processSessionRequests(DefaultConnectingIOReactor.java:273) ~[httpcore-nio-4.4.5.jar:4.4.5]

Any help appreciated.

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [February 28, 2018, 6:25pm UTC](https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895/2 "2018-02-28T18:25:35Z")

</div>

Is that the full stack trace? Can you paste/link your plugin security policy file? And show your doPriv block?

---

<div class="post-metadata">

### Author: ![ropal](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ropal](https://discuss.elastic.co/u/ropal)
#### Post date: [March 1, 2018, 8:43am UTC](https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895/3 "2018-03-01T08:43:56Z")

</div>

This is the full stack trace:

[2018-02-27T03:22:03,045][ERROR][o.a.h.i.n.c.InternalHttpAsyncClient] I/O reactor terminated abnormally  
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:8000" "connect,resolve")  
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) ~[?:1.8.0\_144]  
at java.security.AccessController.checkPermission(AccessController.java:884) ~[?:1.8.0\_144]  
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) ~[?:1.8.0\_144]  
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051) ~[?:1.8.0\_144]  
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:625) ~[?:?]  
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processSessionRequests(DefaultConnectingIOReactor.java:273) ~[httpcore-nio-4.4.5.jar:4.4.5]  
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:139) ~[httpcore-nio-4.4.5.jar:4.4.5]  
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) ~[httpcore-nio-4.4.5.jar:4.4.5]  
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:192) ~[httpasyncclient-4.1.2.jar:4.1.2]  
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) [httpasyncclient-4.1.2.jar:4.1.2]  
at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_144]

**code block:**

```
                    httpclient.start();
		final CountDownLatch latch = new CountDownLatch(1);			
                    AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
				@Override
				public Void run() throws IOException {
					httpclient.execute(get, new FutureCallback<HttpResponse>() {
						@Override
						public void completed(final HttpResponse response) {
							try {
								latch.countDown();
								callbackResponse = response;
							} catch (IllegalStateException e) {
								throw new RuntimeException();
							}
						}

						@Override
						public void failed(final Exception ex) {
							latch.countDown();								
						}

						@Override
						public void cancelled() {
							latch.countDown();								
						}

					});
					return null;
				}
			});
		} catch (PrivilegedActionException e) {
			throw (IOException) e.getCause();
		}
```

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [March 1, 2018, 10:26pm UTC](https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895/4 "2018-03-01T22:26:54Z")

</div>

I dont' think your doPrivileged block will work as intended. See how the Elasticsearch rest client does this in [RestClientBuilder](https://github.com/elastic/elasticsearch/blob/master/client/rest/src/main/java/org/elasticsearch/client/RestClientBuilder.java#L195).

---

<div class="post-metadata">

### Author: ![ropal](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ropal](https://discuss.elastic.co/u/ropal)
#### Post date: [March 2, 2018, 11:16am UTC](https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895/5 "2018-03-02T11:16:38Z")

</div>

That helped. Thanks a lot.

---

<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: [March 30, 2018, 11:16am UTC](https://discuss.elastic.co/t/java-net-socketpermission-access-denied-for-custom-plugin-for-es-6-1-2/121895/6 "2018-03-30T11:16:45Z")

</div>

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