tomcat 7.0.6是否已经支持servlet 3.0规范中的SevletSercurity注释?

发布于 2024-10-14 10:12:40 字数 705 浏览 5 评论 0原文

我试图在tomcat 7.0.6中使用servlet 3.0规范的ServletSecurity注释,但是tomcat服务器似乎不扫描ServletSecurity注释。代码如下,

@WebServlet(name="IndexServlet",urlPatterns={"/index"})
@DeclareRoles("ROLE_ADMIN")
@ServletSecurity(value=@HttpConstraint(rolesAllowed="ROLE_ADMIN"),httpMethodConstraints=@HttpMethodConstraint("GET"))
public class IndexServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request, response);
 }

}

那么有谁在tomcat 7中成功测试过ServletSecurity注解吗?或者tomcat 7还不支持ServletSecurity注解?

我被这个问题困惑了几天,所以有人能帮我解决吗?任何帮助表示赞赏。

I was tring to use the ServletSecurity annotation of servlet 3.0 specification in the tomcat 7.0.6, but it seems that tomcat server doesn't scan the ServletSecurity annotation. The code is following,

@WebServlet(name="IndexServlet",urlPatterns={"/index"})
@DeclareRoles("ROLE_ADMIN")
@ServletSecurity(value=@HttpConstraint(rolesAllowed="ROLE_ADMIN"),httpMethodConstraints=@HttpMethodConstraint("GET"))
public class IndexServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request, response);
 }

}

So is there anyone who has tested the ServletSecurity annotation successfully in tomcat 7? Or the tomcat 7 doesn't support the ServletSecurity annotation yet?

I was confused by the problem for few days, so could someone figure it out for me? Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2024-10-21 10:12:40

您需要删除 httpMethodConstraints=@HttpMethodConstraint("GET")

规范中一个有趣的“功能”是约束是 OR - 而不是 AND。因此,如果您以 GET 方式请求 /index - 安全约束将通过,并且 RolesAllowed 约束将被忽略。

像 SecurityFilter [ http://securityfilter.sourceforge.net/ ] 这样的第三方库可能会做得更好与 Servlet 规范提供的约束处理相比。

You need to remove httpMethodConstraints=@HttpMethodConstraint("GET")

An interesting "feature" in the spec is contraints are OR - not AND. So if you are requesting /index as a GET - the security constraint passes and the rolesAllowed constraint is ignored.

A third party library like SecurityFilter [ http://securityfilter.sourceforge.net/ ] will probably do a better job at constraint handling as compared to what is provided by the Servlet Spec.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文