aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authornickl- <github@jigsoft.co.za>2017-10-27 06:59:33 +0200
committernickl- <github@jigsoft.co.za>2017-11-12 23:49:21 +0200
commit02d023d7e53d15d4c346b70bc9a29113dc62d642 (patch)
tree17986f4031649d42cc124a60ce9e07b51520770c /src/main
parentf52402c2410158bdf0ab53b3852d075fa5320565 (diff)
downloadjavassist-02d023d7e53d15d4c346b70bc9a29113dc62d642.tar.gz
javassist-02d023d7e53d15d4c346b70bc9a29113dc62d642.zip
Add sun.misc.Unsafe privileged retrieval to SecActions.
Also do it anonomously so as not to raise the alarms and upset the powers to be.
Diffstat (limited to 'src/main')
-rwxr-xr-xsrc/main/javassist/util/proxy/SecurityActions.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/javassist/util/proxy/SecurityActions.java b/src/main/javassist/util/proxy/SecurityActions.java
index ca0de912..ce0b5fa6 100755
--- a/src/main/javassist/util/proxy/SecurityActions.java
+++ b/src/main/javassist/util/proxy/SecurityActions.java
@@ -162,4 +162,33 @@ class SecurityActions {
}
}
}
+
+ static Object getSunMiscUnsafeAnonymously() throws ClassNotFoundException
+ {
+ try {
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<Object>() { public Object run() throws
+ ClassNotFoundException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException {
+ Class<?> unsafe = Class.forName("sun.misc.Unsafe");
+ Field theUnsafe = unsafe.getDeclaredField("theUnsafe");
+ theUnsafe.setAccessible(true);
+ Object usf = theUnsafe.get(null);
+ theUnsafe.setAccessible(false);
+ return usf;
+ }
+ });
+ }
+ catch (PrivilegedActionException e) {
+ if (e.getCause() instanceof ClassNotFoundException)
+ throw (ClassNotFoundException) e.getCause();
+ if (e.getCause() instanceof NoSuchFieldException)
+ throw new ClassNotFoundException("No such instance.", e.getCause());
+ if (e.getCause() instanceof IllegalAccessException
+ || e.getCause() instanceof IllegalAccessException
+ || e.getCause() instanceof SecurityException)
+ throw new ClassNotFoundException("Security denied access.", e.getCause());
+ throw new RuntimeException(e.getCause());
+ }
+ }
}