# experiment4 **Repository Path**: Aidenzzy/experiment4 ## Basic Information - **Project Name**: experiment4 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-05-18 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 实验四 基于Spring Security码云OAuth2认证 **一、 实验目的** 1、 掌握使用Spring Security框架; 2、 掌握配置Spring Security的安全过滤链; 3、 掌握编写Spring Security单元测试; 4、 掌握创建接入码云的应用; 5、 掌握码云OAuth2认证基本流程; 6、 掌握使用码云API; 7、 了解使用模板引擎或前端框架制作用户登录界面。 **二、 实验环境** 1、 JDK 1.8或更高版本 2、 Maven 3.6+ 3、 IntelliJ IDEA **三、 实验任务** 步骤一:创建接入码云的应用 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/110206_553189f6_4853661.png "1589770894(1).png") 步骤二:编写重定向过滤器的业务逻辑 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/111109_52f825ce_4853661.png "1589771452(1).png") 步骤三:使用码云access_token API向码云认证服务器发送post请求获取access_token ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/111252_612ce5f8_4853661.png "1589771556(1).png") 步骤四:使用码云API获取授权用户的资料 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/111639_58903235_4853661.png "1589771781(1).png") 步骤五:把自定义的两个Filter加进安全过滤链 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/111729_9e6338dd_4853661.png "1589771825(1).png") 步骤六:把我们自定义的SecurityConfigurer应用到安全过滤链 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/112302_6a998995_4853661.png "1589772170(1).png") 步骤七:改造/user接口,返回码云用户资料给前端;改造user.ftlh模板用于显示用户资料 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/112529_949f6adf_4853661.png "1589772198(1).png") 步骤八:模拟一个登录用户,访问受保护的接口/test,断言接口的返回内容body部分是否一致 ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/113044_eb5a15c1_4853661.png "1589772367(1).png") 用户信息: ![输入图片说明](https://images.gitee.com/uploads/images/2020/0518/113230_9fc048d4_4853661.png "3275cf3fd5a7c4c1f3320c15883c196.png")