I am using reflection to do the following two steps in a bundle:
- create an SSLServerSocket via SSLServerSocketFactory.create...
- on the returned object, invoke a public method "setNeedClientAuthentication".
Both of the SSLServerSocketFactory and Server Socket are exposed by the JRE (not exported by a bundle).
Creating the socket works fine, then the following code:
Method auth = socket.getClass().getMethod("setNeedClientAuth",
new Class[] {boolean.class});
auth.invoke(socket, new Object[] {requireClientAuth});
results in this Exception:
IllegalAccessException:
Class org.knopflerfish.bundle.http.SocketListener can not access a member of class com.sun.net.ssl.internal.ssl.SSLServerSocketImpl with modifiers "public"
Using "doPrivileged" did not help.
Using explicit casting instead of reflection did help. But I want to avoid non-ee.foundation imports.
Thanks
Tom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Class sslSocket = Class.forName("javax.net.ssl.SSLServerSocket");
Method auth = sslSocket.getMethod("setNeedClientAuth", new Class[] {Boolean.TYPE});
auth.invoke(socket, new Object[] {requireClientAuth});
/Per
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To summarize:
- when using the abstract class "SSLServerSocket" to find the method "setNeedClientAuth(boolean)" to invoke it works.
- when using the derived class "com.sun.net.ssl.internal.SSLServerSocketImpl" to find the method to invoke, there is an IllegalAccessException. (even though the method exists in this class and is public)
Could anyone explain the logic behind this?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I suspect it's because SSLServerSocketImpl isn't a public class even though "setNeedClientAuth" is a public method in that class (it has to since it's declared public in SSLServerSocket).
I.e. you cannot do:
import com.sun.net.ssl.internal.ssl.SSLServerSocketImpl;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am using reflection to do the following two steps in a bundle:
- create an SSLServerSocket via SSLServerSocketFactory.create...
- on the returned object, invoke a public method "setNeedClientAuthentication".
Both of the SSLServerSocketFactory and Server Socket are exposed by the JRE (not exported by a bundle).
Creating the socket works fine, then the following code:
Method auth = socket.getClass().getMethod("setNeedClientAuth",
new Class[] {boolean.class});
auth.invoke(socket, new Object[] {requireClientAuth});
results in this Exception:
IllegalAccessException:
Class org.knopflerfish.bundle.http.SocketListener can not access a member of class com.sun.net.ssl.internal.ssl.SSLServerSocketImpl with modifiers "public"
Using "doPrivileged" did not help.
Using explicit casting instead of reflection did help. But I want to avoid non-ee.foundation imports.
Thanks
Tom
Do it this way instead:
Class sslSocket = Class.forName("javax.net.ssl.SSLServerSocket");
Method auth = sslSocket.getMethod("setNeedClientAuth", new Class[] {Boolean.TYPE});
auth.invoke(socket, new Object[] {requireClientAuth});
/Per
Thanks, you are right.
To summarize:
- when using the abstract class "SSLServerSocket" to find the method "setNeedClientAuth(boolean)" to invoke it works.
- when using the derived class "com.sun.net.ssl.internal.SSLServerSocketImpl" to find the method to invoke, there is an IllegalAccessException. (even though the method exists in this class and is public)
Could anyone explain the logic behind this?
Thanks
I suspect it's because SSLServerSocketImpl isn't a public class even though "setNeedClientAuth" is a public method in that class (it has to since it's declared public in SSLServerSocket).
I.e. you cannot do:
import com.sun.net.ssl.internal.ssl.SSLServerSocketImpl;