【发布时间】:2011-12-24 02:14:23
【问题描述】:
我为 Spring Security 使用 facelets 登录表单:
<h:messages globalOnly="true" layout="table" />
<h:form id="formLogin" prependId="false">
<h:outputLabel for="j_username" value="Usuario:" />
<h:inputText id="j_username" value="#{autenticacionController.administrador.login}" />
<h:outputLabel for="j_password" value="Contraseña:" />
<h:inputSecret id="j_password" value="#{autenticacionController.administrador.password}" />
<h:commandButton value="Entrar" action="#{autenticacionController.loginAction}" />
<h:commandButton value="Cancelar" immediate="true" action="#{autenticacionController.cancelarAction}" />
</h:form>`
loginAction 方法用这个转发请求:
FacesContext.getCurrentInstance().getExternalContext().dispatch("/j_spring_security_check")
它工作正常,但是如果 Spring Security 抛出 BadCredentials 异常,我如何在我的 h:messages 标记中显示 facemessage?
我知道可以使用阶段侦听器来完成,但我不喜欢这种方式(处理侦听器中的异常)。
我正在尝试另一种方式,像这样配置 Spring Security:
authentication-failure-url="/faces/paginas/autenticacion/login.xhtml?error=1
然后在登录页面中,捕获 GET 参数“错误”。但是我怎样才能以这种方式显示面部消息呢?
我尝试的另一种方法是覆盖 Spring Security 的消息属性文件(覆盖密钥“badcredentials”的消息),但它也不起作用(我不知道如何显示消息)。
有人知道怎么做吗?
非常感谢您。
【问题讨论】:
标签: exception jsf-2 spring-security message