Spring-BASIC аутентификация не работает в браузере IE - PullRequest
0 голосов
/ 01 октября 2019

Я сделал базовую аутентификацию, используя springboot с BasicAuthenticationEntryPoint и пользовательским фильтром. Он работает должным образом в Chrome, но не работает в браузере IE.

Сначала запрашивается страница входа в систему, если введены неправильные учетные данные, затем, если мы перезагрузим страницу и пытаемся выполнить аутентификацию только с предыдущими данными, и не запрашиваем страницу входа снова вБраузер IE, но тот же работал в Chrome, как и ожидалось.

Код, как показано ниже:

@Override
    protected void configure(HttpSecurity http) throws Exception {


        http.csrf().disable().authorizeRequests().anyRequest().fullyAuthenticated().and().httpBasic()
                .authenticationEntryPoint(new MyBasicAuthenticationEntryPoint());

        http.addFilterAt(getCustomAuthenticationFilter(), BasicAuthenticationFilter.class);

        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }

Код BasicAuthenticationEntryPoint:

public class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response,
            org.springframework.security.core.AuthenticationException authException)
            throws IOException, ServletException {

        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setHeader("WWW-Authenticate", "Basic");
        response.getOutputStream().println(authException.getMessage());

    }

    @Override
    public void afterPropertiesSet() throws Exception {

        setRealmName("localhost");
        super.afterPropertiesSet();
    }

}

Код CustomFilter:

public class CustomAuthenticationFilter extends BasicAuthenticationFilter {

  @Autowired
  AuthUsersService authUsersService;

  @Autowired
  public CustomAuthenticationFilter(AuthenticationManager authenticationManager) {

    super(authenticationManager);
  }

  @Override
  protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response,
      Authentication authResult) throws IOException {

       System.out.println("Successful");

    return;

  }


  @Override
  protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response,
      AuthenticationException failed) throws IOException {

    System.out.println("UN-Successful");

    return;

  }  

}

Может кто-нибудь подсказать, почему приведенный выше код не работает в браузере IE?

...