Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://localhost:8080/testweb/testOperation
- http://localhost:8080/testweb/testOperation
- @RequestMapping(value = "testOperation", method = RequestMethod.GET)
- public Map<String, String> testOperation() {
- final Map<String, String> model = new LinkedHashMap<String, String>();
- return model;
- }
- String ipAddress = request.getHeader("X-FORWARDED-FOR");
- if (ipAddress == null) {
- ipAddress = request.getRemoteAddr();
- }
- System.out.println(ipAddress);
- @Component
- public class IpCheckingInterceptor extends HandlerInterceptorAdapter {
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
- // Your header-checking code
- String ipAddress = request.getHeader("X-FORWARDED-FOR");
- if (ipAddress == null) {
- ipAddress = request.getRemoteAddr();
- }
- if (<ipAddress not OK>) {
- throw new ForbiddenException("You are not allowed to access this page");
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement