我只想用密码保护 Jetty Web 应用程序的上下文路径上的根目录。我的上下文路径是 /MyApp,所以我需要密码才能访问:
http://localhost:8080/MyApp
但不适用于:
http://localhost:8080/MyApp/cometd
我当前的设置如下(注意 url 模式):
<security-constraint>
<web-resource-collection>
<web-resource-name>Private Page</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>moderator</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Test Realm</realm-name>
</login-config>
我希望这能够按照 / 和 /* 一般工作方式的本质起作用。我也看到了这个资源,我相信它表明这应该很有效:http://www.coderanch.com/t/364782/Servlets/java/there-key-difference- Between-url http://www.coderanch.com/t/364782/Servlets/java/there-key-difference-between-url
但是,就我而言,网址模式:
<url-pattern>/</url-pattern>
and
<url-pattern>/*</url-pattern>
似乎表现完全相同:两者
http://localhost:8080/MyApp
and
http://localhost:8080/MyApp/cometd
两者均受密码保护。
当然,如果我更改为 /nothingishere,就像完整性测试一样,除了 /MyApp/nothingishere 之外,没有任何内容受密码保护
有谁知道如何只保护 Web servlet 的根目录?