【问题标题】:Using Stripes Interceptor to prevent access to other servlets使用 Stripes 拦截器阻止对其他 servlet 的访问
【发布时间】:2012-03-20 13:50:29
【问题描述】:

我使用的是 Stripes 1.5,并且我正在使用拦截器(基于 this example)来防止未经授权访问 *.action 页面。

现在我想使用相同的拦截器来阻止对 servlet 的访问。

我已将此添加到 web.xml(DisplayChart 是我要保护的 servlet):

<filter-mapping>
    <filter-name>StripesFilter</filter-name>
    <servlet-name>DisplayChart</servlet-name>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

但是不行,拦截器intercept方法在访问DisplayChart servlet路径时不执行(即使我@Intercepts所有LifeCycleStage)。

有没有办法在访问另一个 servlet 时执行拦截器?或者 Stripes 过滤器不打算以这种方式使用(我必须使用普通的Filter)?

【问题讨论】:

    标签: java servlets stripes


    【解决方案1】:

    我不知道你是否可以将 Stripes 拦截器应用于非 Stripes servlet。

    但我很确定你不应该这样做。

    Stripes 拦截器特定于 Stripes 和 Stripes 的请求生命周期。对普通 servlet 的请求不是 Stripes 请求,并且不会经历此生命周期,即使它通过了 Stripes 过滤器。这样的请求不应该使用 Stripes 拦截器,即使这是可能的。

    我建议您将 Stripes 拦截器中的授权代码分解为与 Stripes 无关的服务类,然后编写一个使用该类的标准过滤器。然后,您的 Stripes 拦截器和过滤器将是非常小的代码,它们会移交给服务。

    【讨论】:

      【解决方案2】:

      Stripes 过滤器不能这样使用,因为 Stripes 过滤器实际上是 Stripes 前端控制器,它只调度操作 bean 和可能在此之前的 Stripes 拦截器。

      正如您已经假设的那样,您需要一个常规的 servlet 过滤器。

      【讨论】:

        猜你喜欢
        • 2019-12-21
        • 1970-01-01
        • 1970-01-01
        • 2014-03-27
        • 1970-01-01
        • 2011-06-07
        • 1970-01-01
        • 2012-06-09
        • 1970-01-01
        相关资源
        最近更新 更多