我有一个 Java 网络应用程序。 webapp 被打包为一个 war 文件。这些 war 文件允许静态内容,直接通过 HTTP 传递。对于这场 war 中的 servlet,我可以进行 HTTP 身份验证(使用 servlet 本身来实现)。但我还想要对静态内容进行 HTTP 身份验证。我怎样才能实现这一点?
最佳答案
将静态 html 文件放入目录中,并在 web.xml 中定义安全约束。将约束映射到适当的角色。
<security-constraint>
<display-name>securedResources</display-name>
<web-resource-collection>
<web-resource-name>securedRes</web-resource-name>
<url-pattern>/secured/*</url-pattern>
<http-method>GET</http-method>
<http-method>PUT</http-method>
<http-method>HEAD</http-method>
<http-method>TRACE</http-method>
<http-method>POST</http-method>
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
</web-resource-collection>
<auth-constraint>
<description>
authenticatedUser_securedRes</description>
<role-name>authenticatedUsed</role-name>
</auth-constraint>
</security-constraint>
关于java - 在 Java-webapp (war) 中,如何对静态内容使用 HTTP 身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/825142/