File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes security issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "security issue" Watch "security issue" New topic

security issue

Mike Croteau

Joined: Apr 09, 2007
Posts: 8
I am using the Reflection API, trying to obtain class information. Displaying in an applet, when using the .getDeclaredMethods or .getDeclaredFields, I come across a Security Exception error. How do I get around this? Thanks in advance!

Here is sample code which I think is throwing the Exception:

public String getPublicMethods(String a) throws ClassNotFoundException{

sb.append(PB + MTD);
Method[] theMethods = clas.getDeclaredMethods();
for (int i = 0; i < theMethods.length; i++) {
mod = theMethods[i].getModifiers();
Modifier modifier = new Modifier();
if(modifier.isPublic(mod)) {
methodName = theMethods[i].getName();
returnType = theMethods[i].getReturnType().getName();
sb.append(" " + returnType + " " + methodName + " (");

Class[] parameterTypes = theMethods[i].getParameterTypes();
boolean first = true;
for (int k = 0; k < parameterTypes.length; k ++) {
if(first) {
first = false;
} else {
sb.append(", " +parameterTypes[k].getName());
sb.append(" )\n");
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
For security reasons, applets aren't allowed to do a number of things, including use of the Reflection API. If you really need to do this, then the two principal ways around that -applet signing, and altering the local security policy- are described here.
I agree. Here's the link:
subject: security issue
It's not a secret anymore!