Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. http://localhost:8080/testweb/testOperation
  2.  
  3. http://localhost:8080/testweb/testOperation
  4.  
  5. @RequestMapping(value = "testOperation", method = RequestMethod.GET)
  6. public Map<String, String> testOperation() {
  7. final Map<String, String> model = new LinkedHashMap<String, String>();
  8. return model;
  9. }
  10.  
  11. String ipAddress = request.getHeader("X-FORWARDED-FOR");
  12. if (ipAddress == null) {
  13. ipAddress = request.getRemoteAddr();
  14. }
  15.  
  16. System.out.println(ipAddress);
  17.  
  18. @Component
  19. public class IpCheckingInterceptor extends HandlerInterceptorAdapter {
  20. public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  21. // Your header-checking code
  22. String ipAddress = request.getHeader("X-FORWARDED-FOR");
  23. if (ipAddress == null) {
  24. ipAddress = request.getRemoteAddr();
  25. }
  26. if (<ipAddress not OK>) {
  27. throw new ForbiddenException("You are not allowed to access this page");
  28. }
  29. return true;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement