1

我试图让我的 tomcat servlet 下载许多文件,但是我在同一台服务器上运行 apache 和 tomcat,所以我认为这就是它不起作用的原因。我已经在不运行 apache 的服务器上进行了测试,一切都很好。

这是我尝试使用 new Url(fileUrl).openStream() 时遇到的异常:

 Opening input stream Attempted to download: http://www.stefankendall.com/files/test.txt java.security.AccessControlException: access denied (java.net.SocketPermission www.stefankendall.com:80 connect,resolve)

如何在运行 apache 的同时通过 tomcat 运行 http 下载?我卡住了吗?

编辑:
无论我做什么,我都无法通过tomcat。这是 03catalina.policy:

// ========== CATALINA 代码权限 =================================== ====

// These permissions apply to the logging API
grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
        permission java.util.PropertyPermission "java.util.logging.config.class", "read";
        permission java.util.PropertyPermission "java.util.logging.config.file", "read";
        permission java.lang.RuntimePermission "shutdownHooks";
        permission java.io.FilePermission "${catalina.base}${file.separator}conf${file.separator}logging.properties", "read";
        permission java.util.PropertyPermission "catalina.base", "read";
        permission java.util.logging.LoggingPermission "control";
        permission java.io.FilePermission "${catalina.base}${file.separator}logs", "read, write";
        permission java.io.FilePermission "${catalina.base}${file.separator}logs${file.separator}*", "read, write";
        permission java.lang.RuntimePermission "getClassLoader";
        // To enable per context logging configuration, permit read access to the appropriate file.
        // Be sure that the logging configuration is secure before enabling such access
        // eg for the examples web application:
        // permission java.io.FilePermission "${catalina.base}${file.separator}webapps${file.separator}examples${file.separator}WEB-INF${file.separator}classes${file.separator}logging.properties", "read";
};

// These permissions apply to the server startup code
grant codeBase "file:${catalina.home}/bin/bootstrap.jar" {
        permission java.security.AllPermission;
 permission java.net.socketPermission "*:80", "connect, resolve";
};

// These permissions apply to the servlet API classes
// and those that are shared across all class loaders
// located in the "lib" directory
grant codeBase "file:${catalina.home}/lib/-" {
        permission java.security.AllPermission;
       permission java.net.socketPermission "*:80", "connect, resolve";
};

grant codeBase "file:${catalina.home}/webapps/-" {
 permission java.security.AllPermission;
 permission java.net.socketPermission "*:80", "connect, resolve";
};
4

1 回答 1

2

您的问题与是否存在在同一个盒子上运行的某些程序无关;它与 Tomcat 中存在 SecurityManager 有关(这可能意味着您正在运行旧版本的 Tomcat)。

这是有关如何配置 Tomcat SecurityManager的详细文档。在您的情况下,您将在 local.policy 文件中添加一些行,如下所示

grant codeBase "file:${catalina.home}/webapps/-" {
  permission java.net.SocketPermission "*:80", "connect";
};
于 2009-10-08T17:13:11.557 回答