Use generic interfaces for checking socket access (#22753)
This commit replaces specialized functional interfaces in various plugins with generic options. Instead of creating `StorageRunnable` interfaces in every plugin we can just use `Runnable` or `CheckedRunnable`.
This commit is contained in:
parent
28cfc533e2
commit
7f20b93051
|
@ -42,10 +42,10 @@ public final class Access {
|
|||
return AccessController.doPrivileged(operation);
|
||||
}
|
||||
|
||||
public static void doPrivilegedVoid(DiscoveryRunnable action) {
|
||||
public static void doPrivilegedVoid(Runnable action) {
|
||||
SpecialPermission.check();
|
||||
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||
action.execute();
|
||||
action.run();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
@ -58,9 +58,4 @@ public final class Access {
|
|||
throw (IOException) e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface DiscoveryRunnable {
|
||||
void execute();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.common.blobstore.gcs.util;
|
||||
|
||||
import org.elasticsearch.SpecialPermission;
|
||||
import org.elasticsearch.common.CheckedRunnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketPermission;
|
||||
|
@ -46,20 +47,15 @@ public final class SocketAccess {
|
|||
}
|
||||
}
|
||||
|
||||
public static void doPrivilegedVoidIOException(StorageRunnable action) throws IOException {
|
||||
public static void doPrivilegedVoidIOException(CheckedRunnable<IOException> action) throws IOException {
|
||||
SpecialPermission.check();
|
||||
try {
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
|
||||
action.executeCouldThrow();
|
||||
action.run();
|
||||
return null;
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (IOException) e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StorageRunnable {
|
||||
void executeCouldThrow() throws IOException;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,12 +38,12 @@ public final class SocketAccess {
|
|||
private SocketAccess() {}
|
||||
|
||||
public static <T> T doPrivileged(PrivilegedAction<T> operation) {
|
||||
checkSpecialPermission();
|
||||
SpecialPermission.check();
|
||||
return AccessController.doPrivileged(operation);
|
||||
}
|
||||
|
||||
public static <T> T doPrivilegedIOException(PrivilegedExceptionAction<T> operation) throws IOException {
|
||||
checkSpecialPermission();
|
||||
SpecialPermission.check();
|
||||
try {
|
||||
return AccessController.doPrivileged(operation);
|
||||
} catch (PrivilegedActionException e) {
|
||||
|
@ -51,21 +51,12 @@ public final class SocketAccess {
|
|||
}
|
||||
}
|
||||
|
||||
public static void doPrivilegedVoid(StorageRunnable action) {
|
||||
checkSpecialPermission();
|
||||
public static void doPrivilegedVoid(Runnable action) {
|
||||
SpecialPermission.check();
|
||||
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||
action.execute();
|
||||
action.run();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static void checkSpecialPermission() {
|
||||
SpecialPermission.check();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface StorageRunnable {
|
||||
void execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue