java - 在安全请求上触发 Spring Security 登录?
问题描述
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 控制器的情况下,这似乎使此功能成为可能。
解决方案
推荐阅读
- sql - 抓取表格中的所有行并抓取条件所在的一行
- django - 当我尝试打开我的 IP 地址时,Apache 默认页面正在打开
- jboss - 如何使用业务中心部署项目?
- python - 如何使用 python 套接字通过连接发送 api 响应?
- php - 有没有办法在 Ajax 请求之后将 cookie 从 laravel 设置到另一个域?
- javascript - Vue.js - 带有查询参数的搜索表单
- javascript - 使子容器相对于父 div 固定(高度不固定)
- terminology - 是否有以下划线开头的类字段的通用术语,供同名的 getter/setter 内部使用?
- r - 什么是 R 相当于 Stata 的填充?
- php - 对按时间段分桶的聚合数据发出请求时,将忽略使用 GoogleFit REST API 时区