All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.twelvet.xss.core.XssCleanDeserializer Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package cn.twelvet.xss.core;

import cn.twelvet.xss.config.XssProperties;
import cn.twelvet.xss.utils.SpringContextHolder;
import cn.twelvet.xss.utils.XssUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * jackson xss 处理
 *
 * @author twelvet
 */
public class XssCleanDeserializer extends XssCleanDeserializerBase {

	private final static Logger log = LoggerFactory.getLogger(XssCleanDeserializer.class);

	@Override
	public String clean(String name, String text) throws IOException {
		// 读取 xss 配置
		XssProperties properties = SpringContextHolder.getBean(XssProperties.class);
		// 读取 XssCleaner bean
		XssCleaner xssCleaner = SpringContextHolder.getBean(XssCleaner.class);
		if (xssCleaner != null) {
			String value = xssCleaner.clean(XssUtil.trim(text, properties.isTrimText()));
			log.debug("Json property value:{} cleaned up by twelvet, current value is:{}.", text, value);
			return value;
		}
		else {
			return XssUtil.trim(text, properties.isTrimText());
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy