spring boot restful服务禁用Chrome登录弹出窗口
我正在构建一个具有角度前端的restful web服务。如果用户使用错误的凭据登录,Chrome浏览器会自动显示登录弹出窗口。我想通过响应代码403而不是401来防止这种情况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
我已经回顾了[这个问题][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");
}
}