我是 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" />
还有其他(更智能)的方法吗?
I'm new to JSF and PrettyFaces. So by now i found out that i can configure PrettyFaces to "forward" the request to the right .xhtml file. The problem is, that i (or a user, in case he knows my folder structure) also can request the file. This is my sample:
Files:
webbapp/mypage.xhtml
I added the following lines to pretty-config.xml:
<url-mapping id="myPageId">
<pattern value="/prettyurltomypage" />
<view-id value="/mypage.xhtml" />
</url-mapping>
The PrettyFaces Filter is configured to intercept on "/". The Faces Front Controller is configured to process all ".xhtml" requests. When i request...
http://localhost:8080/myapp/prettyurltomypage
...evrything is fine. My problem is, that i can also request...
http://localhost:8080/myapp/mypage.xhtml
How can i restrict the .xhtml requests? My goal is to make jsf/server deliver the default 404 page.
My solution (so far) was to define a rewrite rule in pretty-config.xml:
<rewrite match="/mypage.xhtml" substitute="/prettyurltomypage" redirect="301" />
Is there any other (smarter) way?
发布评论
评论(3)
这可以通过在部署描述符中将 XHTML 文件标记为 Web 资源来完成。
为此,您可以在 web.xml 中添加如下内容:
如果您想了解有关安全约束的更多信息,这里有一个简短的 关于 Javalobby 的文章。
It can be done by marking XHTML files as web resources in your deployment descriptor.
To do so, you may add something like this to your web.xml:
If you'd like to read more about security constraints there's a brief article on Javalobby.
是的,如果您只是想阻止对直接页面的访问,那么这可能是不使用自定义安全包之类的东西的最佳方法 - 否则,如果您只是想确保页面正确呈现。实际上,您只需将 faces servlet 映射更改为 .xhtml,这意味着当人们访问页面时,您的源代码不会被暴露。
如果您想要执行更复杂的重写规则以实际锁定页面,您可以考虑使用自定义重写处理器并实现 Processor 接口。
http://ocpsoft.com/docs/prettyfaces/ 3.3.0/en-US/html_single/#inbound_rewriting.options
自定义处理器可以访问 HttpServletRequest 和 HttpServletResponse 并调用两者入站和出站重写:您可以使用此接口做更复杂的事情:
否则,您正在做的事情将会起作用,直到 OCPSoft Rewrite https://github.com/ocpsoft/rewrite(谁也是 PrettyFaces 的幕后推手)已发布,在这种情况下,您可以使用简单的入站重写规则轻松完成此操作:
此重写规则将阻止对入站的访问HTTP 请求在 .XHTML 文件上,同时仍然允许转发、错误或异步请求。它还将使 JSF2 资源 API 处于功能状态,如果您按照另一个答案中的建议使用 Java EE 安全约束,则情况并非如此。
希望这有帮助,
林肯
Yeah, if you just want to block access to direct pages, that's probably the best way to go without using something like a custom security package - otherwise, if you just want to make sure the pages are rendered correctly. You can actually just change your faces servlet mapping to .xhtml, which means that your source will not be exposed when people access pages.
If you want to do more complicated rewrite rules in order to actually lock down the pages, you could consider using a custom rewrite processor and implement the Processor interface.
http://ocpsoft.com/docs/prettyfaces/3.3.0/en-US/html_single/#inbound_rewriting.options
Custom processors have access to the HttpServletRequest and HttpServletResponse and invoke both on inbound and outbound rewrites: You can do more complicated things with this interface:
Otherwise, what you are doing will work, and until OCPSoft Rewrite https://github.com/ocpsoft/rewrite ( Who are also behind PrettyFaces ) is released, in which case you could do this pretty easily with a simple inbound rewrite rule:
This Rewrite rule will block access to inbound HTTP requests on .XHTML files, while still allowing forwarded, or error, or async requests. It will also leave the JSF2 resources API in a functional state, which is not the case if you use the Java EE Security Constraint as suggested in another answer.
Hope this helps,
Lincoln
请参阅以下问题:
http://code.google.com/p/prettyfaces/issues/detail ?id=116
希望这对您有帮助
See the following Issue:
http://code.google.com/p/prettyfaces/issues/detail?id=116
Hope this will help you