使用esapi报错解决方法

来源:互联网 发布:seo设置是什么意思 编辑:程序博客网 时间:2024/05/22 12:23

使用esapi时报错:

Not found in 'org.owasp.esapi.resources' directory or file not readable: C:\Users\ccg\Desktop\esapi\ESAPI.properties

Not found in SystemResource Directory/resourceDirectory: .esapi\ESAPI.properties
Not found in 'user.home' (C:\Users\ccg) directory: C:\Users\ccg\esapi\ESAPI.properties
Loading ESAPI.properties via file I/O failed. Exception was: java.io.FileNotFoundException

Exception in thread "main" org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException SecurityConfiguration class (org.owasp.esapi.reference.DefaultSecurityConfiguration) CTOR threw exception.
Attempting to load ESAPI.properties via the classpath.
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:129)
ESAPI.properties could not be loaded by any means. Fail. Exception was: java.lang.IllegalArgumentException: Failed to load ESAPI.properties as a classloader resource.


解决方法:将esapi.jar添加到项目之后,还要引入ESAPI.properties和validation.properties两个文件。

如何引入这两个文件,第一种方法:建立一个Resources类型的文件夹,把这两个文件直接甩里面即可。

第二种方法:在myeclipse中,选中某个项目,然后在工具栏中选择"Run-->Run Confgurations“,然后在对话框的右边选择"Arguments,然后在VM arguments中输入

 -Dorg.owasp.esapi.resources=C:/Users/ccg/Desktop/esapi/resources(这个是我电脑里面ESAPI.properties和validation.properties文件的路径)。
idea中 选中run-->edit configurations 在configuration选项卡中的vm options中添加 -Dorg.owasp.esapi.resources=C:/Users/ccg/Desktop/esapi/resources(这个是我电脑里面ESAPI.properties和validation.properties文件的路径)。


第二种方法的解决思路:单步跟踪源码,发现报错位置在DefaultSecurityConfiguration.class中 
if(customDirectory != null && f.canRead()) {    this.logSpecial("Found in \'org.owasp.esapi.resources\' directory: " + f.getAbsolutePath());    return f;} else {    this.logSpecial("Not found in \'org.owasp.esapi.resources\' directory or file not readable: " + f.getAbsolutePath()); 其中有:
private static String customDirectory = System.getProperty("org.owasp.esapi.resources");
查资料得:
我的理解是这样的,在myeclipse中,选中某个项目,然后在工具栏中选择"Run-->Run Confgurations“,然后在对话框的右边选择"Arguments,然后在VM arguments中输入-Dproperty.name=value,这样,在你的代码中使用System.getProperty(property.name)即可以获取value的值。
希望可以帮助到你们。

0 0
原创粉丝点击