gpt4 book ai didi

java - ESAPI - 获取具有禁止依赖项的 NoClassDefFoundError (LoggerFactory)

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:42:17 27 4
gpt4 key购买 nike

我正在使用 ESAPI 对字符串值进行编码以解决跨站点脚本问题,如下所示(代码片段)。

String encodedString = ESAPI.encoder().encodeForHTML(value);

异常跟踪

org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException Encoder class (org.owasp.esapi.reference.DefaultEncoder) CTOR threw exception.
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:129)
at org.owasp.esapi.ESAPI.encoder(ESAPI.java:99)
<bold>Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/spi/LoggerFactory</bold>
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:74)
at org.owasp.esapi.ESAPI.logFactory(ESAPI.java:137)
at org.owasp.esapi.ESAPI.getLogger(ESAPI.java:154)
at org.owasp.esapi.reference.DefaultEncoder.<init>(DefaultEncoder.java:75)
at org.owasp.esapi.reference.DefaultEncoder.getInstance(DefaultEncoder.java:59)
... 71 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.spi.LoggerFactory
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

Maven 存储库 pom.xml

<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>${org.owasp.esapi.version}</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
<exclusion>
<groupId>xercesImpl</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
</exclusion>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
<exclusion>
<groupId>org.owasp.antisamy</groupId>
<artifactId>antisamy</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

如果我不排除 log4j 那么它会抛出依赖收敛错误,因为 log4j 是在 maven banned 依赖中声明的,如下所示

<executions>
<execution>
<id>enforce</id>
<configuration>
<rules>
<requireJavaVersion>
<version>${java.version}</version>
</requireJavaVersion>
<requireMavenVersion>
<version>3.0</version>
</requireMavenVersion>
<DependencyConvergence />
<bannedDependencies>
<excludes>
<!-- This should not exist as it will force SLF4J calls to be
delegated to log4j -->
<exclude>org.slf4j:slf4j-log4j12</exclude>
<!-- This should not exist as it will force SLF4J calls to be
delegated to jul -->
<exclude>org.slf4j:slf4j-jdk14</exclude>
<!-- Ensure only the slf4j binding for logback is on the classpath -->
<exclude>log4j:log4j</exclude>
<!-- As recommended from the slf4j guide, exclude commons-logging -->
<exclude>commons-logging:commons-logging</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>

在这方面的帮助将不胜感激。如果您需要更多详细信息,请告诉我。提前致谢!

最佳答案

我升级到最新版本 2.2.1.1 并且我需要在 ESAPI.properties 中添加两个额外的属性(除了 @Carlo 指出的那个) :

ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory
Logger.UserInfo=false
Logger.ClientInfo=false

关于java - ESAPI - 获取具有禁止依赖项的 NoClassDefFoundError (LoggerFactory),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34295088/

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