[英]How to secure a forward URL
有沒有辦法保護轉發URL?
要清楚,我有一個錯誤處理程序:
@Component
public class MyAuthenticationFailureHandler implements
AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest request,
HttpServletResponse response, AuthenticationException exception)
throws IOException, ServletException {
if (exception.getClass().isAssignableFrom(
MyException.class)) {
MyException myException = (MyException) exception;
RequestDispatcher dispatcher = request.getRequestDispatcher("/signup/exception");
request.setAttribute("userID", myException.getUserID());
dispatcher.forward(request, response);
}
}
}
和一個網絡控制器:
@Controller
@RequestMapping("/signup")
public class SignupController {
@RequestMapping("/exception")
public ModelAndView signup() {
ModelAndView model = new ModelAndView(new InternalResourceView("/WEB-INF/jsp/signup.jsp", true));
return model;
}
}
我希望只能從我自己的處理程序中以轉發方式訪問http://{hostname:port}/signup/exception
路由,而不能直接訪問(通過在瀏覽器欄上寫入URL和參數)。
添加類似的屬性
request.setAttribute("isForwarded","True")
在處理程序中,並檢查控制器中的該屬性。
如果是,請繼續執行其他操作,然后重定向到相應的頁面。
我沒有測試它,但是我知道servlet容器拒絕回答相對於WEB-INF的請求,但是您可以轉發到WEB-INF下的jsp servlet。 也許您可以嘗試使用/ WEB-INF / signup / exception之類的網址?
另外,我認為您正在使用Spring Security。 我認為安全過濾器不會應用於轉發的請求。 是什么賦予了以下intercept-url?
<intercept-url pattern="/signup/exception" access="denyAll" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.