【问题标题】:Exclude a JSP from web.xml's security-contraint从 web.xml 安全约束中排除 JSP
【发布时间】:2012-01-18 15:35:58
【问题描述】:

我只想从security-constraint 中排除一个JSP 文件question.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>

【问题讨论】:

  • 您可以创建一个文件夹并将其他所有内容(除了 question.jsp)放入该文件夹并使用该模式,例如/securefolder/*.jsp.
  • 我有很多 JSP,所以风险很大。还有其他解决方案吗?

标签: java security jsp tomcat web


【解决方案1】:

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

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

【讨论】:

  • This blog entry 是一篇关于该主题的好文章。您需要一种比安全模式更具体的模式才能公开一些资源。
【解决方案2】:

解决此问题的一种方法是将所有安全 JSP 内容移动到特定目录路径(例如 /protected/ 从 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 保留在默认 docroot 上或根据需要保留到其他目录路径。

【讨论】:

  • 感谢您的回复,我想过这个解决方案,但我无法应用它,我有这么多 JSP,所以风险很大。还有其他解决方案吗?
  • @naj_ib 我不明白为什么你认为它比仅仅提及*.jsp
  • 因为web项目很大,我不需要一个jsp来操作那个解决方案
  • 是的,所以最好的方法是通过路径将您的安全文件与非安全文件分开。并对我的回答中提到的不同路径中的工件应用不同的安全约束。
猜你喜欢
  • 1970-01-01
  • 2012-11-21
  • 1970-01-01
  • 2012-11-23
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多