How to customize plugin-security.policy for custom realm

So, now, after installing the custom realm extension I have a file named
x-pack-extension-security.policy in
/usr/share/elasticsearch/plugins/x-pack/extensions/mycustomrealm.

The contents of the file is:

grant {
permission java.net.NetPermission "getProxySelector";
};

I am still getting an error: java.security.AccessControlException: access
denied ("java.net.NetPermission" "getProxySelector") when the client is
instantiated. Any ideas? This is with 5.1.1.