我正在使用 waffle 1.7 + spring 4 + spring security 3.2 + thymeleaf。我的问题是,当后备表单日志记录失败时,我无法提供自定义错误页面。这是我的配置:
@覆盖
protected void configure(HttpSecurity http) 抛出异常 {
http.authorizeRequests()
.antMatchers("/**")
.authentiated()
。和()
。异常处理()
.authenticationEntryPoint(negotiateSecurityFilterEntryPoint())
.accessDeniedPage("/访问被拒绝")
。和()
.addFilterBefore(waffleNegotiateSecurityFilter(),
BasicAuthenticationFilter.class);
}
当用户在 SNPENGO 关闭的情况下使用浏览器并输入错误的凭据时,将显示默认系统 500 页面并显示以下信息:
com.sun.jna.platform.win32.Win32Exception:登录尝试失败。 waffle.windows.auth.impl.WindowsAuthProviderImpl.acceptSecurityToken(WindowsAuthProviderImpl.java:134)
waffle.servlet.spi.NegotiateSecurityFilterProvider.doFilter(NegotiateSecurityFilterProvider.java:103) waffle.servlet.spi.SecurityFilterProviderCollection.doFilter(SecurityFilterProviderCollection.java:130)
...
如何提供我的自定义页面(access-denied.html thymeleaf 模板)?到目前为止,我已经尝试了 http://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc 中的所有内容但没有成功。
最佳答案
你可以尝试创建一个 DelegatingNegotiateSecurityFilter并设置一个AuthenticationFailureHandler
。
DelegatingNegotiateSecurityFilter
bean 配置示例:
<bean id="waffleNegotiateSecurityFilter"
class="waffle.spring.DelegatingNegotiateSecurityFilter"
>
<property name="allowGuestLogin" value="false" />
<property name="Provider" ref="waffleSecurityFilterProviderCollection" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" />
<property name="authenticationFailureHandler" ref="authenticationFailureHandler" />
<property name="accessDeniedHandler" ref="accessDeniedHandler" />
<property name="defaultGrantedAuthority">
<null />
</property>
</bean>
AuthenticationManager
允许服务提供商授权主体。authenticationSuccessHandler
允许服务提供者进一步填充Authentication
对象。- 如果 AuthenticationManager 抛出
AuthenticationException
,则调用AuthenticationFailureHandler
。 - 如果 AuthenticationManager 抛出
AccessDeniedException
,则调用AccessDeniedHandler
。
我希望这有帮助......
关于java - Spring 中的华夫饼自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26627295/