Spring Security“将为您提供登录表单” ... https://docs.spring.io/spring-security/site/docs/current/guides/html5/hellomvc-javaconfig.html
那么我该如何在受保护的请求上触发内置表单?
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("admin").roles("ADMIN", "USER").and()
.withUser("guest").password("guest").roles("USER");
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.httpBasic().and()
.authorizeRequests()
.antMatchers(HttpMethod.POST,"/test").hasRole("ADMIN")
.antMatchers(HttpMethod.PUT,"/test/**").hasRole("ADMIN")
.antMatchers(HttpMethod.DELETE,"/test/**").hasRole("ADMIN")
.antMatchers(HttpMethod.PATCH,"/test/**").hasRole("ADMIN").and()
.formLogin()
.and()
.csrf().disable();
}
当我在未登录的情况下对“ / test”进行POST时,可以正确地防止并保护它,但是当我从前端发出请求时,我希望Spring触发其登录表单。尤其是在没有创建html文件或/ login控制器的情况下,此功能似乎可以实现。