gpt4 book ai didi

JSF 和 PrettyFaces - 如何限制直接的 xhtml 请求

转载 作者:行者123 更新时间:2023-12-04 11:29:34 26 4
gpt4 key购买 nike

我是 JSF 和 PrettyFaces 的新手。所以现在我发现我可以配置 PrettyFaces 将请求“转发”到正确的 .xhtml 文件。问题是,我(或用户,以防他知道我的文件夹结构)也可以请求该文件。这是我的样本:

文件:
webbapp/mypage.xhtml

我在pretty-config.xml 中添加了以下几行:

<url-mapping id="myPageId">
<pattern value="/prettyurltomypage" />
<view-id value="/mypage.xhtml" />
</url-mapping>

PrettyFaces 过滤器配置为拦截“/”。 Faces Front Controller 配置为处理所有“.xhtml”请求。当我请求...
http://localhost:8080/myapp/prettyurltomypage

......一切都很好。我的问题是,我也可以要求...
http://localhost:8080/myapp/mypage.xhtml

如何限制 .xhtml 请求?我的目标是让 jsf/server 提供默认的 404 页面。

我的解决方案(到目前为止)是在pretty-config.xml 中定义一个重写规则:
<rewrite match="/mypage.xhtml" substitute="/prettyurltomypage" redirect="301" />

还有其他(更聪明的)方法吗?

最佳答案

这可以通过在部署描述符中将 XHTML 文件标记为 Web 资源来完成。
为此,您可以在 中添加类似的内容。 web.xml :

<security-constraint>
<display-name>Restrict direct access to XHTML files</display-name>
<web-resource-collection>
<web-resource-name>XHTML files</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>

如果您想阅读有关安全约束的更多信息,这里有一个简短的 article在 Javalobby 上。

关于JSF 和 PrettyFaces - 如何限制直接的 xhtml 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6924105/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com