首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试使用ESAPI,但遇到错误

尝试使用ESAPI,但遇到错误
EN

Stack Overflow用户
提问于 2011-10-08 19:17:03
回答 10查看 107.8K关注 0票数 22

我正在尝试使用ESAPI.jar为我的web application.Basically提供安全性,我刚刚开始使用ESAPI.jar。但问题是我甚至不能使用ESAPI运行一个简单的程序。下面的小代码片段是:

代码语言:javascript
复制
String clean = ESAPI.encoder().canonicalize("someString");
Randomizer r=ESAPI.randomizer();    
System.out.println(r);
System.out.println(clean);

我得到了这个错误:

代码语言:javascript
复制
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: D:\Eclipse-Workspace\Test\ESAPI.properties
Not found in SystemResource Directory/resourceDirectory: .esapi\ESAPI.properties
Not found in 'user.home' (C:\Documents and Settings\user.user) directory: C:\Documents and Settings\user.user\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.lang.IllegalArgumentException: Failed to load ESAPI.properties as a classloader resource.
Exception in thread "main" org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException SecurityConfiguration class (org.owasp.esapi.reference.DefaultSecurityConfiguration) CTOR threw exception.
    at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:129)
    at org.owasp.esapi.ESAPI.securityConfiguration(ESAPI.java:184)
    at org.owasp.esapi.ESAPI.encoder(ESAPI.java:99)
    at org.rancore.testJasp.TestEsapi.main(TestEsapi.java:59)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:86)
    ... 3 more
Caused by: org.owasp.esapi.errors.ConfigurationException: ESAPI.properties could not be loaded by any means. Fail.
    at org.owasp.esapi.reference.DefaultSecurityConfiguration.loadConfiguration(DefaultSecurityConfiguration.java:439)
    at org.owasp.esapi.reference.DefaultSecurityConfiguration.<init>(DefaultSecurityConfiguration.java:227)
    at org.owasp.esapi.reference.DefaultSecurityConfiguration.getInstance(DefaultSecurityConfiguration.java:75)
    ... 8 more
Caused by: java.lang.IllegalArgumentException: Failed to load ESAPI.properties as a classloader resource.
    at org.owasp.esapi.reference.DefaultSecurityConfiguration.loadConfigurationFromClasspath(DefaultSecurityConfiguration.java:667)
    at org.owasp.esapi.reference.DefaultSecurityConfiguration.loadConfiguration(DefaultSecurityConfiguration.java:436)
    ... 10 more

我已经尝试复制我的源文件夹中的3个ESAPI属性文件,并在构建路径上配置它们,但仍然没有成功。我尝试了许多排列和组合,但都无济于事。

请给我引路。

属性文件的内容为:

代码语言:javascript
复制
# User Messages
Error.creating.randomizer=Error creating randomizer

This.is.test.message=This {0} is {1} a test {2} message

# Validation Messages

# Log Messages
EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2011-10-08 23:19:18

ESAPI.properties文件中的行数应超过3行。例如,请参阅:

https://web.archive.org/web/20150904064147/http://code.google.com:80/p/owasp-esapi-java/source/browse/trunk/configuration/esapi/ESAPI.properties

根据我的经验,ESAPI.properties文件要么需要与esapi.jar位于同一文件夹中,要么需要编译到资源目录中的jar中。

代码语言:javascript
复制
/resources/ESAPI.properties

我相信任何一个都应该行得通。如果ESAPI在一个位置找不到该文件,它会在其他位置查找。

其代码在第620行:

https://web.archive.org/web/20161005210258/http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/reference/DefaultSecurityConfiguration.java

票数 25
EN

Stack Overflow用户

发布于 2014-10-08 02:54:52

我自己也在挣扎着解决这个问题。

  1. 我在我的C:/users/myname/目录中创建了一个名为esapi的文件夹,并加载了ESAPI.properties、validation.properties和ESAPI AccessControlPolicy.xml,这让我克服了所有找不到文件的错误。ESAPI在多个位置查找文件。顺便说一句,我运行的是64位的Windows7.
  2. ,然后我不得不更新一些jars。我应该从一开始就这么做,但我并不知道。我收到这个错误:对于每个需要更新版本的(org.owasp.esapi.reference.DefaultAccessController),AccessController类jar CTOR都抛出了exception.,比如commons集合或log4j。在堆栈跟踪的底部,它将引用有问题的jar。

当我从esapi lib目录添加更新的jars时,一切都正常了!

我在控制台的末尾收到了这条消息:

代码语言:javascript
复制
ESAPI.accessController found: org.owasp.esapi.reference.DefaultAccessController@1cb8deef

注意:有一个ESAPI_en_US.properties文件,但它只有几行。只需使用\esapi-2.1.0-dist\src\test\resources\esapi\ESAPI.properties.中的文件即可这是完整的文件。

票数 4
EN

Stack Overflow用户

发布于 2014-06-09 21:52:25

在遇到这个问题并查看了安装文档(esapi-x.x.x-dist\documentation\esapi4java-core-x-x-install-guide.pdf)后,我发现了一个非常有用的部分,其中详细说明了属性文件可以在任何地方,只要vm标志(-Dorg.owasp.esapi.resources=path")指向特定的目录。例如,如果我将文件放在项目目录根目录下的"resources“文件夹中,则标志为:

代码语言:javascript
复制
-Dorg.owasp.esapi.resources="path\to\project\root\resources"
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7696423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档