AccessControlException: access denied (net.jini.discovery.DiscoveryPermission) exception when i try to run my first Jini client :-(
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bruno_Baguette
Posted On:   Saturday, May 11, 2002 12:42 PM

Hello, I have a problem with my first Jini client (extracted from the "Jini Core - Second Edition" book) and I'm getting the java.security.AccessControlException: access denied (net.jini.discovery.DiscoveryPermission) exception... The Jini client is "trying" to run on a WindowsXP computer with the JDK 1.3 and Jini 1.2.1. All the Jini services are running on a Linux computer with the JDK 1.3 and Jini 1.2.1. Here's the exception : C:javaCodes_Jini>java -cp ConvertMyCurrency;C:javajini_1_2_1libjini-core.jar;C:javajini_1_2_1libjini-ext.jar; C:javajini_1_2_1libsun-util.jar -Djava.rmi.security.policy=C:javaCodes_jinijini.polic   More>>

Hello,



I have a problem with my first Jini client (extracted from the "Jini Core - Second Edition" book) and I'm getting the java.security.AccessControlException: access denied (net.jini.discovery.DiscoveryPermission) exception...



The Jini client is "trying" to run on a WindowsXP computer with the JDK 1.3 and Jini 1.2.1.

All the Jini services are running on a Linux computer with the JDK 1.3 and Jini 1.2.1.



Here's the exception :

			
C:javaCodes_Jini>java -cp

ConvertMyCurrency;C:javajini_1_2_1libjini-core.jar;C:javajini_1_2_1libjini-ext.jar;
C:javajini_1_2_1libsun-util.jar -Djava.rmi.security.policy=C:javaCodes_jinijini.policy ConvertMyCurrency
Exception in thread "main" java.security.AccessControlException: access denied

(net.jini.discovery.DiscoveryPermission )

at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at java.security.AccessController.checkPermission(AccessController.java:399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at net.jini.discovery.LookupDiscovery.checkGroups(LookupDiscovery.java:1216)
at net.jini.discovery.LookupDiscovery. (LookupDiscovery.java:777)
at ConvertMyCurrency. (ConvertMyCurrency.java:38)
at ConvertMyCurrency.main(ConvertMyCurrency.java:88)



I don't understand why I am getting this exception because I have given the DiscoveryPermission in the policy file :


			
grant {
permission java.security.AllPermission "", "";
permission net.jini.discovery.DiscoveryPermission "*";
permission java.net.SocketPermission "*", "connect,accept";
};


I don't know if the problem come from my program, but here's the code above :
			
import net.jini.discovery.DiscoveryListener;
import net.jini.discovery.DiscoveryEvent;
import net.jini.discovery.LookupDiscovery;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;

public class ConvertMyCurrency implements Runnable {
protected ServiceTemplate template;
protected LookupDiscovery disco;

// An inner class to implement DiscoveryListener
class Listener implements DiscoveryListener {
public void discovered(DiscoveryEvent ev) {
ServiceRegistrar[] newregs = ev.getRegistrars();
for (int i=0 ; i
lookForService(newregs[i]);
}
}
public void discarded(DiscoveryEvent ev) {
}
}

public ConvertMyCurrency() throws IOException {
Class[] types = { CurrencyCalculator_Interface.class };

template = new ServiceTemplate(null, types, null);

// Set a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(
new RMISecurityManager());
}

// Only search the public group
disco = new LookupDiscovery(new String[] { "" });

// Install a listener
disco.addDiscoveryListener(new Listener());
}

// Once we've found a new lookup service, search
// for proxies that implement
// CurrencyCalculator_Interface
protected Object lookForService(ServiceRegistrar lusvc) {
Object o = null;

try {
o = lusvc.lookup(template);
} catch (RemoteException ex) {
System.err.println("Error doing lookup: " + ex.getMessage());
return null;
}

if (o == null) {
System.err.println("No matching service.");
return null;
}

System.out.println("Got a matching service.");
//System.out.println("It's message is: " + ((CurrencyCalculator_Interface)o).getMessage());
return o;
}

// This thread does nothing--it simply keeps the
// VM from exiting while we do discovery.
public void run()
{
while (true)
{
try
{
Thread.sleep(1000000);
}
catch (InterruptedException ex)
{
}
}
}

// Create a ConvertMyCurrency and start its thread
public static void main(String args[])
{
try
{
ConvertMyCurrency hwc = new ConvertMyCurrency();
new Thread(hwc).start();
}
catch (IOException TheException)
{
System.out.println("Couldn't create client: " + TheException.getMessage());
}
}
}





Please can you help me to find the error(s) in my program, or in the policy file in order to me to be able to

run and to connect my programm to the Lookup Service ?


Thanks you very much in advance !


Bruno.    <<Less
About | Sitemap | Contact