调用SecurityManager从webservice访问rmi服务器时出错

时间:2015-07-13 17:03:56

标签: java web-services jboss rmi

我有一个web服务并且工作正常,实际上我已经使用SoapUI的wsdl文件对其进行了测试。 但是当我添加代码以便访问包含我需要使用的所有功能的rmi服务器时,一切都变坏了

if(System.getSecurityManager()==null){
    System.setProperty("java.security.policy", "file:/C:/Users/usuario/workspace/Interface/cliente.policy");
    System.setSecurityManager(new SecurityManager());
}

registro = LocateRegistry.getRegistry(serverAddress,(new Integer(serverPort)).intValue());
rmiServidor = (PeticionesInterface) (registro.lookup(serverName));

调试该代码,在执行新的SecurityManager时,我收到以下错误

14:00:10,762 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 1) JBAS014612: Operation ("read-children-names") failed - address: (undefined): java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getClassLoader")
    at java.security.AccessControlContext.checkPermission(Unknown Source) [:1.7.0_05]
    at java.security.AccessController.checkPermission(Unknown Source) [:1.7.0_05]
    at java.lang.SecurityManager.checkPermission(Unknown Source) [:1.7.0_05]
    at java.lang.Thread.getContextClassLoader(Unknown Source) [:1.7.0_05]
    at org.jboss.as.controller.SecurityActions$SetThreadContextClassLoaderAction$2$1.run(SecurityActions.java:105)
    at org.jboss.as.controller.SecurityActions$SetThreadContextClassLoaderAction$2$1.run(SecurityActions.java:103)
    at java.security.AccessController.doPrivileged(Native Method) [:1.7.0_05]
    at org.jboss.as.controller.SecurityActions$SetThreadContextClassLoaderAction$2.setThreadContextClassLoader(SecurityActions.java:103)
    at org.jboss.as.controller.SecurityActions.setThreadContextClassLoader(SecurityActions.java:68)
    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:383)
    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:272)
    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:200)
    at org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:121)
    at org.jboss.as.controller.ModelControllerImpl$1.execute(ModelControllerImpl.java:304)
    at org.jboss.as.controller.ModelControllerImpl$1.execute(ModelControllerImpl.java:294)
    at org.jboss.as.server.deployment.scanner.FileSystemDeploymentService.getDeploymentNames(FileSystemDeploymentService.java:843)
    at org.jboss.as.server.deployment.scanner.FileSystemDeploymentService.access$3300(FileSystemDeploymentService.java:88)
    at org.jboss.as.server.deployment.scanner.FileSystemDeploymentService$ScanContext.<init>(FileSystemDeploymentService.java:1177)
    at org.jboss.as.server.deployment.scanner.FileSystemDeploymentService$ScanContext.<init>(FileSystemDeploymentService.java:1173)
    at org.jboss.as.server.deployment.scanner.FileSystemDeploymentService.scan(FileSystemDeploymentService.java:335)
    at org.jboss.as.server.deployment.scanner.FileSystemDeploymentService$DeploymentScanRunnable.run(FileSystemDeploymentService.java:149)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [:1.7.0_05]
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source) [:1.7.0_05]
    at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [:1.7.0_05]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [:1.7.0_05]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [:1.7.0_05]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [:1.7.0_05]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.7.0_05]
    at java.lang.Thread.run(Unknown Source) [:1.7.0_05]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)

我有服务器和客户端的安全文件。 客户端上的此文件

grant {
    permission java.security.AllPermission;
    permission java.net.SocketPermission "*", "resolve,connect,listen,accept";
    permission java.lang.RuntimePermission "getClassLoader";
    permission java.lang.RuntimePermission "setSecurityManager";
    permission java.lang.RuntimePermission "createSecurityManager";
    permission java.lang.RuntimePermission "usePolicy"; 
    permission java.lang.RuntimePermission "*";
    permission java.util.PropertyPermission "*", "read";
    permission java.io.FilePermission "*","read";
};

服务器上的此文件

grant {
    permission java.security.AllPermission;
    permission java.net.SocketPermission "*", "resolve,connect,listen,accept";
    permission java.lang.RuntimePermission "getClassLoader";
    permission java.lang.RuntimePermission "*";
    permission java.util.PropertyPermission "*", "read";
};

我知道两个.policy文件都不正确,但我一直在添加权限,因为我收到了错误。

我也试过使用RMISecurityManager,但我也有同样的行为。

我不知道如何解决这个错误,任何人都可以帮助我吗?

提前致谢。

0 个答案:

没有答案