ESAPI.properties在Java Google AppEngine项目中的位置

时间:2012-02-21 20:14:41

标签: java google-app-engine owasp

我的项目正在开发服务器上。它适用于以下两种情况:

  1. 使用源路径中的.esapi目录,以便最终在WEB-INF / classes中
  2. 使用lib根目录中的.esapi目录,以便最终在WEB-INF / lib中
  3. 但是,当部署到Google时(使用上述两种策略中的任何一种),它都不起作用。

    我收到有关无法找到ESAPI的常见消息。我第一次尝试使用ESAPI一旦部署到Google时的属性文件。

    Attempting to load ESAPI.properties via file I/O.
    Attempting to load ESAPI.properties as resource file via file I/O.
    Not found in 'org.owasp.esapi.resources' directory or file not readable: /base/data/home/ap
    Not found in SystemResource Directory/resourceDirectory: .esapi/ESAPI.properties
    Loading ESAPI.properties via file I/O failed. Exception was: java.io.FileNotFoundException
    Attempting to load ESAPI.properties via the classpath.
    ESAPI.properties could not be loaded by any means. Fail. Exception was: java.security.Acces
    

    ESAPI似乎确实包含支持AppEngine http://goo.gl/rD8dz

    的更改

    更新 问题是org.owasp.esapi.reference.DefaultSecurityConfiguration的第603行调用ClassLoader.getSystemClassLoader(),这在Google Appengine中是非法的。这导致上面的异常(抱歉它被裁剪)。 在代码尝试获取资源之前,有三个ClassLoader预先加载到数组中。

        ClassLoader[] loaders = new ClassLoader[] {
                Thread.currentThread().getContextClassLoader(),
                ClassLoader.getSystemClassLoader(),
                getClass().getClassLoader() 
        };
        String[] classLoaderNames = {
                "current thread context class loader",
                "system class loader",
                "class loader for DefaultSecurityConfiguration class"
        };
    

    我已经攻击了我自己的DefaultSecurityConfiguration副本,我从loadConfigurationFromClasspath方法中删除了SystemClassLoader(和相应的classLoaderName)。

        ClassLoader[] loaders = new ClassLoader[] {
                Thread.currentThread().getContextClassLoader(),
                getClass().getClassLoader() 
        };
        String[] classLoaderNames = {
                "current thread context class loader",
                "class loader for DefaultSecurityConfiguration class"
        };
    

    具有讽刺意味的是,这是因为他们通过循环使用这种方法失败的类加载器使代码易于阅读/扩展(IMHO)。我很想提交一个内部类的补丁来延迟调用getSystemClassLoader(你不能在AppEngine上做)。

    有趣的是,这是有效的,因为它是唯一可能的,因为esapi罐没有密封。 我原以为应该密封一个安全库jar。也许我用错了!

    更新 我通过maven使用esapi jar,这已被重新包装并且没有签名。不太理想,但它不比我从maven得到的其他40个开源罐子更安全!

5 个答案:

答案 0 :(得分:3)

使用您自己的实现覆盖DefaultSecurityConfiguration类的解决方案正是解决该问题的正确方法。这正是它以这种方式设计的原因。在Google App-Engine上使用ESAPI存在一些其他固有问题,主要是加密/散列问题。根据此主题(http://code.google.com/p/googleappengine/issues/detail?id=1612)上的评论,此问题已“部分”解决,但在GAE中使用加密仍存在严重限制。< / p>

答案 1 :(得分:3)

我刚刚在Google App Engine项目上成功整合了 ESAPI 2.1.0 ,我甚至没有使用Maven。

ESAPI.properties &amp;目录[gae-project]/war/ESAPI/中的 validation.properties 。 因此, ESAPI.properties 的完整路径将是

[gae-project]/war/ESAPI/ESAPI.properties

将其置于 war / 下可确保将文件上传到Google。

编辑您的 appengine-web.xml ,在<appengine-web-app>根节点

中添加以下行
...
<system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
    <property name="org.owasp.esapi.resources" value="ESAPI" />
</system-properties>
<static-files>
    <exclude path="/ESAPI**properties" />
</static-files>
...

将允许App Engine将 .properties 文件识别为项目文件。

有关更详细的讨论,您还可以阅读ESAPI for Google App Engine Integration Tutorial

答案 2 :(得分:1)

您可以将文件放在META-INF/目录中,然后将org.owasp.esapi.resources系统属性更改为 appengine-web.xml 中的META-INF/,如下所示:

    <system-properties>
      <property name="org.owasp.esapi.resources" value="META-INF/" />
    </system-properties>

因为DefaultSecurityConfiguration首先在资源目录中寻找配置文件,然后在类路径中。

答案 3 :(得分:1)

以下步骤对我有用。

  1. 提取jar
  2. 创建一个文件夹.esapi
  3. 下载ESAPI.properties
  4. 创建jar。
  5. 使用它,它不会再抱怨缺少属性文件。

答案 4 :(得分:0)

在我们的项目中,该文件位于WEB-INF / classes文件夹中。我们不使用.esapi子文件夹。

Esapi version = 2.0.1

虽然部署在jboss中。