spring saml身份验证失败重定向到Angular 路由不工作

jdgnovmf  于 2021-09-30  发布在  Java
关注(0)|答案(0)|浏览(261)

我有一个Angular 错误路由(/#/error),在服务提供者的saml身份验证失败后需要重定向。然而,在重定向到错误路由后,它会立即再次重定向到idp进行身份验证。
下面是配置

@Override
   public void configure(WebSecurity web) throws Exception {
       web.ignoring().antMatchers("/#/error");
       }

@Override
protected void configure(HttpSecurity http) throws Exception {
        final CookieCsrfTokenRepository cookieCsrfTokenRepository = new CookieCsrfTokenRepository();
        cookieCsrfTokenRepository.setCookieHttpOnly(false);
        http.authorizeRequests().antMatchers("/saml/**","/error").permitAll().antMatchers("/**").fullyAuthenticated()
                .anyRequest().authenticated();
        http.exceptionHandling().defaultAuthenticationEntryPointFor(samlEntryPoint, new AntPathRequestMatcher("/"));
        http.csrf().disable();

        http.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
                .addFilterBefore(new CustomCsrfFilter(cookieCsrfTokenRepository), MetadataGeneratorFilter.class)
                .addFilterBefore(new SecurityFilter(), CustomCsrfFilter.class);

        http.addFilterAfter(samlFilter(samlLogoutFilter, samlEntryPoint, samlAuthSuccessHandler, samlAuthFailureHandler,
                samlLogoutProcessingFilter), BasicAuthenticationFilter.class);

    }

    @Bean
    @Qualifier("saml")
    public SimpleUrlAuthenticationFailureHandler authenticationFailureHandler() {
        SimpleUrlAuthenticationFailureHandler failureHandler = new SimpleUrlAuthenticationFailureHandler();
        failureHandler.setUseForward(true);
        failureHandler.setDefaultFailureUrl("/authentication-failure");
        return failureHandler;
    }

A controller class for above authentication failure url.

@PostMapping(value = { "/authentication-failure" })
    public String errorHandler(final HttpServletRequest request) {
          return "redirect:/#/error";
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题