저는 스프링 MVC 컨트롤러 프로젝트를 진행하고 있습니다. 두 JSP 페이지에 보안을 추가하려고합니다. 의미 나는 요청에서 나오는 IP 주소를 가로 채고 그 IP 주소가 유효한 IP 주소인지 여부를 확인합니다. 유효한 IP 주소가 아닌 경우 오류 JSP 페이지를 표시하십시오.@ExceptionHandler를 Spring 인터셉터와 함께 두 JSP 페이지에 사용하는 방법은 무엇입니까?
저는이 보안을 두 개의 JSP 페이지에 추가하고 있습니다. 그래서 잘못된 IP 주소 호출에 대한 위의 두 jsp 호출에 대해 다른 오류 메시지를 표시하려고합니다.
마자 브라우저에 URL을 아래 공격으로 유효한 IP 주소 전화의 경우, 내 testOperation
및 testProcess
JSP 페이지를 표시합니다 -
http://localhost:8080/testweb/testOperation
http://localhost:8080/testweb/testProcess
그래서 나는이의 인터셉터를 구현하고 구성 봄 XML의 MVC 인터셉터. 이제 아래 코드와 함께 올바른 IP 주소를 확인합니다. 내의 context.xml 파일에서
@Component
public class IpCheckingInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String requestURI = request.getRequestURI();
System.out.println(requestURI);
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}
if (!isValid(ipAddress) && requestURI.equalsIgnoreCase("/testweb/testOperation")) {
// need to show a proper error message on the jsp
return false;
} else if (!isValid(ipAddress) && requestURI.equalsIgnoreCase("/testweb/testProcess")) {
// need to show a below JSON response as an error on the browser
// {"response":"You are not authorized to make a call.","error":"AUTHORIZATION_ERROR","status":"ERROR"}
return false;
}
return true;
}
}
-
<mvc:interceptors>
<bean class="com.testing.interceptor.IpCheckingInterceptor" />
</mvc:interceptors>
이 어쨌든 할 수 있습니까? 이제 위에서 언급 한 것처럼 어떤 페이지가 호출되었는지에 따라 잘못된 IP 주소 호출에 대해 다른 오류 JSP 메시지를 표시해야합니다. 이 작업을 수행하는 가장 좋은 방법은 무엇입니까?
가능한 경우 다른 JSP 페이지로 리디렉션하고 싶지 않습니다. 같은 페이지에 있고 가능한 경우 오류 메시지를 적절히 표시하고 싶습니다.