java - Spring 中的华夫饼自定义错误页面

标签 java spring spring-security waffle

我正在使用 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/

相关文章:

java - Spring无法配置授权服务器

java - 使用浏览器获取请求发送 JWT token

java - Quarkus Qute 无法解析模板

java - 使用 "this."的优势

Java奇怪的ExceptionInInitializerError

grails - 如何在单元测试中针对Spring Security验证用户身份

java - 使用 Java 从列表中选择特定对象

java - 数据库连接超时

java - 如何根据组合框的更改事件更改另一个文本框的值

java - 使用Spring 3.0的MultipartHttpServletRequest时的请求大小限制