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

发布于 2024-08-30 05:48:55 字数 997 浏览 3 评论 0原文

我正在尝试为 RMI 编写一个简单的程序。但是,我在运行该行时遇到以下异常 Naming.rebind("接口名称",Remoteserverobject);

java.security.AccessControlException: 拒绝访问 (java.net.SocketPermission 127.0.0.1:1099 连接,解析)

我的代码如下:

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!!!!");
        }
    }

如何克服这个问题。提前致谢

I'm trying to do a simple program for RMI. But, I'm getting the following exception while running the line
Naming.rebind("interfacename",Remoteserverobject);

java.security.AccessControlException:
access denied
(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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世俗缘 2024-09-06 05:48:55

不要使用安全管理器,除非 (i) 您知道您需要一个安全管理器并且 (ii) 您已经编写了适当的 .policy 文件。如果您认为这两者都适用,请使用 -Djava.security.debug=access,failure 运行您的问题,看看到底出了什么问题。您很可能没有授予自己所需的权限,或者没有正确指定策略文件位置。

Don't use a security manager unless (i) you know you need one and (ii) you have written an appropriate .policy file. If you think both these apply, run your problem with -Djava.security.debug=access,failure to see what is really going wrong. Most likely you haven't granted yourself the required permission or you haven't specified the policy file location correctly.

舞袖。长 2024-09-06 05:48:55

我想这可行

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!!!!");
        }
    }

每个 JRE 都有一个默认的安全管理器,您试图用新的安全管理器覆盖。您没有为这个新的安全管理器指定任何属性。因此会出现错误。解决方案是使用默认管理器,按照这些 说明

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. 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.

╭ゆ眷念 2024-09-06 05:48:55

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

Make sure you have setup the RMISecurityManager as explained here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文