简体   繁体   English

如何保护转发URL

[英]How to secure a forward URL

Is there a way to secure a forward URL? 有没有办法保护转发URL?

To be clear, I've an error handler: 要清楚,我有一个错误处理程序:

@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);
        }
    }

}

and a web controller: 和一个网络控制器:

@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;
    }

}

I'd like that the route http://{hostname:port}/signup/exception will be accessible only as forward from my own handler, not directly (by writing URL and params on browser bar). 我希望只能从我自己的处理程序中以转发方式访问http://{hostname:port}/signup/exception路由,而不能直接访问(通过在浏览器栏上写入URL和参数)。

Add an attribute like 添加类似的属性

request.setAttribute("isForwarded","True")

in handler and check that attribute inside your controller. 在处理程序中,并检查控制器中的该属性。

If yes, go ahead else redirect to appropriate page. 如果是,请继续执行其他操作,然后重定向到相应的页面。

I didn't test it, but I know that servlet containers refuse to answer to request relative to WEB-INF, but that you can forward to jsp servlets under WEB-INF. 我没有测试它,但是我知道servlet容器拒绝回答相对于WEB-INF的请求,但是您可以转发到WEB-INF下的jsp servlet。 May be you could try to use an url like /WEB-INF/signup/exception ? 也许您可以尝试使用/ WEB-INF / signup / exception之类的网址?

Alternatively, I think you're using Spring Security. 另外,我认为您正在使用Spring Security。 I do not think that security filters are applied to forwarded requests. 我认为安全过滤器不会应用于转发的请求。 What gives the following intercept-url ? 是什么赋予了以下intercept-url?

<intercept-url pattern="/signup/exception" access="denyAll" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM