# spring-security-oauth2 **Repository Path**: pf65812/spring-security-oauth2 ## Basic Information - **Project Name**: spring-security-oauth2 - **Description**: 这是用于oauth2.0的 授权码模式 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 1 - **Created**: 2020-01-12 - **Last Updated**: 2023-05-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Oauth2.0 有5种模式 "authorization_code", "client_credentials", "refresh_token","password", "implicit" ## 授权码模式 ###1. 首先通过授权码模式获取'授权码' http://localhost:8090/oauth/authorize?client_id=client&response_type=code https://www.baidu.com/?code=o14SzC 回调地址中自带了 授权码, 将授权码提取至postman中进行进一步的操作 OAuth Approval Do you authorize "client" to access your protected resources? scope.app: 口Approve 口Deny Authorize
### 2. 其次,将获得的'授权码'进行postman请求 ######(1) 这是cURL方式通过CMD访问 curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=authorization_code&code=o14SzC' "http://client:secret@localhost:8090/oauth/token" ######(2) POSTMAN通过授权码,获取访问令牌 http://client:secret@localhost:8090/oauth/token?grant_type=authorization_code&code=o14SzC result: { "access_token": "9dfffe26-0f97-4fbc-8861-c3e0de993972", "token_type": "bearer", "expires_in": 43121, "scope": "app" } ##RBAC介绍 回顾 JDBC 存储令牌 client 存到数据库 Token 存到数据库 认证 验证账号密码 授权 这个角色能操作哪些数据 人 运营,编辑 系统 日志系统,监控系统 时间 定时清理 基于角色的访问控制 RBAC 基于角色 ACL 访问控制列表 ABAC 基于属性 PBAC 基于策略 权限控制模型 RBAC 是什么: 权限控制模型 为什么: Who: 资源所有者 What: 能访问哪些资源 How: 具体怎么访问 怎么用 who User What 静态资源 功能操作 , 数据列 动态资源 数据 文章, 相册, 笔记 How CRUD User 用户 role 角色 permission 权限 user_role 用户角色 role_permission 角色权限 一个用户可以拥有多种角色 一个角色可以拥有多种权限 Spring Data JPA 是标准 Hibernate 是实现(单表操作) MyBatis, MyBatis写Xml过于繁琐, 所以使用tk.Mybatis MybatisPlus XP极限编程原则 基于RBAC模型自定义数据库已经实现 RBAC模型已实现access_token 系统中的资源包括两种 静态资源 html css js img 动态资源 tb_content tb_order tb_item 在没有和server端对接,并且还没有写config下的文件配置的时候, 单运行ResourceApplication时, 输入的用户名和密码是 user 密码是后台日志系统生成的 Using generated security password: 68ebefdd-d1d3-40e8-ab6a-33ff43ae161c 这时将认证服务器和资源服务器打通 先通过授权码去获取access_token 现在只能通过认证服务器获取到的access_token去访问资源服务器了 通过认证服务器获取到access_token = xxx 将access_token访问 这样就可以访问数据了,也就是意义上的单点登录 http://localhost:8091/contents/?access_token=66f49c9a-f7f3-4515-8ea6-327f24fe77c8