Code Monkey home page Code Monkey logo

spring-nsfn-validation-starter's Introduction

spring-nsfn-validation-starter

Spring实现请求参数敏感词校验,使用Aho–Corasick作为检测算法 项目采用Kotlin实现

外部依赖库:

使用示例:

添加依赖

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}	
dependencies {
    // 低版本gradle使用
    // compile 'com.github.shenluw.spring-nsfn-validation-starter:nsfn-validation-starter:Tag'
    // 版本号查看仓库tag
    implementation 'com.github.shenluw.spring-nsfn-validation-starter:nsfn-validation-starter:Tag'
}

添加注解

@RestController
@Validated
class TestController {

	@RequestMapping("/simple")
	fun test(@Sensitive text: CharSequence?): CharSequence? {
		log.info("simple: {}", text)
		return text
	}
}

配置敏感词

在application.yaml中添加配置,敏感词读取优先级 words > word-file > word-dir

nsfn:
  words: 敏感词,敏感
  word-file: filepath # 敏感词文件路径,一行表示一个词
  word-dir: filedir # 敏感词目录,会读取目录下所有文件内容

也可以自己配置WordStore作为Bean,也可以自定义实现WordStore类,添加不同敏感词的读取策略

@Bean
fun customStore(): MemoryWordStore {
    return MemoryWordStore(hashSetOf("word"))
}

spring-nsfn-validation-starter's People

Contributors

shenluw avatar

Watchers

James Cloos avatar

spring-nsfn-validation-starter's Issues

没过滤成功

配置
nsfn:
words: sex

public CharSequence filter(@sensitive CharSequence text){
return text;
}

text 传sex is good
返回还是sex is good

请问怎么调用?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.