284 Star 894 Fork 434

monkeyk7 / oauth2-shiro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README.md
Apache-2.0

oauth2-shiro


整合Apache OltuShiro. 提供一个轻量的OAUTH2应用框架实现.

并根据不同的应用场景提供不同的实现(如web场景,移动设备).

该项目与spring-oauth-server实现相同的需求与场合. 只是在实现上使用的技术不同(spring-oauth-server使用Spring Security + spring-security-oauth2实现); 相比spring-oauth-server, oauth2-oltu具有如下特点:

  • 更加透明 -- 每一步实现都有可以查看的, 更容易理解的源代码, 一目了然

  • 更多的可自定义与可扩展 -- 不管是ERROR返回信息的内容或格式, 都可根据需要自定义, 对请求参数,处理细节等可添加更多的具体实现

  • 可读性更强 -- 由于Shiro, Oltu 没有Spring Security,spring-security-oauth2 的门槛高, 所有代码都是常用的Controller或Java Bean实现各项业务, 更可读,更易于理解

  • 模块化 -- 得益于Oltu的模块化设计, 将authz, resources分开成不同的模块, 使用时可根据实际需要将二者合并在一个项目中或拆分为不同的模块


OAuth2下一代身份认证授权协议OIDC实现: MyOIDC

主要技术及版本

Spring Boot-- 2.4.13
oltu -- 1.0.2
shiro -- 1.11.0
MySQL -- 5.6+

开发环境

  • JDK -- 1.8.0_40

  • Maven -- 3.6.0

  • MySQL -- 5.7.22


项目模块说明

oauth2-shiro项目使用模块化开发, 以实现"高内聚, 低耦合"目标, 更符合实际项目需要; 分为三个模块: authz, core 与 resources, 具体说明如下

  • authz 实现使用各类grant_type去获取token业务逻辑----获取access_token

  • core 将公共部分提取到该模块中, 减少重复代码, 保证一致性, 如定义ClientDetails, AccessToken; authz, resources 模块都依赖于该模块

  • resources 资源管理模块,将受OAuth2保护的资源(URI)放在这里----使用access_token

在线测试

Redis版本

Redis版本的实现主要是将Token数据存储换成Redis,并利用TTL特性自动清除过期数据,性能更高。

如何使用

  1. 项目是Maven管理的, 需要本地安装maven(开发用的maven版本号为3.6.0), 数据库MySql(开发用的mysql版本号为5.7.22)
  2. 下载(或clone)项目到本地
  3. 项目由三个模块(core,authz,resources)组成, core是一个Java项目(jar), authz与resources是SpringBoot项目(.jar)
  4. 创建MySQL数据库(数据库名 oauth2_shiro), 并运行相应的SQL脚本(脚本文件位于others/database目录),
    运行脚本的顺序: oauth2-shiro.ddl -> initial-db.ddl
    若需要运行单元测试,则还需要创建数据库 oauth2_shiro_test 并运行SQL脚本 (单元测试的配置文件为application-test.properties,位于 src/test/resources 目录中)。
  5. 依次修改authz模块的配置文件application.properties(位于模块的src/main/resources目录)与resources模块的配置文件application.properties(位于模块的src/main/resources目录); 修改配置文件中的数据库连接信息(包括username, password等), 都连接到数据库oauth2_shiro
  6. 将本地项目导入到IDE(如Intellij IDEA)中, 并启动服务。
    (authz默认端口为8080,启动类 AuthzApplication.java; resources默认端口为8083,启动类 ResourcesApplication.java )。
    启动后查看控制台的日志输出或查看logs/目录中按日期分类的log日志。
    另: 也可通过maven package命令将项目编译为SpringBoot jar文件(authz.jar 与 rs.jar), 注意编译时每个模块的pom.xml文件中配置的数据库连接信息, 可在Maven命令中添加 -Dmaven.test.skip=true 忽略单元测试; 将authz模块与resources模块生成的jar通过 java -jar 命令启动( java -jar authz.jarjava -jar rs.jar)。
  7. 在浏览器中直接访问authz地址: http://localhost:8080 在线测试或 参考oauth_test.txt(位于others目录)的内容使用postman等工具测试。

支持的 grant_type

说明 oauth2-shiro 项目支持的OAuth2 grant_type (授权方式)与功能

  1. authorization_code -- 授权码模式(即先登录获取code,再获取token)
  2. password -- 密码模式(将用户名,密码传过去,直接获取token) [不推荐]
  3. refresh_token -- 刷新access_token
  4. implicit(token) -- 简化模式(在redirect_uri 的Hash传递token; Auth客户端运行在浏览器中,如JS,Flash) [不推荐]
  5. client_credentials -- 客户端模式(无用户,用户向客户端注册,然后客户端以自己的名义向'服务端'获取资源)
在OAuth2.1中对 grant_type的使用进行了安全升级(如不推荐使用 password 方式), 详细变化请查看 OAuth2.1的状态与主要特征

开发计划

从 0.2版本开始将项目的所有计划的开发内容列出来, 方便大家跟进, 也欢迎你加入.
项目的开发管理使用开源项目 andaily-developer.

计划加入Spring-Boot的实现

  • Version: 2.0.1 [plan]
    Date: --- / ---

    1. ---


  • Version: 2.0.0 [finished]
    Date: 2020-07-05 / 2023-09-28

    1. 升级使用Spring Boot,调整工程结构,使用 thymeleaf替换 servlet/jsp,打包由war换成jar

    2. 升级使用JDK 1.8, 日志框架使用logback替换log4j(处理log4j的安全漏洞)

    3. token支持使用JWT格式,通过配置参数authz.token.generator.type来控制与向下兼容

    4. 升级shiro到v1.11.0

    5. 密码存储算法由MD5换成SHA-256,并支持盐(salt),使密码存储更安全可靠;通过配置参数authz.store.credentials.alg来控制与向下兼容

    6. 对初始的账户密码使用更安全的密码策略:包括大小写字母,数字与特殊符号,长度至少10位


  • Version: 0.3 [finished]
    Date: 2016-07-16 / 2018-10-17

    1. (152) - oltu版本升级到1.0.2 并完成测试.

    2. (153) - 尝试添加并实现OIDC在 oauth2-shiro中[canceled]

    3. (161) - 增加必要的代码注释与配置注释, 更易理解

    4. implicit模式不需要带上client_secret


  • Version: 0.2 [finished]
    Date: 2016-05-26 / 2016-07-03

    1. (66) - 更新首页UI, 参照spring-oauth-server

    2. (67) - client details overview

    3. (68) - client details testing

    4. (69) - user add/edit, overview

    5. (70) - 添加API使用说明, 举例各个场景

    6. (71) - 发布到测试服务器

    7. (72) - resources模块更新UI说明



项目动态

  1. 2015-05-17 Initial project, start push code (private)

  2. 2015-07-16 oauth2-shiro项目开发状态(7月)

  3. 2015-09-06 oauth2-shiro项目开发状态(8月)

  4. 2015-09-06 项目由 私有 变为 开源, 开发 resource 模块

  5. 2015-09-26 版本0.1 开发完毕, 发布 0.1-beta 版本

  6. 2015-10-07 重构项目结构, 发布 0.1-rc 版本

  7. 2016-05-26 开始开发 0.2 版本

  8. 2016-07-02 添加在线测试环境

  9. 2016-08-17 发布 0.2 版本

  10. 2017-01-21 加入到GitHub中, Git@OSC地址: http://git.oschina.net/mkk/oauth2-shiro

  11. 2020-07-05 开始2.0.0版本开发

  12. 2023-09-28 发布 2.0.0 版本,大升级


姊妹项目


问答与讨论

与OAuth2相关的技术文章请访问 https://andaily.com/blog/?cat=19 (不断更新与OAuth相关的文章)
与项目相关的,与OAuth相关的问题与回答,以及各类讨论请访问
https://andaily.com/blog/?dwqa-question_category=oauth

捐赠历史

支付宝: monkeyking1987@126.com (**钊)

  • 明瑞 -- 5元
  • Triton -- 8.8元
  • 半个鼠标 -- 10元
  • Andis -- 10元 (2017-03-09)
  • Max Shu -- 10元 (2017-04-13)
  • 514407363 -- 6.66元 (2017-06-02)
  • 自负 -- 5元 (2017-09-18)
  • 红领巾 -- 10元 (2017-09-28)
  • 张宏俊 -- 20元 (2018-03-28)

开源扩展

关注更多我的开源项目请访问 https://andaily.com/my_projects.html

若需更多的商业技术支持请联系 monkeyk1987@gmail.com或发私信。
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2015 monkeyk7 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Integrate OAuth2(oltu) and Shiro 展开 收起
Java 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/mkk/oauth2-shiro.git
git@gitee.com:mkk/oauth2-shiro.git
mkk
oauth2-shiro
oauth2-shiro
master

搜索帮助