Spring security SpringSecurity启用formLogin而不启用登录页面
可以在Spring Security中启用formLogin,但只能访问“POST”端点 我不需要HTML登录页面,因为我不想用用户名和密码进行http调用来验证用户Spring security SpringSecurity启用formLogin而不启用登录页面,spring-security,Spring Security,可以在Spring Security中启用formLogin,但只能访问“POST”端点 我不需要HTML登录页面,因为我不想用用户名和密码进行http调用来验证用户 @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .httpBasic().disable() .formLogin() ..
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.httpBasic().disable()
.formLogin()
...
}
谢谢
编辑:问题是我不想要Spring引导生成的登录页面。登录页面将存在,但它将在不同的前端项目中开发,因此需要调用此POST端点。您的问题被否决的原因是跨站点请求伪造(CSRF) 如果没有登录页面,您必须禁用CSRF,这是不可取的 现在,如果您想强制执行,请将登录页面发送到其他地方
.formLogin()
.loginPage("/does-not-exist")
这很难看,因为Spring将尝试重定向到该页面
您仍然可以实现它,而无需启用表单登录
@Override
protected void configure(HttpSecurity http) throws Exception {
UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter();
filter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
//here you can setup success handlers etc
http
.csrf().disable()
.addFilter(myAuthFilter);
...
}
您的问题被否决的原因是因为跨站点请求伪造(CSRF) 如果没有登录页面,您必须禁用CSRF,这是不可取的 现在,如果您想强制执行,请将登录页面发送到其他地方
.formLogin()
.loginPage("/does-not-exist")
这很难看,因为Spring将尝试重定向到该页面
您仍然可以实现它,而无需启用表单登录
@Override
protected void configure(HttpSecurity http) throws Exception {
UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter();
filter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
//here you can setup success handlers etc
http
.csrf().disable()
.addFilter(myAuthFilter);
...
}
问题是我不想要Spring引导生成的登录页面。登录页面将存在,但它将在不同的前端项目中开发,因此需要调用此POST端点。也许你的第二个选择适合我的需要,我会试试看。谢谢。第二个选项对我来说是正确的答案。我添加了AuthenticationManager来公开authenticationManagerBean方法,而不是使用sharedObject。谢谢,太好了。如果配置,两个选项都可以工作。现在,您可能还想将
成功处理程序
和失败处理程序
添加到您的过滤器中。问题是我不想要Spring Boot生成的登录页面。登录页面将存在,但它将在不同的前端项目中开发,因此需要调用此POST端点。也许你的第二个选择适合我的需要,我会试试看。谢谢。第二个选项对我来说是正确的答案。我添加了AuthenticationManager来公开authenticationManagerBean方法,而不是使用sharedObject。谢谢,太好了。如果配置,两个选项都可以工作。现在,您可能还需要将成功处理程序
和失败处理程序
添加到过滤器中。