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

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.

主站蜘蛛池模板: 诏安县| 衡水市| 陆河县| 康保县| 沈阳市| 桦甸市| 麟游县| 塔城市| 南城县| 梅河口市| 延庆县| 扶风县| 兴和县| 额敏县| 明光市| 班玛县| 石泉县| 香河县| 襄城县| 长海县| 南汇区| 汉寿县| 施甸县| 黎城县| 全椒县| 中牟县| 邻水| 黄陵县| 黔东| 法库县| 灵寿县| 潜江市| 大竹县| 勐海县| 县级市| 德格县| 沙田区| 忻州市| 玛曲县| 上思县| 桂东县|