2014-10-29 6 views
0

나는 와플 1.7 + 스프링 4 + 스프링 보안 3.2 + 타임 리프를 사용하고 있습니다. 내 문제는 fallback 양식 로깅이 실패 할 때 사용자 정의 오류 페이지를 제공 할 수 없다는 것입니다. 이것은 내 구성입니다 : @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./access-denied 페이지에 대한 보안을 무한 리디렉션 루프를 방지하기 위해 비활성화합니다. 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을 throw하면 호출됩니다.

나는이 도움이되기를 바랍니다.

관련 문제