Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web applications 仅将jetty url模式与根目录匹配_Web Applications_Servlets_Passwords_Jetty_Cometd - Fatal编程技术网

Web applications 仅将jetty url模式与根目录匹配

Web applications 仅将jetty url模式与根目录匹配,web-applications,servlets,passwords,jetty,cometd,Web Applications,Servlets,Passwords,Jetty,Cometd,我只想对Jetty WebApp的上下文路径上的根目录进行密码保护。我的上下文路径是/MyApp,因此我需要密码才能访问: http://localhost:8080/MyApp 但不是为了: http://localhost:8080/MyApp/cometd 我当前的设置如下(请注意url模式): 及 都有密码保护 当然,如果我改为/nothingishere,就像一个正常测试一样,除了/MyApp/nothingishere之外,没有任何东西是受密码保护的 有人知道如何只保护web s

我只想对Jetty WebApp的上下文路径上的根目录进行密码保护。我的上下文路径是/MyApp,因此我需要密码才能访问:

http://localhost:8080/MyApp
但不是为了:

http://localhost:8080/MyApp/cometd
我当前的设置如下(请注意url模式):

都有密码保护

当然,如果我改为/nothingishere,就像一个正常测试一样,除了/MyApp/nothingishere之外,没有任何东西是受密码保护的


有人知道如何只保护web servlet的根目录吗?

以下是答案:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <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>
    <security-constraint>   
        <web-resource-collection>
            <web-resource-name>Public page</web-resource-name>
            <url-pattern>/test/*</url-pattern>
        </web-resource-collection>        
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Test Realm</realm-name>
    </login-config>
</web-app>

30
私人网页
/
调解人
公共页
/试验/*
基本的
测试领域
在此配置中,根目录受密码保护,而
/test/…
目录不受密码保护。我想这就是你想要的

此配置在Tomcat7+上进行了测试,并且从一开始就在NetBeans中创建了一个新项目(如果您需要,我可以通过电子邮件向您发送整个源代码)

这是输出:

谢谢,这正是我想要的。对我来说也很有用:)24小时一到,我就给悬赏。当然,这个答案不仅适用于jetty,也适用于所有符合j2ee的web服务器。所以你可能想改变标题。。。顺便说一句,很高兴我能帮上忙。有一种方法不需要白名单所有的子路径?即,让所有的子路径都不受保护,而必须一个接一个地为它们添加安全约束。
<url-pattern>/</url-pattern>
<url-pattern>/*</url-pattern>
http://localhost:8080/MyApp 
http://localhost:8080/MyApp/cometd
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <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>
    <security-constraint>   
        <web-resource-collection>
            <web-resource-name>Public page</web-resource-name>
            <url-pattern>/test/*</url-pattern>
        </web-resource-collection>        
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Test Realm</realm-name>
    </login-config>
</web-app>