我目前有一个必须通过 BasicAuth 进行身份验证的 REST API,但后来有一些其他方法。
它是在 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。
我的问题是,有谁知道是否可以或如何在不构建和重新部署的情况下动态定义其他 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>
谢谢
最佳答案
每当您对 web.xml 进行更改时,都需要重新启动 Web 应用程序以获取这些更改。
如果您需要动态安全约束,请考虑构建一个自定义的可配置过滤器和一个相关的属性文件,您可以在其中定义 protected 资源(例如)。
关于java - Java web.xml 中的动态安全约束配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9979739/