url-pattern和通配符 [英] url-pattern and wildcards

查看:317
本文介绍了url-pattern和通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在J2EE应用程序中为Web模块的角色配置安全性约束时,我遇到以下问题:

While configuring the security constraints for a web-module's roles in J2EE application I'm having the following problem:

提供一个名为 customersServlet 的servlet,它在URL中接收两个参数:

Giving a servlet named customersServlet, which receives two parameters in the URL:


  • 表示操作的字符串(INS,UPD,DLT和DSP)。

  • 用于标识将在其上执行操作的客户的标识号。

EG:url / servlet / cusotmersServlet?UPD,5 用于更新客户5号数据,以及url / servlet / customersServlet?DLT,8 用于删除客户编号8.

E.G.: the url /servlet/cusotmersServlet?UPD,5 is used to update customer number 5 data, and the url /servlet/customersServlet?DLT,8 is used to delete customer number 8.

如果我使用这个安全约束,servlet只能被指定的角色访问,这是可以的:

If I use this security-constraint the servlet can only be accessed by the role specified, which is ok:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>...</web-resource-name>
        <url-pattern>/servlet/clientsServlet*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>clientAdmin</role-name>
    </auth-constraint>
</security-constraint>

但我想限制只将客户插入名为 clientAdmin的角色的能力

But I want to restrict the ability to insert customers only to a role named clientAdmin.

我已经尝试了几个url模式,但它们都没有按我的意愿工作(所有这些都允许每个角色使用任何参数访问servlet):

I've tried several url patterns but none of them works as I want (all of them allow every role to access the servlet with any parameter):

<url-pattern>/servlet/clientsServlet?INS,*</url-pattern>
<url-pattern>/servlet/clientsServlet?INS/*</url-pattern>
...

如何使用通配符 * url-pattern 标签中?

How to use the wildcard * in the url-pattern tag?

注意: 应用程序无法更改,因此我需要一个仅涉及触及部署描述符的解决方案。

Note: The application cannot be changed, so I need a solution that only implies touching the deployment descriptor.

推荐答案

< url-pattern> 标记仅允许非常有限的通配符子集。这可能不是您在其他情况下习惯的,其中 * 可以在任何位置使用。你可以在这里下载Servlet规范:

The <url-pattern> tag only allows a very restricted subset of wildcards. This is probably not what you are used to from other situations, where a * can be used at any position. You can download the Servlet specification here:

http://jcp.org/aboutJava/communityprocess/mrel/jsr154/index2.html

该文件的SRV.11.2节描述如何解释这些URL模式。特别是, * 在这里表示零个或多个任意字符。

Section SRV.11.2 of that document describes how these URL patterns are interpreted. In particular, the * does not mean "zero or more arbitrary characters" here.

这篇关于url-pattern和通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆