gpt4 book ai didi

java - 简单的 ESAPI 目录路径验证示例不起作用

转载 作者:行者123 更新时间:2023-12-02 09:40:13 25 4
gpt4 key购买 nike

我构建了一个 ESAPITestValidator 类,如下所示:

public class ESAPITestValidator {

Validator instance = ESAPI.validator();
ValidationErrorList errors = new ValidationErrorList();
File parent = null;
String path = new String("");
boolean status = false;
public boolean testGetValidDirectoryPath(String inputPath,String context)
{
try
{
parent = new File(inputPath).getParentFile().getCanonicalFile();
//String parent = ESAPI.securityConfiguration().getResourceFile("ESAPI.properties").getParentFile().getCanonicalPath();
path = instance.getValidDirectoryPath(context, inputPath, parent, true, errors);
status = true;
return status;
}catch(Exception exception)
{
exception.printStackTrace();
status= false;
}
return status;
}

}

现在我尝试从主类调用 testGetValidDirectoryPath() ,如下所示:

public class HelloWorld {


public static void main(String[] args) {
ESAPITestValidator obj = new ESAPITestValidator();
if ( obj.testGetValidDirectoryPath("C:\\Users\\1730176\\Downloads","C:\\Users") )
System.out.println("Success");
else
System.out.println("Failure");
}

}

我还将 ESAPI.properties 和 Validation.properties 上传到与主类和 validator 类相同的源文件夹中。但我遇到以下异常:

System property [org.owasp.esapi.opsteam] is not set
System property [org.owasp.esapi.devteam] is not set
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:\Arindam_Workspace\ESAPI_Workspace\ESAPIProofOfConcept\ESAPI.properties
Not found in SystemResource Directory/resourceDirectory:
.esapi\ESAPI.properties
Found in 'user.home' directory: C:\Users\1730176\esapi\ESAPI.properties
Loaded 'ESAPI.properties' properties file
SecurityConfiguration for Validator.ConfigurationFile.MultiValued not found
in ESAPI.properties. Using default: false
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:
D:\Arindam_Workspace\ESAPI_Workspace\ESAPIProofOfConcept\
validation.properties
Not found in SystemResource Directory/resourceDirectory:
.esapi\validation.properties
Found in 'user.home' directory: C:\Users\1730176\esapi\validation.properties
Loaded 'validation.properties' properties file
Exception in thread "main" java.lang.NoClassDefFoundError:
javax/servlet/http/HttpServletRequest
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getMethod0(Class.java:2670)
at java.lang.Class.getMethod(Class.java:1603)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:77)
at org.owasp.esapi.ESAPI.validator(ESAPI.java:191)
at main.utility.ESAPITestValidator.<init>(ESAPITestValidator.java:20)
at main.core.HelloWorld.main(HelloWorld.java:16)
Caused by: java.lang.ClassNotFoundException:
javax.servlet.http.HttpServletRequest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 8 more

任何人都可以质疑我所做的事情还是我错过了什么?

最佳答案

JVM 正在寻找 javax/servlet/http/HttpServletRequest 类,而您尚未将其加载到类路径中。您将需要包含 java servlet API 的实现在类路径上。请记住,ESAPI 是一个基于 Web 的库,如果您克隆实际的 esapi-java-legacy 项目并使用其中的单元测试,您可能会更轻松地进行测试。

关于java - 简单的 ESAPI 目录路径验证示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57144828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com