从web.xml的安全约束中排除JSP

问题描述:

我想从security-constraint只排除一个JSP文件question.jsp从web.xml的安全约束中排除JSP

我有这个从我的web.xml

<security-constraint> 
    <display-name>My Security Constraint</display-name> 
    <web-resource-collection> 
     <web-resource-name>Protected Area</web-resource-name>  
     <url-pattern>*.do</url-pattern> 
     <url-pattern>*.jsp</url-pattern> 
    </web-resource-collection> 
    <auth-constraint>  
     <role-name>*</role-name> 
    </auth-constraint> 
</security-constraint> 
+0

您可以创建一个文件夹并将其他所有内容(question.jsp除外)放在该文件夹中并使用该模式,例如'/ securefolder/*。jsp'。 –

+0

我有这么多的JSP,所以它非常危险。还有其他解决方案吗? –

一种方式去了解这是你所有的安全JSP内容移动到特定的目录路径(比如/从Web根保护/)然后你的web.xml的内容将是这样的:

<security-constraint> 
    <display-name>My Security Constraint</display-name> 
    <web-resource-collection> 
     <web-resource-name>Protected Area</web-resource-name>  
     <url-pattern>/protected/*.jsp</url-pattern> 

的要求,则可以留在默认文档根目录或其他目录路径的公共的JSP。

+0

感谢您的回应,我想到了这个解决方案,但是我无法应用它,我拥有这么多的JSP,所以它非常危险。还有其他解决方案吗? –

+0

@naj_ib我不明白为什么你认为它比冒险提高'* .jsp' –

+0

因为web项目是非常大的,我不需要操作该解决方案只有一个jsp –

只需添加一个免费页面部分,而不提供任何验证约束。它将优先于受保护的页面:

<security-constraint> 
    <web-resource-collection> 
    <web-resource-name>free pages</web-resource-name> 
    <url-pattern>/question.jsp</url-pattern> 
    </web-resource-collection> 
</security-constraint> 
+2

这对我有效。 –

+0

[此博客文章](http://blog.mafr.de/2011/04/17/excluding-pages-from-auth/)是关于这个话题的一篇很好的文章。你需要一个比安全的模式更具体的模式,以便公开一些资源。 – cheffe