小编Dre*_*wch的帖子

将jetty url-pattern匹配到只有根目录

我想只在密码保护Jetty WebApp的上下文路径上的根目录.我的上下文路径是/ MyApp,所以我想要一个密码来访问:

http://localhost:8080/MyApp
Run Code Online (Sandbox Code Playgroud)

但不是:

http://localhost:8080/MyApp/cometd
Run Code Online (Sandbox Code Playgroud)

我目前的设置如下(注意网址格式):

<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>
Run Code Online (Sandbox Code Playgroud)

我希望这只能通过/和/*工作的性质来发挥作用.我也看到过这个资源,我认为这表明这应该起作用了:http://www.coderanch.com/t/364782/Servlets/java/there-key-difference-between-url

但是,对于我的情况,网址模式:

<url-pattern>/</url-pattern>
Run Code Online (Sandbox Code Playgroud)

<url-pattern>/*</url-pattern>
Run Code Online (Sandbox Code Playgroud)

似乎表现得完全一样:两者兼而有之

http://localhost:8080/MyApp 
Run Code Online (Sandbox Code Playgroud)

http://localhost:8080/MyApp/cometd
Run Code Online (Sandbox Code Playgroud)

两个密码保护.

当然,如果我改为/ nothingishere,就像一个完整性测试一样,没有任何密码保护,除了/ MyApp/nothingishere

有谁知道如何只保护Web servlets的根目录?

passwords servlets web-applications jetty cometd

8
推荐指数
1
解决办法
3066
查看次数

标签 统计

cometd ×1

jetty ×1

passwords ×1

servlets ×1

web-applications ×1