官术网_书友最值得收藏!

Configuring custom servlet filters

In a real-world web application, we almost always find a need to add facades or wrappers to service requests, to log them, filter out bad characters for XSS, perform authentication, and so on. Out of the box, Spring Boot automatically adds OrderedCharacterEncodingFilter and HiddenHttpMethodFilter, but we can always add more. Let's see how Spring Boot helps us achieve this task.

Among the various assortments of Spring Boot, Spring Web, Spring MVC, and others, there is already a vast variety of different servlet filters that are available and all we have to do is define them as beans in the configuration. Let's say that our application will be running behind a load balancer proxy and we would like to translate the real request IP that is used by the users instead of the IP from the proxy when our application instance receives the request. Luckily, Apache Tomcat 8 already provides us with an implementation: RemoteIpFilter. All we will need to do is add it to our filter chain.

主站蜘蛛池模板: 石家庄市| 大田县| 昭苏县| 奉贤区| 民和| 吴川市| 陆河县| 若羌县| 龙门县| 阆中市| 和平区| 扶余县| 浦江县| 汝阳县| 马山县| 河源市| 汝阳县| 建德市| 磐安县| 五河县| 马边| 健康| 多伦县| 长汀县| 新河县| 长武县| 屏山县| 昆明市| 永顺县| 肇源县| 太保市| 呼玛县| 石渠县| 尤溪县| 德江县| 凤阳县| 隆昌县| 临汾市| 西城区| 泗洪县| 曲阜市|