[libbluray-devel] BDJSocketFactory: reflection requires doPrivileged

hpi1 git at videolan.org
Mon Mar 23 11:51:44 CET 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Mar 23 12:11:22 2015 +0200| [8fbcc1dbd5f03606715f8c611ab35ba0b9b4b3a2] | committer: hpi1

BDJSocketFactory: reflection requires doPrivileged

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=8fbcc1dbd5f03606715f8c611ab35ba0b9b4b3a2
---

 .../bdj/java/org/videolan/BDJSocketFactory.java    |   23 ++++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/libbluray/bdj/java/org/videolan/BDJSocketFactory.java b/src/libbluray/bdj/java/org/videolan/BDJSocketFactory.java
index 43f9ab8..5d1efde 100644
--- a/src/libbluray/bdj/java/org/videolan/BDJSocketFactory.java
+++ b/src/libbluray/bdj/java/org/videolan/BDJSocketFactory.java
@@ -28,6 +28,10 @@ import java.net.Socket;
 import java.net.SocketImpl;
 import java.net.SocketImplFactory;
 
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
 class BDJSocketFactory implements SocketImplFactory {
 
     protected static void init() {
@@ -45,13 +49,18 @@ class BDJSocketFactory implements SocketImplFactory {
 
     private SocketImpl newSocket() {
         try {
-            Class defaultSocketImpl = Class.forName("java.net.SocksSocketImpl");
-            Constructor constructor = defaultSocketImpl.getDeclaredConstructor/*s*/(new Class[0])/*[0]*/;
-            constructor.setAccessible(true);
-            return (SocketImpl) constructor.newInstance(new Object[0]);
-        } catch (Exception e) {
-            logger.error("Failed to create socket: " + e + " at " + Logger.dumpStack());
-            throw new RuntimeException(e);
+            return (SocketImpl)AccessController.doPrivileged(
+                new PrivilegedExceptionAction() {
+                    public Object run() throws Exception {
+                        Class defaultSocketImpl = Class.forName("java.net.SocksSocketImpl");
+                        Constructor constructor = defaultSocketImpl.getDeclaredConstructor/*s*/(new Class[0])/*[0]*/;
+                        constructor.setAccessible(true);
+                        return constructor.newInstance(new Object[0]);
+                    }
+                });
+        } catch (PrivilegedActionException e) {
+            logger.error("Failed to create socket: " + e.getException() + " at " + Logger.dumpStack());
+            throw new RuntimeException(e.getException());
         }
     }
 



More information about the libbluray-devel mailing list