带有f:ajax的PrimeFaces组件和普通JSF组件不再通过Spring-Security唤醒

时间:2019-07-11 19:47:38

标签: jsf spring-security primefaces

我正在尝试将 Spring-Security 5.1.4.RELEASE 集成到已经运行的 JSF 2.2 - Primefaces 6.1 APP中证券化。 当我尝试访问受保护的页面“ logged.xhtml”时,spring触发并带我进入登录页面“ login.xhtml”,因此Spring似乎工作正常。

问题在于,一旦我配置了Spring,所有的Primefaces p:commandLink就会停止工作(以及其他Primefaces组件中的某些“ Action”方法)。像“ h:outputLink”之类的JSF Sun组件( xmlns:h =“ http://java.sun.com/jsf/html” )继续工作,但h:commmandButton与{{ 1}}也失败了。

我不知道为什么Primefaces组件或带有f:ajax的JSF组件损坏了...

这是我的faces-config.xml:

f:ajax

这是我的WEB.XML:

<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

    <resource-bundle>
        <base-name>messages</base-name>
        <var>msg</var>
    </resource-bundle>

    <message-bundle>messages</message-bundle>

    <locale-config>
        <default-locale>en</default-locale>
        <supported-locale>en</supported-locale>
        <supported-locale>es</supported-locale>
    </locale-config>
</application>

这是我的安全初始化程序:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
</context-param>

<session-config>
    <session-timeout>30</session-timeout>
</session-config>

<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

这是我的安全配置:

public class SecurityWebInitializer extends AbstractSecurityWebApplicationInitializer{

}

编辑:

检查浏览器控制台后,我发现每次按任何Primefaces链接/按钮都会出现以下错误:

XHR POST本地主机:8080 / springtest / index.xhtml [HTTP / 1.1 403 Forbidden 2ms]

我认为权限存在问题,但是在查看我的SecurityConfig文件后,我没有看到问题。

以下行应限制对受保护页面的访问:

.antMatchers(“ / logged.xhtml”)。authenticated()

此行应允许其余页面中的所有流量通过:

.anyRequest()。permitAll()

我做错了什么?

有什么建议吗?

谢谢!

PS:让我知道您是否需要有关该项目的更多信息

1 个答案:

答案 0 :(得分:1)

如果有人需要,我想回答这个问题:

在使用TEMPLATES组成JSF页面时,始终将“ csrf”令牌以每种单一形式放置在其上。将令牌放在一个地方是不够的。

<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />