我正在使用ESAPI库在我的代码中编码名称变量。我的项目是在spring上实现的。
ESAPI.encoder()。encodeForSQL(new OracleCodec(),name);
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.codecs.Codec;
import org.owasp.esapi.codecs.MySQLCodec;
import org.owasp.esapi.reference.DefaultEncoder;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
public class StringJdbcDao extends JdbcDaoSupport{
public void execute(){
BufferedReader r = new BufferedReader(new InputStreamReader(sqlDDL));
try {
// read the first line, skipping any '--' comment lines
boolean firstLine = true;
StringBuffer buf = new StringBuffer();
for (String line = r.readLine(); line != null; line = r.readLine()) {
**line = ESAPI.encoder().encodeForSQL(new MySQLCodec(MySQLCodec.MYSQL_MODE), line.trim());**
getSpringJdbcTemplate().execute(line);
}
}
我收到以下错误。
org.springframework.beans.factory.BeanCreationException:错误 用名字创建bean 'org.sakaiproject.genericdao.test.GenericDaoTarget'在课堂上定义 path资源[spring-jdbc.xml]:调用init方法失败; 嵌套异常是 org.springframework.beans.factory.BeanInitializationException: DAO初始化失败;嵌套异常是 org.owasp.esapi.errors.ConfigurationException: java.lang.reflect.InvocationTargetException SecurityConfiguration class(org.owasp.esapi.reference.DefaultSecurityConfiguration)CTOR 扔了例外。在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory $ 1.run(AbstractAutowireCapableBeanFactory.java:409) 在java.security.AccessController.doPrivileged(Native Method)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) 在 org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:264) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)