Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring boot restful服务禁用Chrome登录弹出窗口_Spring_Rest_Google Chrome_Authentication_Spring Boot - Fatal编程技术网

spring boot restful服务禁用Chrome登录弹出窗口

spring boot restful服务禁用Chrome登录弹出窗口,spring,rest,google-chrome,authentication,spring-boot,Spring,Rest,Google Chrome,Authentication,Spring Boot,我正在构建一个具有角度前端的restful web服务。如果用户使用错误的凭据登录,Chrome浏览器会自动显示登录弹出窗口。我想通过响应代码403而不是401来防止这种情况 我已经回顾了[这个问题][1],它对我的用例没有帮助。我也尝试过在谷歌上找到的不同解决方案,但在所有情况下都是使用登录弹出窗口 对于最新的Spring版本,处理身份验证的配置已经更改。由于这个原因,大多数教程不再有效。以下是工作配置: SecurityConfig.java: @Configuration @EnableW

我正在构建一个具有角度前端的restful web服务。如果用户使用错误的凭据登录,Chrome浏览器会自动显示登录弹出窗口。我想通过响应代码403而不是401来防止这种情况


我已经回顾了[这个问题][1],它对我的用例没有帮助。我也尝试过在谷歌上找到的不同解决方案,但在所有情况下都是使用登录弹出窗口

对于最新的Spring版本,处理身份验证的配置已经更改。由于这个原因,大多数教程不再有效。以下是工作配置:

SecurityConfig.java:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private CustomAuthenticationEntryPoint authenticationEntryPoint;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            //....
            //.and()
            .httpBasic().authenticationEntryPoint(authenticationEntryPoint)
            .and().csrf().disable();
    }
}
CustomAuthenticationAntryPoint.java:

@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {

    private final Logger log = LoggerFactory.getLogger(CustomAuthenticationEntryPoint.class);

    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        log.debug("Pre-authenticated entry point called. Rejecting access");
        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "Bad credentials");
    }
}