我想将 Spring Security 与 JSF2 和 richfaces 结合使用。
如果我使用 spring 生成的登录页面,它工作正常。
<security:http auto-config="true" use-expressions="true">
<security:intercept-url pattern="/Admin*" access="isAuthenticated()" />
<security:form-login login-page="/spring_security_login" login-processing-url="/j_spring_security_check" authentication-failure-url="/spring_security_login?login_error" />
<security:logout logout-url="/j_spring_security_logout" logout-success-url="/" delete-cookies="JSESSIONID" invalidate-session="true"/>
</security:http>
现在我想介绍我的自定义登录。
<security:form-login login-page="/login.xhtml" ....>
login.xhtml:
<h:form id ="select_form" prependId="false">
<h:panelGrid columns="2" style="">
<h:outputText value ="Identifiant :"> </h:outputText>
<h:inputText name="j_username" >
<rich:placeholder value="Entrez un identifiant..." />
</h:inputText>
<h:outputText value ="Mot de passe :"> </h:outputText>
<h:inputText name="j_password" >
<rich:placeholder value="Entrez un mot de passe..." />
</h:inputText>
<h:outputText value =""> </h:outputText>
<h:commandButton id="btnLoginId" action="j_spring_security_check" value="Login" type="submit" style="float:right;" />
</h:panelGrid>
</h:form>
问题是我想使用 j_spring_security_check,如 security-conf.xml 中所述。
但是JSF想要重定向到一个不存在的url。事实上,如果我尝试将 faces-configs.xml 中的导航案例配置为 j_spring_security_check ,它无论如何都不会工作,因为 j_spring_security_check 不提供渲染的页面,它更像是一种为我们完成工作的身份验证 Controller 。
所以我的问题是如何在 JSF2 中配置操作登录,而不使用支持 bean,只调用 security-conf 的强度来完成所有工作,而无需编写不必要的行。或者如何在使用 j_spring_security_check 时配置 faces-config 导航?这可能吗?
非常感谢您的帮助。
更新:它可以在不使用 JSF 的情况下使用硬编码的 html 正常工作。
<form name='f' action='/Lyric/j_spring_security_check' method='post'>
<table>
<tr><td>User:</td><td><input type='text' name='j_username' value=""/></td></tr>
<tr><td>Password:</td><td><input type='password' name='j_password'/></td></tr>
<tr><td colspan='2'><input name="submit" type="submit" value="Login"/></td></tr>
</table>
</form>
最佳答案
您需要更改提交表单的 URL,还需要更改 <h:inputText>
s 代表用户名和密码:
<form method="POST" action="j_spring_security_check">
...
<h:inputText id="j_username" />
<h:inputSecret id="j_password" />
<h:commandButton name="submit" type="submit" value="Submit"></h:commandButton>
</form>
关于java - Spring Security : Custom Login without backing bean, 仅使用 spring security 配置作为 j_spring_security_check,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19294315/