2012-03-19 19 views
0

我試圖使用tomcats安全約束來保護我的web應用程序。因此我添加了一個文件夾「prot」,我想通過web.xml中的url-pattern來保護它。當我將標籤更改爲<url-pattern>/prot</url-pattern>時,我的登錄頁面不出現,因此我想保護的文件。我改變路徑<url-pattern>/*</url-pattern>頁面登錄頁面出現,但沒有任何JavaScript我定義在一個單獨的文件(這是從tomcat阻止?)。 在上下文中,我添加了路徑/ mywebapp/prot。我如何確保文件夾保護?提前致謝!Tomcat的url模式問題

回答

2

默認情況下,您應該保護您的安全並取消安全措施。

約束必須從最具體到最通用的web.xml中聲明,以便您匹配最具體的第一個。

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Unsecure resources</web-resource-name> 
     <url-pattern>/unsecure</url-pattern> 
    </web-resource-collection> 
</security-constraint> 

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Secure resources</web-resource-name> 
     <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>authenticated</role-name> 
    </auth-constraint> 
</security-constraint> 
+0

非常好!它工作正常! – Poessl 2012-03-20 22:21:21

+0

然後請將問題標記爲已解決 – 2012-03-21 05:45:01

+0

這並不是那麼直截了當,僅僅存在''決定了安全與否,但它確實在第二眼看起來確實有意義。 – 2017-08-16 16:40:43