spring - 为什么我不能将 POST 登录信息发送到 Spritg 身份验证服务器?
问题描述
我有带有 @EnableResourceServer 的 OAuth 支持的身份验证服务器。 应用配置
我可以 GET 到 /login 并填写表格。当我将 POST 发送到 /login 时, POST /login 后出现 401 错误
解决方案
你可能会从我的倾斜实验中得到帮助。我也面临同样的问题,添加HttpMethod.POST
antMatchers 帮助了我,你应该.authorizeRequests()
在一开始就使用
http
.csrf().disable()
.authorizeRequests().antMatchers("/login","/home","/failure").permitAll()
.antMatchers(HttpMethod.POST,"/admin/**").hasRole("ADMIN")
.antMatchers(HttpMethod.PUT,"/admin/**").hasRole("ADMIN")
.antMatchers(HttpMethod.GET,"/admin/**").hasRole("ADMIN")
.antMatchers(HttpMethod.GET,"/user/**").hasAnyRole("ADMIN","USER")
.antMatchers(HttpMethod.POST,"/user/**").hasAnyRole("ADMIN","USER")
.anyRequest().authenticated()
.and()
.exceptionHandling().accessDeniedPage("/403")
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login")
.usernameParameter("email")
.passwordParameter("password")
.defaultSuccessUrl("/home",true)
.failureUrl("/failure")
.and()
.logout().logoutUrl("/logout").permitAll();
推荐阅读
- node.js - Mailgun 在 Node.js 应用程序中看不到凭据
- javascript - React 处理 DOM 元素的良好实践
- javascript - 为什么这个 MongoDB 文档是用相同的 nanoid 生成的?
- javascript - 从javascript中的圆圈中排除点
- flutter - Flutter 的谷歌地图插件 onTap 不工作
- python-3.x - 将数据从 Pandas 数据框中保存到 csv 文件中,并附加多个项目
- function - 反射性地引用重载的顶级 Kotlin 函数
- amazon-web-services - Amazon DynamoDB:将数据模型从一个账户复制到另一个账户
- javascript - 输入不能为空,但 console.log 仍在运行
- reactjs - 第二个 axios 拦截器不起作用