diff options
author | Tim Brooks <tim@uncontended.net> | 2017-01-21 12:03:52 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-21 12:03:52 -0600 |
commit | a4ac29c00588e8597502fc17f4caa6af88346fa8 (patch) | |
tree | 18ce552b297f1e8f33abb5bfd607400f05b81cdb /plugins/ingest-attachment | |
parent | 3ad6d6ebcccd06969f7d1fc22d6ad45655f3a349 (diff) |
Add single static instance of SpecialPermission (#22726)
This commit adds a SpecialPermission constant and uses that constant
opposed to introducing new instances everywhere.
Additionally, this commit introduces a single static method to check that
the current code has permission. This avoids all the duplicated access
blocks that exist currently.
Diffstat (limited to 'plugins/ingest-attachment')
-rw-r--r-- | plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/TikaImpl.java | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/TikaImpl.java b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/TikaImpl.java index 27a4cfebbc..f99a2a630a 100644 --- a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/TikaImpl.java +++ b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/TikaImpl.java @@ -82,18 +82,11 @@ final class TikaImpl { // only package private for testing! static String parse(final byte content[], final Metadata metadata, final int limit) throws TikaException, IOException { // check that its not unprivileged code like a script - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new SpecialPermission()); - } + SpecialPermission.check(); try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<String>() { - @Override - public String run() throws TikaException, IOException { - return TIKA_INSTANCE.parseToString(new ByteArrayInputStream(content), metadata, limit); - } - }, RESTRICTED_CONTEXT); + return AccessController.doPrivileged((PrivilegedExceptionAction<String>) + () -> TIKA_INSTANCE.parseToString(new ByteArrayInputStream(content), metadata, limit), RESTRICTED_CONTEXT); } catch (PrivilegedActionException e) { // checked exception from tika: unbox it Throwable cause = e.getCause(); |