【问题标题】:Spring Security 3 and JSF 2 integration without redirecting pageSpring Security 3 和 JSF 2 集成,无需重定向页面
【发布时间】:2012-07-02 05:50:08
【问题描述】:

是否可以集成 Spring Security 3 和 JSF 2,保持 JSF 默认工作,而不是在用户导航时显示新 url,保留旧 url,不使用 redirect JSF 属性浏览页面?

我找不到有关此的文档。我发现作者的所有文章在导航时都会重定向页面。

谢谢

【问题讨论】:

  • 你能更明确地举个例子吗?
  • Spring 使用 url 来检查页面是否安全。默认情况下,在 JSF 中,当您单击按钮导航到另一个页面时,url 不会更改

标签: jsf-2 spring-security


【解决方案1】:

默认情况下,FilterSecurityInterceptor 只会对每个请求执行一次,并且不会进行安全重新检查,除非 url 发生更改,但使用 JSP/JSF 转发页面将呈现为对当前请求的响应,并且浏览器中的url包含上一页的地址。因此,为此只需在 applicationContext 中的 http 元素中将每次请求属性设置为 false,从而强制重新检查安全性。

<http auto-config="true" use-expressions="true" once-per-request="false">

并在 web.xml 中的 springSecurityFilterChain 过滤器映射中添加转发器

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

更多info

或者,您还可以通过将参数 faces-redirect=true 附加到结果中来启用页面重定向,如下所示:

<h:form>
    <h:commandButton action="page1?faces-redirect=true" value="Page1" />
</h:form>

但也请记住,在您的情况下,GET 请求看起来更合适,正如 BalusC 所说,它不是使用 POST 进行可书签页面到页面导航的好习惯。

使用&lt;h:link&gt;&lt;h:button&gt;或 faces-redirect=true 的 GET 也会导致 GET 请求。

另见:

【讨论】:

  • 抱歉耽误了测试。它没有奏效。我仍然需要使用 faces-redirect=true 来保证安全性。
  • 我会接受你的回答,但我总是需要做 page1?faces-redirect=true 即使有所有这些配置。
  • 是的 Ed,很抱歉我会更广泛地测试它并使用 Spring 打开一个错误。或者,如果您认为您已经完成了足够的研究,请在他们的网站上发布错误并告诉我。
猜你喜欢
  • 1970-01-01
  • 2015-06-29
  • 1970-01-01
  • 2011-11-20
  • 1970-01-01
  • 2012-04-25
  • 2012-08-19
  • 2013-04-26
  • 1970-01-01
相关资源
最近更新 更多