简体   繁体   English

java.security.AccessControlException:访问被拒绝的异常

[英]java.security.AccessControlException: access denied Exception

I'm trying to do a simple program for RMI. 我正在尝试为RMI做一个简单的程序。 But, I'm getting the following exception while running the line Naming.rebind("interfacename",Remoteserverobject); 但是,我在运行Naming.rebind(“ interfacename”,Remoteserverobject);行时遇到以下异常。

java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve) java.security.AccessControlException:访问被拒绝(java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

My Code is as follows: 我的代码如下:

public static void main(String[] args) throws Exception {

        if(System.getSecurityManager()==null)
        {
            System.setSecurityManager(new RMISecurityManager());
        }
        Remoteserver objremoteserver=new Remoteserver();
        objremoteserver.setmsg("Hello! How are you?");
        System.out.println(objremoteserver.getmsg());
        try
        {
        Naming.rebind("Remotemethod", objremoteserver);
        System.out.println("Server Started");
        }
        catch(RemoteException re)
        {
            System.out.println(re.getLocalizedMessage());
        }
        finally
        {
            System.out.println("Unknown Exception Occured!!!!");
        }
    }

How to overcome this problem. 如何克服这个问题。 Thanks in advance 提前致谢

Don't use a security manager unless (i) you know you need one and (ii) you have written an appropriate .policy file. 除非(i)您知道自己需要一个,并且(ii)您已经编写了适当的.policy文件,否则请不要使用安全管理器。 If you think both these apply, run your problem with -Djava.security.debug=access,failure to see what is really going wrong. 如果您认为这两种方法都适用,请使用-Djava.security.debug = access运行您的问题,否则将无法查看实际出了什么问题。 Most likely you haven't granted yourself the required permission or you haven't specified the policy file location correctly. 您很可能没有授予自己所需的权限,或者未正确指定策略文件的位置。

确保已按照此处的说明设置RMISecurityManager

i guess this works 我想这可行

public static void main(String[] args) throws Exception {

        Remoteserver objremoteserver=new Remoteserver();
        objremoteserver.setmsg("Hello! How are you?");
        System.out.println(objremoteserver.getmsg());
        try
        {
        Naming.rebind("Remotemethod", objremoteserver);
        System.out.println("Server Started");
        }
        catch(RemoteException re)
        {
            System.out.println(re.getLocalizedMessage());
        }
        finally
        {
            System.out.println("Unknown Exception Occured!!!!");
        }
    }

Every JRE has a default security manager, U r trying to override with a new security manager. 每个JRE都有​​一个默认的安全管理器,U r试图用新的安全管理器覆盖。 You dint specify any properties to this new security manager.so the error.The solution is use the default manager are create a completely new security manager following these instructions . 您可以为此新的安全管理器指定任何属性。因此会出现错误。解决方案是使用默认管理器,并按照以下说明创建一个全新的安全管理器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决 Exception::java.security.AccessControlException: access denied in HttpServlet - How to resolve Exception::java.security.AccessControlException: access denied in HttpServlet JSP-java.security.AccessControlException:拒绝访问 - JSP - java.security.AccessControlException: access denied 错误:java.security.AccessControlException:访问被拒绝 - Error: java.security.AccessControlException: Access denied 线程“main”中的异常java.security.AccessControlException:访问被拒绝(java.util.PropertyPermission * read,write) - Exception in thread “main” java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write) java.security.AccessControlException: 访问被拒绝 (java.io.FilePermission - java.security.AccessControlException: Access denied (java.io.FilePermission java.security.AccessControlException:Java RMI电话目录中的访问被拒绝 - java.security.AccessControlException: access denied in Java RMI Telephone Directory “java.security.AccessControlException:access denied”执行签名的Java Applet - “java.security.AccessControlException: access denied” executing a signed Java Applet java.security.AccessControlException:使用Java Web Start拒绝访问 - java.security.AccessControlException: access denied using Java Web Start Java RMI java.security.AccessControlException:访问被拒绝 - Java RMI java.security.AccessControlException: access denied 具有JDBC的Applet-java.security.AccessControlException:访问被拒绝 - Applet with JDBC - java.security.AccessControlException: access denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM