aspose file tools*
The moose likes JBoss/WildFly and the fly likes AccessControlException when accessing Bean in JBOSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "AccessControlException when accessing Bean in JBOSS" Watch "AccessControlException when accessing Bean in JBOSS" New topic
Author

AccessControlException when accessing Bean in JBOSS

Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

I have written a ClientServlet prgm which calls the methods of Entity bean...And deployed the WAR file in JBOSS...

When i hit the application, i get the following error,


java.security.AccessControlException: access denied (java.io.FilePermission sqlexception-service.xml)


Please suggest in resolving this issue...


SCJP 6 [SCJP - Old is Gold]
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Please reply...
Gaurav Sainii
Greenhorn

Joined: May 18, 2009
Posts: 24
Please try to post more details regarding your exception and the code snippets from your code if possible so that it would be easy to understand the details of the problem and reply.
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

I have deployed a WAR file which contains Servlet accessing the entity bean....

This is the exception i get...


java.security.AccessControlException: access denied (java.io.FilePermission G:\j
boss-5.1.0.GA\server\default\deploy\sqlexception-service.xml read)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.File.exists(File.java:731)
at org.jboss.virtual.plugins.context.file.FileHandler.exists(FileHandler
.java:140)
at org.jboss.virtual.VirtualFile.exists(VirtualFile.java:182)
at org.jboss.system.server.profileservice.repository.HotDeploymentReposi
tory.getModifiedDeployments(HotDeploymentRepository.java:108)
at org.jboss.system.server.profile.repository.AbstractProfile.getModifie
dDeployments(AbstractProfile.java:128)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDSca
nner.java:336)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScan
ner.java:255)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:44
1)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java
:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
access$101(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
runPeriodic(ScheduledThreadPoolExecutor.java:181)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
run(ScheduledThreadPoolExecutor.java:205)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
utor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:908)
at java.lang.Thread.run(Thread.java:619)
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import java.util.Properties;
import ejb.entity.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.rmi.RMISecurityManager;

public class Client extends HttpServlet {
public void doGet( HttpServletRequest request, HttpServletResponse response )
{
PrintWriter out = null;
try
{
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}

out = response.getWriter();
Context jndiContext = getInitialContext();
Object obj=jndiContext.lookup("userHome");
UserHome userObj= (UserHome)
javax.rmi.PortableRemoteObject.narrow(obj,UserHome.class);



UserRemote usr =userObj.findByPrimaryKey("Ram");

out.println("Phone :"+ usr.getPhone());

}
catch( Exception e )
{
out.println(e);
}
}
public static Context getInitialContext()
throws javax.naming.NamingException {
Properties p =new Properties();
p.setProperty( "java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" );
p.setProperty( "java.naming.factory.url.pkgs", "org.jboss.namingrg.jnp.interfaces" );
p.setProperty( "java.naming.provider.url", "localhost:1099" );
return new javax.naming.InitialContext(p);
}
}




This is the Client Servlet accessing the entity bean.... Entity bean has been deployed and working fine...
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Please Reply... I am unable to fix this issue...
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

First, please use the code tags - they make it easier to read source code.

java.security.AccessControlException: access denied (java.io.FilePermission G:\j
boss-5.1.0.GA\server\default\deploy\sqlexception-service.xml read)

Have you checked that the file mentioned exists? Have you checked the security settings for that file? (What exact version and variant of Windows are you using? Example: XP Professional) This error means that the account used to run JBoss AS does not have sufficient permission to open and read that file (if it exists).

JBoss In Action
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

That file exists in deploy folder of JBOSS itself... Its got RW Permission... I am using Windows 7... Is this exception related to OS I use?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9343
    
111

at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)


Are you running JBoss AS under a security manager?

[My Blog] [JavaRanch Journal]
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Yes... Running under RMISecurityManager
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9343
    
111

To be sure, how exactly are you doing that? And what policy file are you using for the security manager? What are it's contents?
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

In ClientServlet Program i have included this code snippet since i got an exception saying "No SecurityManager found unable to find the EJBObject"...




And i am not using any security policy files...

Still now where i am missing out the config...
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Please Reply... I am unable to identify the root cause... please give suggestions it will be very useful for me as well as those who get this error also
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Please give me a suggestion for this...
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9343
    
111

Ram Narayan.M wrote:In ClientServlet Program i have included this code snippet since i got an exception saying "No SecurityManager found unable to find the EJBObject"...






Don't do that. Remove that and whatever exception you get after removing that, post that entire exception stacktrace here.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

Are you using EJB 2.1 or 3? If 2.1, why not 3? I very strongly recommend using 3 for any new apps. It's been ages since I did anything with 2.1.

How simple is your EJB? Does it do anything with a database? If it does, then t think that the issue is that you are attempting to do too much at one time (this opinion is based on your other post that says you are new to JBoss AS). I recommend starting off with a simple "hello" EJB and a simple servlet that calls it. You could change your existing EJB to not do any persistence and return a hard-coded string for the getPhone() method. Once you have that working correctly, you can add in more and more of your existing code, which will hopefully narrow down the problem.

I have never had to provide an RMI security manager for a servlet accessing an EJB. I have seen RMI security-related errors from stand-alone clients, but those issues were always solved by providing the necessary client JAR files in the client's classpath.

How are you starting the app server?
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Hi..... Its perfectly working now... What the mistake i have done is i separately deployed war file and jar file (contains EJB Comp) . So it was not working since no link between these two Components.

When i deployed as an EAR file linking together, i got it working... Really nice working in JBOSS... I learn something core things from JBOSS... Most configs has to be done manually which gives a very good scope of learning behind the screen concepts...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AccessControlException when accessing Bean in JBOSS
 
Similar Threads
EJB not bound
SocketTimeoutException: Read timed out
Integration of jboss messaging with jboss
Servlets accessing EJB in JBOSS.
stateless session bean