Java web.xml中的动态安全性约束配置

时间:2012-04-02 16:03:32

标签: java security tomcat constraints security-constraint

我目前有一个REST API,必须通过BasicAuth进行身份验证,但后来还有其他一些方法。

在Tomcat 6中使用领域进行设置,我在web.xml中有以下内容,

<security-constraint>
    <web-resource-collection>
        <web-resource-name>document</web-resource-name>
        <url-pattern>/rest/document/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>document</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
    <Realm-name>Tomcat-Advance-Authentication-Realm</Realm-name>
</login-config>

这适用于/rest/document/*等网址。

我的问题是,有没有人知道是否有可能或如何在不构建和重新部署的情况下动态定义其他URL?

例如另一个安全约束,

<security-constraint>
    <web-resource-collection>
        <web-resource-name>secure</web-resource-name>
        <url-pattern>/rest/secure/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>secure</role-name>
    </auth-constraint>
</security-constraint>

由于

1 个答案:

答案 0 :(得分:2)

每当您对web.xml进行更改时,都需要重新启动Web应用程序以获取这些更改。

如果您需要动态安全性约束,请考虑构建自定义可配置过滤器和相关属性文件,以便定义受保护资源(例如)。