spring security oauth2 自定义登录页面点击登录按钮报错full authentication is required to access

  • A+
所属分类:Spring

---
title: Spring Security OAuth2 自定义登录页面点击登录按钮报错Full authentication is required to access this resource
date: 2019-12-18 16:10:14
categories: Spring Security
tags:
- spring
- csrf
- 登录
- 自定义
- Required
- security
- oauth2
- configure
- WebSecurityConfigurerAdapter
- Authentication
---

之前用框架默认的登录画面是可以正常拿到code的,但是按网上的博客的方法,换成自定义login画面后,自定义login画面可以出来,但点击登录时就会报错Full authentication is required to access this resource。

自定义login画面很简单,就是两个input框,name为username和password,form表单的action地址为/login,这个地址应该是框架内置的一个地址,这个我与默认的login画面比较了,默认的login画面里的action地址也是/login,所以login画面应该是完全没问题的,但是其它配置也没什么区别啊,最后发现默认的login画面里有一个隐藏值_csrf,而我们自定义的login画面没有定义这个,所以在想是不是这个影响的,但是这个值应该是一个随机值,自己也不知道设什么。。

后来仔细对比所有配置发现,继承自WebSecurityConfigurerAdapter的configure方法里,有一个csrf().disable()配置被我注释掉了,把这个放开后就好了。

ZPY

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: