Estoy creando una aplicación simple con un sitio de inicio de sesión. Usé el tipo básico de autorización HTTP, pero el problema es que no sé cómo deshabilitar la ventana emergente que se muestra cada vez que paso credenciales incorrectas o en caso de escribir un sitio de punto final seguro antes de la autenticación.
La interfaz está escrita en JS puro, lanzada sin ningún motor de plantillas. Solo archivos js + html en directorio estático.
La página de autenticación usa Fetch Api para enviar encabezados con credenciales
¿Alguien sabe cómo deshabilitar esta ventana, que se muestra a continuación:
Aquí está mi clase de configuración de seguridad:
@Configuration @EnableWebSecurity public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { @Resource private UserDetailsService userDetailsService; @Autowired private CustomLogoutHandler logoutHandler; @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(authProvider()); } @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable().authorizeRequests() .antMatchers(HttpMethod.POST, "/demo/users/save").permitAll() .antMatchers(HttpMethod.POST, "/demo/users/**").permitAll() .antMatchers(HttpMethod.POST, "/users/*/save").permitAll() .antMatchers(HttpMethod.DELETE, "/users/**").permitAll() .antMatchers(HttpMethod.POST, "/users/*/verify").permitAll() .antMatchers(HttpMethod.GET,"/users/**").permitAll() .antMatchers(HttpMethod.PUT,"/users/**").permitAll() .antMatchers("/css/**", "/js/**", "/img/**").permitAll() .antMatchers("/signup-page.html").permitAll() .antMatchers("/landing-page.html").permitAll() .anyRequest().authenticated() .and() .formLogin() .disable() .logout() .logoutUrl("/logout") .addLogoutHandler(logoutHandler) .logoutSuccessUrl("/landing-page.html") .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)) .permitAll() .and() .httpBasic(); } @Bean public DaoAuthenticationProvider authProvider() { DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); authProvider.setUserDetailsService(userDetailsService); authProvider.setPasswordEncoder(passwordEncoder()); return authProvider; } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } }No pude encontrar la respuesta antes, cada respuesta que encontré consistía en "deshabilitar httpBasic" y esa no fue una solución satisfactoria. Aquí hay un tema: la seguridad de Spring Boot muestra la ventana emergente Http-Basic-Auth después de un inicio de sesión fallido
y estas líneas resolvieron mi problema:
httpBasic() .authenticationEntryPoint(new AuthenticationEntryPoint(){ //<< implementing this interface @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { //>>> response.addHeader("WWW-Authenticate", "Basic realm=\"" + realmName + "\""); <<< (((REMOVED))) response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase()); } });