-
Signed applet fails to access the remote file
hi
I have a applet, and this gets invoked by the javascript.
The purpose of the applet is to fetch the values from a txt file which is in remote server.
Earlier, I have the JRE1.4.1... during this version my applet worked fine.
But now when the JRE is updated to the 1.4.2 the same applet is not working.
In some other forum, i read that giving AllPermissions in the policy file will solve this issue.
But giving such permission is not insecure.
and when the applet is tryign to access the file the followign exception is thrown.
java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.0.53:8080 resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at sun.plugin.net.protocol.http.HttpURLConnection.checkPermission(Unknown Source)
at sun.plugin.net.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.http://www.protocol.http.HttpURLConn...etOutputStream(Unknown Source)
at CMI_Saba.doIt(CMI_Saba.java:121)
at CMI_Saba.getCMIgetParam(CMI_Saba.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
at sun.plugin.com.DispatchImpl$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.com.DispatchImpl.invoke(Unknown Source) java.lang.Exception: java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.0.53:8080 resolve)
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
at sun.plugin.com.DispatchImpl$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
[sample code:begin]
aicc_conn = aicc_url.openConnection();
......
......
......
aicc_conn.setUseCaches(false);
aicc_conn.setRequestProperty("Content-length", String.valueOf(s.length()));
aicc_conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream dataoutputstream = new DataOutputStream(aicc_conn.getOutputStream());
dataoutputstream.writeBytes(s);
dataoutputstream.flush();
[sample code:end]
CMI_Saba.java:121 ==> DataOutputStream dataoutputstream = new DataOutputStream(aicc_conn.getOutputStream());
Pls give some solution to solve this issue.
THNX'n ADV
Deva
-
well it is obviously a permissions error, yuo need to check that you have to correct permissions to view the file, and check thatthe file is not protected by a firewall or something. Maybe the settings on the server have changed, i dont think it is your code, but something external. You'll just have to do some investigating.
But if you want to see if it is your code, i suppose you could just try to access a local file using your own IP so that you see if java has a problem with the way you are trying to read an "external" file...maybe??
Let me know how it goes
A kram a day keeps the doctor......guessing
-
First, Thnx for your reply..
I too think that there is no change needed in the part of the code.
But how to deal with permission.i am using the default java.policy.
Also i edited the existing policy file setting all permission to that file(path will be in http url)
The applet is signed. and when the applet is triggered, the end-user is asked for "yes/no/always". when i give yes..... its raising this exception
Also, Sun has locked down security by ordering the Java Security Manager not to allow any code path kicked off by javascript to perform secured operations within the Applet.
So the existing code doesnt seems to work for the JVM version >= 1.4.2.
Is there any alternative to fix this problem....Sure there will be some alternative that Sun might provided...I dont know what is that ...
Any solution towards this issue?
-
This is the policy file that i have.
..............
grant codeBase "http://192.168.0.53:8080/jsp-examples/lms.txt" {
permission java.security.AllPermission;
permission java.net.SocketPermission "*", "accept, connect, listen, resolve";
permission java.io.FilePermission "<<ALL FILES>>", "read, write, delete, execute";
permission java.net.SocketPermission "*", "resolve";
};
..............
My applet is tryign to access the http://192.168.0.53:8080/jsp-examples/lms.txt file
THe applet is called from the js.
Here is the codes..
import java.applet.Applet;
import java.io.*;
import java.net.*;
public class CMI_Saba extends Applet
{
public String getResponseText()
{
return commText;
}
public String getCMIgetParam()
{
System.out.println("---=== getCMIgetParam ===---\n");
String s = "command=GetParam&version=" + aicc_version + "&session_id=" + aicc_sid;
doIt(s);
System.out.println("Response from LMS:");
-
-
-
-
-
-
}
public int setCMIComm(String s, String s1, String s2)
{
try
{
aicc_url = new URL(s);
aicc_sid = URLEncoder.encode(s1);
aicc_version = URLEncoder.encode(s2);
........
}
catch(MalformedURLException exception)
{
}
-
-
-
}
private void doIt(String s)
{
try
{
aicc_conn = aicc_url.openConnection();
aicc_conn.setDoInput(true);
aicc_conn.setDoOutput(true);
aicc_conn.setUseCaches(false);
aicc_conn.setRequestProperty("Content-length", String.valueOf(s.length()));
aicc_conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream dataoutputstream = new DataOutputStream(aicc_conn.getOutputStream());
dataoutputstream.writeBytes(s);
dataoutputstream.flush();
System.out.println("Passing data to LMS:");
System.out.println("--------------------");
System.out.println(s + "\n");
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(aicc_conn.getInputStream()));
String s1;
for(commText = ""; (s1 = bufferedreader.readLine()) != null; commText += "\n\r")
commText += s1;
statVal = 0;
dataoutputstream.close();
bufferedreader.close();
}
catch(IOException exception)
{
System.err.println("\n** !!! ERROR occured -> " + exception.toString() + " !!! **");
errString = exception.toString();
commText = "2";
statVal = 2;
}
catch(Exception e)
{
System.err.println("\n** !!! ERROR occured -> " + e.toString() + " !!! **");
errString = e.toString();
commText = "2";
statVal = 2;
}
}
the java script is
..........
function getCMIAppletHTMLCode() {
//get the applet file
document.write('<APPLET CODE="CMI_Saba" archive="CMI_Saba.jar" ID="AICCApplet" NAME="AICCApplet" WIDTH=1 HEIGHT=1><PARAM NAME="cabbase" VALUE="CMI_Saba.cab"></APPLET>');
}
..........
Pls give me a solution...This is very urgent.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks