使用esapi时发生java错误
我正在尝试在我的项目中使用OWASP ESAPI。但问题是owasp文档对我来说太复杂了。我正在尝试使用esapi的验证,但即使没有错误,也无法得到结果
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Validator;
public void security(String s) {
System.out.println("connect 1");
Validator instance = ESAPI.validator();
System.out.println("connect 2");
System.out.println(instance.isValidInput("test", "xxxxx@gmail.com", "Email", 100, false));
}
如果我尝试运行3次,结果如下:
connect 1
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: C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\ESAPI.properties
Not found in SystemResource Directory/resourceDirectory: .esapi\ESAPI.properties
Found in 'user.home' directory: C:\Users\xxxx\esapi\ESAPI.properties
Loaded 'ESAPI.properties' properties file
Attempting to load validation.properties via file I/O.
Attempting to load validation.properties as resource file via file I/O.
Not found in 'org.owasp.esapi.resources' directory or file not readable: C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\validation.properties
Not found in SystemResource Directory/resourceDirectory: .esapi\validation.properties
Found in 'user.home' directory: C:\Users\xxxx\esapi\validation.properties
Loaded 'validation.properties' properties file
connect 1
connect 1
正如您所看到的,没有错误,属性加载正确。我的问题是它为什么停在那里。为什么不打印“连接2”?以及为什么会出现实例的结果。ValidInput是否也未打印
# 1 楼答案
您没有在ESAPI配置中正确设置ESAPI资源路径。一旦你做到了这一点,你应该是金色的
请尝试以下链接:
ESAPI Resource Directory setup
# 2 楼答案
为了进行验证,我直接在需要验证用户输入的地方使用了这段代码
你可能有这样的东西
//调用类/对象
啊。安全 这个代码对我来说很有用。有关NetBean及其属性文件的配置,请查看this url
# 3 楼答案
很好,你正在使用ESAPI。首先,这个项目是maven、eclipse、ant还是其他什么?每个类型都有两个属性文件的特定位置,以便在第一次调用ESAPI时在运行时加载它们。浏览谷歌上的ESAPI instal指南。但从日志中可以明显看出,两个文件都已成功加载。发布文件中可能包含的更多日志。问题可能是您正在验证并试图使用getVAlidInput()方法获取电子邮件地址,但使用了错误的正则表达式。从文件和控制台发布完整的正则表达式代码和异常日志