这是我的 login.xhtml :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<body>
<h:form id="form">
<p:panel id="panel" header="Connexion">
<p:messages id="msgs" />
<h:panelGrid columns="3">
<h:outputLabel for="login" value="Login: *" />
<p:inputText id="login"
value="#{utilisateurAuthentificationService.login}"
required="true"
label="Login">
<f:validateLength minimum="2" />
</p:inputText>
<p:message for="login" display="icon" />
<h:outputLabel for="password" value="Password: *" />
<p:password id="password"
value="#{utilisateurAuthentificationService.password}"
label="Password" required="true">
<f:validateLength minimum="2" />
<p:ajax update="msgPassword" event="keyup" />
</p:password>
<p:message for="password" id="msgPassword" display="icon" />
</h:panelGrid>
<p:commandButton id="btn" value="Connexion" update="panel"
actionListener="#{utilisateurAuthentificationService.authentifierUtilisateur(utilisateurAuthentificationService.login,utilisateurAuthentificationService.password)}" />
</p:panel>
</h:form>
</body>
</html>
这是我的 security-config.xml :
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<http auto-config='true'>
<intercept-url pattern="/login.xhtml*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<intercept-url pattern="/welcome.xhtml*" access="ROLE_USER" />
<form-login login-page='/login.xhtml'
always-use-default-target="true" authentication-failure-url="/login.xhtml" />
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="utilisateurService">
</authentication-provider>
</authentication-manager>
</beans:beans>
Spring安全性过滤器 web.xml :
<!-- Spring Security filters -->
<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>
</filter-mapping>
成功记录而不是将我重定向到 welcome.xhtml 页面(这是web.xml中指定的欢迎文件的方式),它将我重定向到 login.xhtml 页面...
问题出在哪里? security-config.xml是否配置错误?还是别的什么?
请告诉我是否必须向您展示一些代码详情..
谢谢
答案 0 :(得分:1)
尝试在http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#csrf
禁用csrf保护或者尝试添加他的CSRF令牌:http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#csrf-include-csrf-token-form
答案 1 :(得分:1)
添加
ajax="false"
到命令按钮,如下所示:
<p:commandButton id="btn" value="Connexion" update="panel"
actionListener="#{utilisateurAuthentificationService.authentifierUtilisateur(utilisateurAuthentificationService.login,utilisateurAuthentificationService.password)}" ajax="false"/>
我不完全确定为什么会有效,但我认为这是因为该按钮现在执行完整页面提交而不是ajax请求,允许Spring Securitys重定向,因为它不再部分页面重新呈现。
答案 2 :(得分:0)
尝试添加default-target-url =&#34; /Welcome.xhtml"属性为form-login元素,如