java.policy

D

Darren

No i've edited the global java.policy file and added the entry

permission java.io.Filepermission
"/usr/local/apache2/htdocs/hello.html","read";
permission java.net.SocketPermission ":80","connect,resolve,accept";

Then i made sure rmiregistry is running then i run my applet

and i still get

thread applet-Helloserver.class[1] > java.security.AccessControlException:
access denied (java.net.SocketPermission 10.0.0.254:80 connect,resolve)

on the line
BufferedReader in = new BufferedReader(new
InputStreamReader(location.openStream()));

Does anyone know why and how i can fix it?

I've included the full script below
Thanks in advance


import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.security.*;

public class Helloserver extends Applet
{
private String hostname = "10.0.0.254";
private String protocol = "http://";
private String port="80";
private URL location;
private Object content;
private String getStr = "GET / HTTP/1.1";



public void init()
{


hello();
}

public void paint(Graphics g)
{

g.drawString(hostname, 50, 60 );
}

/**
* Method hello
*
*
* @return
*
*/
protected boolean hello()
{

String host=hostname+":"+port;
hostname = host;
String str,buf,server;
buf="";


try
{

location=new URL(protocol+hostname);
server=location.getHost();
server=server+"/hello.html";
System.out.println(server);

SocketPermission sp = new SocketPermission (server, "connect,resolve");
FilePermission fp = new FilePermission ("<<ALL FILES>>","read");
BufferedReader in = new BufferedReader(new
InputStreamReader(location.openStream()));

while ((str = in.readLine()) != null)
{
buf=buf+str;
}
in.close();
System.out.println(buf);





}
catch(MalformedURLException u)
{
hostname=u.getMessage();
}
catch(IOException u)
{
hostname=u.getMessage();
}


return true;
}


}
 
P

Pete Barrett

No i've edited the global java.policy file and added the entry

permission java.io.Filepermission
"/usr/local/apache2/htdocs/hello.html","read";
permission java.net.SocketPermission ":80","connect,resolve,accept";

Then i made sure rmiregistry is running then i run my applet

and i still get

thread applet-Helloserver.class[1] > java.security.AccessControlException:
access denied (java.net.SocketPermission 10.0.0.254:80 connect,resolve)
I would guess that you're downloading the applet from somewhere other
than 10.0.0.254, in which case you can't open a socket to that IP from
an applet - only to the same machine it was served from.
on the line
BufferedReader in = new BufferedReader(new
InputStreamReader(location.openStream()));

Does anyone know why and how i can fix it?
I don't actually know what you're trying to do, but that <:80>
suggests that you're trying to display a web page. If that's the case,
try using AppletContext.showDocument(...) to display it.

Pete Barrett
 
D

Darren

Pete Barrett said:
No i've edited the global java.policy file and added the entry

permission java.io.Filepermission
"/usr/local/apache2/htdocs/hello.html","read";
permission java.net.SocketPermission ":80","connect,resolve,accept";

Then i made sure rmiregistry is running then i run my applet

and i still get

thread applet-Helloserver.class[1] > java.security.AccessControlException:
access denied (java.net.SocketPermission 10.0.0.254:80 connect,resolve)
I would guess that you're downloading the applet from somewhere other
than 10.0.0.254, in which case you can't open a socket to that IP from
an applet - only to the same machine it was served from.
on the line
BufferedReader in = new BufferedReader(new
InputStreamReader(location.openStream()));

Does anyone know why and how i can fix it?
I don't actually know what you're trying to do, but that <:80>
suggests that you're trying to display a web page. If that's the case,
try using AppletContext.showDocument(...) to display it.

Pete Barrett
Nothing so dramatic. the idea is one web site checks to see if another one
is up and if it is then return a value
 
D

Darren

Roedy Green said:
There are lots of policy files floating about your machine. Which one
is the one being used? See http://mindprod.com/applets/wassup.html
to be sure.

look for property java.security.policy. You may find your browser is
using a different policy file.

That could be a problem. I was hoping that because i edited the default
policies then the browser would look there by default. How would i find out
which policy file it's looking at and is this changeable?

TIA
 
R

Roedy Green

That could be a problem. I was hoping that because i edited the default
policies then the browser would look there by default. How would i find out
which policy file it's looking at and is this changeable?

Try the advice in my previous post:
 
P

Pete Barrett

Nothing so dramatic. the idea is one web site checks to see if another one
is up and if it is then return a value

Then why use an applet? It certainly wouldn't be my choice, simply
because of the security restrictions on applets. If you really have to
use an applet, you probably need to connect to a proxy on the same
server the applet came from, and have the proxy do the actual checking
and report the result to the applet.


Pete Barrett
 
A

Andrew Thompson

Then why use an applet? It certainly wouldn't be my choice, simply
because of the security restrictions on applets. If you really have to
use an applet, you probably need to connect to a proxy on the same
server the applet came from, and have the proxy do the actual checking
and report the result to the applet.

No you do not. Not if it is a trusted applet.

Try reading the thread before jumping in next time Pete.
This has been discussed numerous times before, as well as
a number of times on this thread.
 
D

Darren

Pete Barrett said:
Then why use an applet? It certainly wouldn't be my choice, simply
because of the security restrictions on applets. If you really have to
use an applet, you probably need to connect to a proxy on the same
server the applet came from, and have the proxy do the actual checking
and report the result to the applet.
Nothing is forcing me to use an applet other than the fact that the site
doig checks doesn't have server side scripting.
 
D

Darren

Roedy Green said:
Try the advice in my previous post:

You mean the File I/O Amanuensis? I tried that. I even editied the policie
files and started the remote policy server on the site the applet is trying
to talk to but it still didn't work
 
R

Roedy Green

Nothing is forcing me to use an applet other than the fact that the site
doig checks doesn't have server side scripting.
The two other easier choices are JAWS and plain old Application.

The nice thing about avoiding an Applet is it gets all the
uncertainties added by the browser out of the equation. It also gives
you back its ram if you want to do something grandiose.
 
R

Roedy Green

You mean the File I/O Amanuensis? I tried that. I even editied the policie
files and started the remote policy server on the site the applet is trying
to talk to but it still didn't work

no the advice about how to check which policy file is the REAL policy
file.
 
R

Roedy Green

yes. I can post it all if you like

I did a check on my own machine and discovered this property, despite
its name, is Opera specific. So, never mind.

I guess the other browsers expect java.policy in the standard places
offset from the java.home = C:\Program Files\Java\jre1.5.0_04
property or user.home = C:\Documents and Settings\Administrator.ROEDY.

C:\Program Files\Java\jre1.5.0_04\lib\security\java.policy
or
E:\Program Files\Java\jdk1.5.0_04\jre\lib\security\java.policy

You also might have a user .java.policy which could be interfering.

I explain the chain you can use to figure out which policy file is the
one in effect at http://mindprod.com/policyfile.html

I revamped that entry it recently. You would feel awfully silly if
the reason it was ignoring your permissions was you modified the wrong
file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top