使用 Java EE 部署描述符来定义缺少的安全角色

此规则会标记在 WEB-INF/web.xml 文件中找到的 auth-constraintrole-name 元素,这些元素缺少相应的 security-role 元素。 Apache Tomcat 服务器不要求定义 security-role 元素,但 Java EE 规范表明必须定义该元素。

这里举例说明了会进行标记的 auth-constraintrole-name 元素:
<web-app>
...
<security-constraint>
<display-name>ThisConstraint</display-name>
<web-resource-collection>
<web-resource-name>adminResources</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<description>The admins</description>
<role-name>admin</role-name>
<role-name>superuser</role-name>
</auth-constraint>
</security-constraint>
</web-app>

会同时标记 <role-name>admin</role-name><role-name>superuser</role-name> 行。

源扫描程序包含一个快速修订,该快速修订会添加任何缺少的 security-role 元素。

在本示例中,该快速修订会将下列元素添加至 web.xml 文件:
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>superuser</role-name>
</security-role>