Access control Exception - java

When I am running RMI Server in netbeans I am getting java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
What to do?

You need to set the permissions within a policy file. An example can be found at the RMI tutorial site and also further information concering policy files.

Related

java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\tempFolder" "read") on GAE

I am migrating my application from Tomcat to Google App Engine (1.9.1). I am running jsf 2.2 on servlet 2.5 and I am facing an issue with reading files from file system. I have code that creates a file on the file system as follows:
File file = new File("C:\\tempFolder");
if(file.isDirectory()){
// do writing stuff here
}
On Tomcat I was not getting any exceptions on the above code, but on Google App Engine I am getting the following exception:
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\tempFolder" "read")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
at java.security.AccessController.checkPermission(AccessController.java:559)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:429)
Why am I getting this exception, and how to fix it?
why i am getting this exception
GAE environment is sandboxed for a number of reasons. This means that you cannot do a lot of things you could normally do on your local machine.
This also includes write access to the file system.
how to fix it
Find another way to persist your data (database, for example).
You can read a little bit more on sandbox restrictions here.

Running a sample RMI application

I am trying to run the example of the RMI application given in the Oracle website http://docs.oracle.com/javase/tutorial/rmi/running.html.
However, trying both Eclipse and in the command line, I can't run the server nor the client.
In fact, when running in Eclipse I get this error:
ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
I also have changed the VM Argument like this:
For the ComputeEngine (server):
-Djava.security.manager -Djava.rmi.server.codebase=file:/Users/name/Documents/workspace/PiComputationRM/src/compute/compute.jar -Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/server.policy
For the ComputePi (client):
-Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/client.policy
The content of my client and server policy is:
grant {
permission java.security.AllPermission;
};
Also when I try to run the server in terminal with:
java -Djava.security.policy="server.policy" src/engine/ComputeEngine.java
I got this error:
Error: Could not find or load main class src.engine.ComputeEngine.java
Please any help, I have spent many hours on the Internet in vain ??
ComputeEngine exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
You are using a security manager and you haven't granted that permission in your .policy file.
I also have changed the VM Argument like this:
For the ComputeEngine (server):
-Djava.security.manager -Djava.rmi.server.codebase=file:/Users/name/Documents/workspace/PiComputationRM/src/compute/compute.jar -Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/server.policy
Several problems there:
a file: codebase isn't going to work unless it specifies a shared location that is visible by that name to the client and the Registry. This doesn't look like one of those.
you need to check whether that is the correct name for the policy file
you don't even need a security manager or policy in the server, unless the client is setting its own codebase and is going to provide classes to you. That doesn't happen in this example.
For the ComputePi (client):
-Djava.security.policy=/Users/name/Documents/workspace/PiComputationRM/client.policy
Double-check this name.
Also when I try to run the server in terminal with:
java -Djava.security.policy="server.policy" src/engine/ComputeEngine.java
I got this error:
Error: Could not find or load main class src.engine.ComputeEngine.java
Of course you did. You gave a compiler command to the JVM. Use the command provided in the tutorial. You don't name .java files to the JVM.
I have spent many hours on the Internet in vain
You should have been double-checking your work against the tutorial instead. You've misread the tutorial in at least two places.
I would also question whether you really need the codebase feature at all. I would start by removing it, and the security managers, altogether, and just get it working without them. It's too much of a complication for a first RMI project.

error running javadb in jre 8 / netbeans 7.4

I recently updated to jre8. It seem that the present security settings are really nasty. I am unable to run javadb
I get the following error
Mon Mar 31 02:04:54 IST 2014 : Security manager installed using the Basic server security policy.
Mon Mar 31 02:04:54 IST 2014 : access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
what are the steps taken by me
changed the permission in java.policy file to listen to 1527 (also added resolve)-but to no avail
this is what http://www.oracle.com/technetwork/java/javase/8-known-issues-2157115.html gives out
Bug 8030961
Area: Java DB Synopsis An additional permission may be needed to
bring up the Java DB network server. In particular, the startup
scripts in may fail to boot the network server.
While attempting to boot, the network server may fail and raise the
following error:
access denied ("java.net.SocketPermission" "localhost:1527"
"listen,resolve") java.security.AccessControlException: access denied
("java.net.SocketPermission" "localhost:1527" "listen,resolve") To fix
this problem, you must bring up the network server with a security
policy that includes the missing permission. Instead of booting the
network server as:
java org.apache.derby.drda.NetworkServerControl start boot the network
server as follows:
java -Djava.security.manager -Djava.security.policy=${yourPolicyFile}
org.apache.derby.drda.NetworkServerControl start where
${yourPolicyFile} is a file containing a customized version of the
policy file described in the Java DB Admin Guide section titled Basic
Network Server security policy. You must customize that generic policy
file to fit your application. In addition, you must add the following
permission to the permissions block granted to the
${derby.install.url}derbynet.jar codebase:
permission java.net.SocketPermission "localhost:${port}", "listen";
where ${port} should be replaced by the port number where the network
server listens for incoming connection requests. By default, that is
port 1527.
now I exactly not sure what to do
*do I need to do any additional stuff
*found derbynet.jar ( as an executable jar file) how do I edit, what do I edit
Thanks,
Think you need to show
1) How your start the server (cmdline)
2) The stacktrace you get
3) Content of your policy file
Alternatively you could study the comments in the corresponding Derby Jira issue

java RMID example

I want to experiment with Activatable objects in RMI. Is there a simple example somewhere that works? I'm trying to use Oracle's tutorial but I get java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1098 connect,resolve)
Try to add this as first argument to your java-vm
-Djava.security.policy=rmi.security
example of rmi.security (could be more specific, created with policytool)
grant {
permission java.security.AllPermission;
};

Hessian Web service invocation from a JavaFX Applet

I'm trying to invoke a Hessian Web Service from a JavaFX applet. I know it needs some reflection permissions so I signed it myself for testing but even then it doesn't work. The browser asks me if I accept the certificate, I click yes but I receive the permission exceptions anyway:
com.caucho.hessian.client.HessianRuntimeException: java.security.AccessControlException: access denied (java.net.SocketPermission 192.168.0.112:8080 connect,resolve)
java.security.AccessControlException: access denied (java.lang.reflect.ReflectPermission suppressAccessChecks
java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
Am I missing something?
Thank you in advance.
According to Sun's documentation:
a signed applet has the AllPermission permission only if Java Plug-in can verify the signers
Since you are self-signing, I think you'll want to setup a policy file to grant yourself permission (will NOT work for others). Here is a tutorial.

Categories

Resources