2014-10-29 3 views
0

Я использую вафли 1.7 + весна 4 + весна безопасности 3.2 + тимелеаф. Моя проблема заключается в том, что я не могу предоставить страницу пользовательских ошибок при сбое регистрации формы назад. Это моя конфигурация: @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/**") .authenticated() .and() .exceptionHandling() .authenticationEntryPoint(negotiateSecurityFilterEntryPoint()) .accessDeniedPage("/access-denied") .and() .addFilterBefore(waffleNegotiateSecurityFilter(), BasicAuthenticationFilter.class); } Вафли пользовательский ошибка страница весной

Когда пользователь использует браузер с SNPENGO офф и вводит неправильные учетные данные, система по умолчанию 500 страницы по-видимому с следующей информацией:

com.sun.jna.platform.win32.Win32Exception: The logon attempt failed. 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) ...

Как я могу обеспечить свою кодовую страницу (доступ -denied.html шаблон thymeleaf)? До сих пор я пробовал все от http://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc, но безуспешно.

ответ

0

После того, как вы вникнете в весеннюю документацию и отслеживаете, что на самом деле вафли, я смог решить ее в следующем «уродливом» способе. 1. отключение защиты для страницы с доступом, запрещающей бесконечную переадресацию 2. обертывание вафельного фильтра, чтобы уловить все исключения и перенаправить его

У кого-нибудь есть лучшее решение?

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.authorizeRequests() 
      .antMatchers("/access-denied") 
      .permitAll() 
      .and() 
      .authorizeRequests() 
      .antMatchers("/**") 
      .authenticated() 
      .and() 
      .exceptionHandling() 
      .authenticationEntryPoint(negotiateSecurityFilterEntryPoint()) 
      .accessDeniedPage("/access-denied") 
      .and() 
      .addFilterBefore(waffleNegotiateSecurityFilter(), 
        BasicAuthenticationFilter.class); 
} 

public class WaffleWrapperSecurityBean extends GenericFilterBean { 
    @NotNull 
    private final GenericFilterBean wrappedFilter; 
    public WaffleWrapperSecurityBean(GenericFilterBean filter) { 
     wrappedFilter = filter; 
    } 
    @Override 
    public void doFilter(ServletRequest request, ServletResponse response, 
      FilterChain chain) throws IOException, ServletException { 
     try { 
      wrappedFilter.doFilter(request, response, chain); 
     } catch (Exception e) { 
      ((HttpServletResponse) response) 
        .sendRedirect("access-denied?message=" 
          + e.getLocalizedMessage()); 
     } 
    } 
    @Override 
    public void destroy() { 
     wrappedFilter.destroy(); 
    } 
} 
// controller code ommited 
1

Вы можете попробовать создать DelegatingNegotiateSecurityFilter и установив AuthenticationFailureHandler. Конфигурация

Пример DelegatingNegotiateSecurityFilter фасоли:

<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.
  • Вызывается AuthenticationFailureHandler, если AuthenticationManager выбрасывает AuthenticationException.
  • Вызывается AccessDeniedHandler, если AuthenticationManager выбрасывает AccessDeniedException.

Надеюсь, это поможет ...