diff --git a/sa-token-dev/.gitignore b/.gitignore similarity index 100% rename from sa-token-dev/.gitignore rename to .gitignore diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 8e39eada..00000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 www.uviewui.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 9e2e1213..00000000 --- a/README.md +++ /dev/null @@ -1,92 +0,0 @@ -

- logo -

-

sa-token v1.6.0

-

一个JavaWeb轻量级权限认证框架,功能全面,上手简单

-

- - - - - - - -

- ---- - - -## 😘 在线资料 -- ##### [官网首页:http://sa-token.dev33.cn/](http://sa-token.dev33.cn/) -- ##### [在线文档:http://sa-token.dev33.cn/doc/index.html](http://sa-token.dev33.cn/doc/index.html) -- ##### [需求提交:我们深知一个优秀的项目需要海纳百川,点我在线提交需求](http://sa-app.dev33.cn/wall.html?name=sa-token) -- ##### [开源不易,求鼓励,点个star吧](https://github.com/click33/sa-token) - - -## ⭐ sa-token是什么? -- **sa-token是一个JavaWeb轻量级权限认证框架,其API调用非常简单,有多简单呢?以登录验证为例,你只需要:** -``` java -// 在登录时写入当前会话的账号id -StpUtil.setLoginId(10001); -``` - - -- **然后在任意需要验证登录权限的地方:** -``` java -// 检测是否登录 --- 如果当前会话未登录,下面这句代码会抛出 `NotLoginException`异常 -StpUtil.checkLogin(); -``` - - -- **没有复杂的封装!不要任何的配置!先写入,后鉴权!只需这两行简单的调用,即可轻松完成系统登录鉴权!** - - -## 🔥 框架设计思想 -与其它权限认证框架相比,`sa-token`尽力保证两点: -- 上手简单:能自动化的配置全部自动化,不让你费脑子 -- 功能强大:能涵盖的功能全部涵盖,不让你用个框架还要自己给框架打各种补丁 - - -## 💦️️ 涵盖功能 -- ⚡ **登录验证** —— 轻松登录鉴权,并提供五种细分场景值 -- ⚡ **权限验证** —— 拦截违规调用,不同角色不同授权 -- ⚡ **自定义session会话** —— 专业的数据缓存中心 -- ⚡ **踢人下线** —— 将违规用户立刻清退下线 -- ⚡ **模拟他人账号** —— 实时操作任意用户状态数据 -- ⚡ **持久层扩展** —— 可集成redis、MongoDB等专业缓存中间件 -- ⚡ **多账号认证体系** —— 比如一个商城项目的user表和admin表分开鉴权 -- ⚡ **无cookie模式** —— APP、小程序等前后台分离场景 -- ⚡ **注解式鉴权** —— 优雅的将鉴权与业务代码分离 -- ⚡ **花式token生成** —— 内置六种token风格,还可自定义token生成策略 -- ⚡ **组件自动注入** —— 零配置与Spring等框架集成 -- ⚡ **更多功能正在集成中...** —— 如有您有好想法或者建议,欢迎加群交流 - - -## 🔨 贡献代码 -sa-token欢迎大家贡献代码,为框架添砖加瓦 -1. 在github上fork一份到自己的仓库 -2. clone自己的仓库到本地电脑 -3. 在本地电脑修改、commit、push -4. 提交pr(点击:New Pull Request) -5. 等待合并 - - -## 🌱 建议贡献的地方 -- 修复源码现有bug,或增加新的实用功能 -- 完善在线文档,或者修复现有错误之处 -- 更多demo示例:比如SSM版搭建步骤 -- 您可以参考项目issues与需求墙进行贡献 -- 如果更新实用功能,可在文档友情链接处留下自己的推广链接 - - -## 🚀 友情链接 -[**[ okhttps ]** 一个轻量级http通信框架,支持 WebSocket 以及 Stomp 协议](https://gitee.com/ejlchina-zhxu/okhttps) - - -## 😎 交流群 -QQ交流群:[1002350610 点击加入](https://jq.qq.com/?_wv=1027&k=45H977HM) ,欢迎你的加入 - - -![扫码加群](https://color-test.oss-cn-qingdao.aliyuncs.com/sa-token/qq-group.png ':size=150') - - diff --git a/license.txt b/license.txt new file mode 100644 index 00000000..52d99a66 --- /dev/null +++ b/license.txt @@ -0,0 +1,13 @@ +Copyright 1999-2018 Alibaba Group Holding Ltd. + +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. diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..de72e4e9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + + cn.dev33 + sa-token-parent + pom + 1.6.0 + + + sa-token + A Java Web lightweight authority authentication framework, comprehensive function, easy to use + https://github.com/click33/sa-token + + + + + sp-token-core + sa-token-spring-boot-starter + + + + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + + + + + 1.8 + utf-8 + utf-8 + + + + + master + https://github.com/click33/sa-token.git + scm:git:https://github.com/click33/sa-token.git + scm:git:https://github.com/click33/sa-token.git + + + + + + shengzhang + 2393584716@qq.com + + + + + + + org.sonatype.oss + oss-parent + 7 + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/sa-token-demo-springboot/.factorypath b/sa-token-demo-springboot/.factorypath index c4a7ef47..a207d798 100644 --- a/sa-token-demo-springboot/.factorypath +++ b/sa-token-demo-springboot/.factorypath @@ -36,7 +36,8 @@ - + + diff --git a/sa-token-demo-springboot/pom.xml b/sa-token-demo-springboot/pom.xml index 8a60efe8..ff83a887 100644 --- a/sa-token-demo-springboot/pom.xml +++ b/sa-token-demo-springboot/pom.xml @@ -32,10 +32,17 @@ 1.6.0 --> + + + cn.dev33 - sa-token + sa-token-spring-boot-starter 1.6.0 diff --git a/sa-token-demo-springboot/src/main/java/com/pj/SaTokenDemoApplication.java b/sa-token-demo-springboot/src/main/java/com/pj/SaTokenDemoApplication.java index 1273ceb0..268e248c 100644 --- a/sa-token-demo-springboot/src/main/java/com/pj/SaTokenDemoApplication.java +++ b/sa-token-demo-springboot/src/main/java/com/pj/SaTokenDemoApplication.java @@ -4,9 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import cn.dev33.satoken.SaTokenManager; -import cn.dev33.satoken.spring.SaTokenSetup; -@SaTokenSetup // 必须有这个注解,用来标注加载sa-token @SpringBootApplication public class SaTokenDemoApplication { diff --git a/sa-token-demo-springboot/src/main/java/com/pj/satoken/MySaTokenConfig.java b/sa-token-demo-springboot/src/main/java/com/pj/satoken/MySaTokenConfig.java index 36b55d19..af334cc8 100644 --- a/sa-token-demo-springboot/src/main/java/com/pj/satoken/MySaTokenConfig.java +++ b/sa-token-demo-springboot/src/main/java/com/pj/satoken/MySaTokenConfig.java @@ -4,8 +4,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import cn.dev33.satoken.annotation.SaCheckInterceptor; import cn.dev33.satoken.config.SaTokenConfig; +import cn.dev33.satoken.interceptor.SaCheckInterceptor; /** * sa-token代码方式进行配置 diff --git a/sa-token-demo-springboot/src/main/resources/application.yml b/sa-token-demo-springboot/src/main/resources/application.yml index 2018a8d9..c325d680 100644 --- a/sa-token-demo-springboot/src/main/resources/application.yml +++ b/sa-token-demo-springboot/src/main/resources/application.yml @@ -22,7 +22,7 @@ spring: # 是否在初始化配置时打印版本字符画 is-v: true - + # redis配置 redis: # Redis数据库索引(默认为0) diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/SaTokenManager.java b/sa-token-dev/src/main/java/cn/dev33/satoken/SaTokenManager.java deleted file mode 100644 index 2071a412..00000000 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/SaTokenManager.java +++ /dev/null @@ -1,128 +0,0 @@ -package cn.dev33.satoken; - -import cn.dev33.satoken.action.SaTokenAction; -import cn.dev33.satoken.action.SaTokenActionDefaultImpl; -import cn.dev33.satoken.config.SaTokenConfig; -import cn.dev33.satoken.config.SaTokenConfigFactory; -import cn.dev33.satoken.cookie.SaCookieOper; -import cn.dev33.satoken.cookie.SaCookieOperDefaultImpl; -import cn.dev33.satoken.dao.SaTokenDao; -import cn.dev33.satoken.dao.SaTokenDaoDefaultImpl; -import cn.dev33.satoken.stp.StpInterface; -import cn.dev33.satoken.stp.StpInterfaceDefaultImpl; -import cn.dev33.satoken.util.SaTokenInsideUtil; - -/** - * 管理sa-token所有对象 - * @author kong - * - */ -public class SaTokenManager { - - - /** - * 配置文件 Bean - */ - private static SaTokenConfig config; - public static SaTokenConfig getConfig() { - if (config == null) { - initConfig(); - } - return config; - } - public static void setConfig(SaTokenConfig config) { - SaTokenManager.config = config; - if(config.getIsV()) { - SaTokenInsideUtil.printSaToken(); - } - } - public synchronized static void initConfig() { - if (config == null) { - setConfig(SaTokenConfigFactory.createConfig()); - } - } - - /** - * 持久化 Bean - */ - public static SaTokenDao dao; - public static SaTokenDao getDao() { - if (dao == null) { - initDao(); - } - return dao; - } - public static void setDao(SaTokenDao dao) { - SaTokenManager.dao = dao; - } - public synchronized static void initDao() { - if (dao == null) { - setDao(new SaTokenDaoDefaultImpl()); - } - } - - /** - * 权限认证 Bean - */ - public static StpInterface stp; - public static StpInterface getStp() { - if (stp == null) { - initStp(); - } - return stp; - } - public static void setStp(StpInterface stp) { - SaTokenManager.stp = stp; - } - public synchronized static void initStp() { - if (stp == null) { - setStp(new StpInterfaceDefaultImpl()); - } - } - - /** - * sa-token行为 Bean - */ - public static SaTokenAction sta; - public static SaTokenAction getSta() { - if (sta == null) { - initSta(); - } - return sta; - } - public static void setSta(SaTokenAction sta) { - SaTokenManager.sta = sta; - } - public synchronized static void initSta() { - if (sta == null) { - setSta(new SaTokenActionDefaultImpl()); - } - } - - /** - * sa-token cookie操作 Bean - */ - public static SaCookieOper saCookieOper; - public static SaCookieOper getSaCookieOper() { - if (saCookieOper == null) { - initSaCookieOper(); - } - return saCookieOper; - } - public static void setSaCookieOper(SaCookieOper saCookieOper) { - SaTokenManager.saCookieOper = saCookieOper; - } - public synchronized static void initSaCookieOper() { - if (saCookieOper == null) { - setSaCookieOper(new SaCookieOperDefaultImpl()); - } - } - - - - - - - - -} diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/spring/SpringSaToken.java b/sa-token-dev/src/main/java/cn/dev33/satoken/spring/SpringSaToken.java deleted file mode 100644 index 0d00e20c..00000000 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/spring/SpringSaToken.java +++ /dev/null @@ -1,80 +0,0 @@ -package cn.dev33.satoken.spring; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Component; - -import cn.dev33.satoken.SaTokenManager; -import cn.dev33.satoken.action.SaTokenAction; -import cn.dev33.satoken.config.SaTokenConfig; -import cn.dev33.satoken.cookie.SaCookieOper; -import cn.dev33.satoken.dao.SaTokenDao; -import cn.dev33.satoken.stp.StpInterface; - -/** - * 与SpringBoot集成, 保证此类被扫描,即可完成sa-token与SpringBoot的集成 - * @author kong - * - */ -@Component -public class SpringSaToken { - - - /** - * 获取配置Bean - * @return . - */ - @Bean - @ConfigurationProperties(prefix="spring.sa-token") - public SaTokenConfig getSaTokenConfig() { - return new SaTokenConfig(); - } - - /** - * 注入配置Bean - * @param saTokenConfig . - */ - @Autowired - public void setConfig(SaTokenConfig saTokenConfig){ - SaTokenManager.setConfig(saTokenConfig); - } - - /** - * 注入持久化Bean - * @param dao . - */ - @Autowired(required = false) - public void setDao(SaTokenDao dao){ - SaTokenManager.setDao(dao); - } - - /** - * 注入权限认证Bean - * @param stp . - */ - @Autowired(required = false) - public void setStp(StpInterface stp){ - SaTokenManager.setStp(stp); - } - - /** - * 注入Cookie操作Bean - * @param saCookieOper . - */ - @Autowired(required = false) - public void setSaCookieOper(SaCookieOper saCookieOper){ - SaTokenManager.setSaCookieOper(saCookieOper); - } - - /** - * 注入框架行为Bean - * @param sta . - */ - @Autowired(required = false) - public void setSta(SaTokenAction sta){ - SaTokenManager.setSta(sta); - } - - -} diff --git a/sa-token-doc/index.css b/sa-token-doc/index.css index 9b07d97e..b2c15461 100644 --- a/sa-token-doc/index.css +++ b/sa-token-doc/index.css @@ -67,7 +67,7 @@ footer a:hover{text-decoration: underline;} } /* 闪光背景 */ -.main-box{ +.z-div{ background-size: 500%; background-image: linear-gradient(125deg,#BFFEBE,#F6F8B5,#FCD0B3,#BFB6F8,#E8D8B3); animation: bganimation 15s infinite; diff --git a/sa-token-doc/index.html b/sa-token-doc/index.html index 7f0c9779..95d88b06 100644 --- a/sa-token-doc/index.html +++ b/sa-token-doc/index.html @@ -14,7 +14,7 @@ -
+
diff --git a/sa-token-spring-boot-starter/.gitignore b/sa-token-spring-boot-starter/.gitignore new file mode 100644 index 00000000..f56feec7 --- /dev/null +++ b/sa-token-spring-boot-starter/.gitignore @@ -0,0 +1,12 @@ +target/ + +node_modules/ +bin/ +.settings/ +unpackage/ +.classpath +.project + +.factorypath + +.idea/ \ No newline at end of file diff --git a/sa-token-dev/pom.xml b/sa-token-spring-boot-starter/pom.xml similarity index 52% rename from sa-token-dev/pom.xml rename to sa-token-spring-boot-starter/pom.xml index 532eb6e9..1aaffc84 100644 --- a/sa-token-dev/pom.xml +++ b/sa-token-spring-boot-starter/pom.xml @@ -1,41 +1,39 @@ + + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - - cn.dev33 - sa-token-dev - jar - 1.6.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.1.0.RELEASE - + cn.dev33 + sa-token-parent + 1.6.0 + + jar + + sa-token-spring-boot-starter + sa-token-spring-boot-starter + springboot integrate sa-token - - + + cn.dev33 + sa-token-core + 1.6.0 + org.springframework.boot spring-boot-starter-web + 2.0.0.RELEASE - - org.springframework.boot - spring-boot-starter-aop - - - org.springframework.boot spring-boot-configuration-processor + 2.0.0.RELEASE true - - - - \ No newline at end of file + + + + diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/spring/SaTokenSetup.java b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/autowired/SaTokenSetup.java similarity index 87% rename from sa-token-dev/src/main/java/cn/dev33/satoken/spring/SaTokenSetup.java rename to sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/autowired/SaTokenSetup.java index 0bb7e1aa..69a68e47 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/spring/SaTokenSetup.java +++ b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/autowired/SaTokenSetup.java @@ -1,4 +1,4 @@ -package cn.dev33.satoken.spring; +package cn.dev33.satoken.autowired; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -17,7 +17,7 @@ import org.springframework.context.annotation.Import; @Target({java.lang.annotation.ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Configuration -@Import({SpringSaToken.class}) +@Import({SaTokenSpringAutowired.class}) public @interface SaTokenSetup { } diff --git a/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/autowired/SaTokenSpringAutowired.java b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/autowired/SaTokenSpringAutowired.java new file mode 100644 index 00000000..456724f5 --- /dev/null +++ b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/autowired/SaTokenSpringAutowired.java @@ -0,0 +1,100 @@ +package cn.dev33.satoken.autowired; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +import cn.dev33.satoken.SaTokenManager; +import cn.dev33.satoken.action.SaTokenAction; +import cn.dev33.satoken.config.SaTokenConfig; +import cn.dev33.satoken.cookie.SaTokenCookie; +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.servlet.SaTokenServlet; +import cn.dev33.satoken.spring.SaTokenServletSpringImpl; +import cn.dev33.satoken.stp.StpInterface; + +/** + * 利用spring的自动装配来加载开发者重写的Bean + * @author kong + * + */ +@Component +public class SaTokenSpringAutowired { + + + /** + * 获取配置Bean + * @return . + */ + @Bean + @ConfigurationProperties(prefix="spring.sa-token") + public SaTokenConfig getSaTokenConfig() { + return new SaTokenConfig(); + } + + /** + * 注入配置Bean + * @param saTokenConfig . + */ + @Autowired + public void setConfig(SaTokenConfig saTokenConfig){ + SaTokenManager.setConfig(saTokenConfig); + } + + /** + * 注入持久化Bean + * @param saTokenDao . + */ + @Autowired(required = false) + public void setSaTokenDao(SaTokenDao saTokenDao){ + SaTokenManager.setSaTokenDao(saTokenDao); + } + + /** + * 注入权限认证Bean + * @param stpInterface . + */ + @Autowired(required = false) + public void setStpInterface(StpInterface stpInterface){ + SaTokenManager.setStpInterface(stpInterface); + } + + /** + * 注入Cookie操作Bean + * @param saTokenCookie . + */ + @Autowired(required = false) + public void setSaTokenCookie(SaTokenCookie saTokenCookie){ + SaTokenManager.setSaTokenCookie(saTokenCookie); + } + + /** + * 注入框架行为Bean + * @param saTokenAction . + */ + @Autowired(required = false) + public void setSaTokenAction(SaTokenAction saTokenAction){ + SaTokenManager.setSaTokenAction(saTokenAction); + } + + /** + * 获取Servlet操作Bean (Spring版) + * @return Servlet操作Bean (Spring版) + */ + @Bean + public SaTokenServlet getSaTokenServlet() { + return new SaTokenServletSpringImpl(); + } + + /** + * 注入Servlet操作Bean + * @param saTokenServlet . + */ + @Autowired + public void setSaTokenServlet(SaTokenServlet saTokenServlet){ + SaTokenManager.setSaTokenServlet(saTokenServlet); + } + + +} diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/annotation/SaCheckInterceptor.java b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/interceptor/SaCheckInterceptor.java similarity index 94% rename from sa-token-dev/src/main/java/cn/dev33/satoken/annotation/SaCheckInterceptor.java rename to sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/interceptor/SaCheckInterceptor.java index eeb821ef..cd7a50e2 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/annotation/SaCheckInterceptor.java +++ b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/interceptor/SaCheckInterceptor.java @@ -1,4 +1,4 @@ -package cn.dev33.satoken.annotation; +package cn.dev33.satoken.interceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -6,6 +6,8 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; +import cn.dev33.satoken.annotation.SaCheckLogin; +import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.stp.StpLogic; import cn.dev33.satoken.stp.StpUtil; diff --git a/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SaTokenServletSpringImpl.java b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SaTokenServletSpringImpl.java new file mode 100644 index 00000000..2b702136 --- /dev/null +++ b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SaTokenServletSpringImpl.java @@ -0,0 +1,32 @@ +package cn.dev33.satoken.spring; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import cn.dev33.satoken.servlet.SaTokenServlet; + +/** + * sa-token 对cookie的相关操作 接口实现类 + * @author kong + * + */ +public class SaTokenServletSpringImpl implements SaTokenServlet { + + /** + * 获取当前请求的Request对象 + */ + @Override + public HttpServletRequest getRequest() { + return SpringMVCUtil.getRequest(); + } + + + /** + * 获取当前请求的Response对象 + */ + @Override + public HttpServletResponse getResponse() { + return SpringMVCUtil.getResponse(); + } + +} diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/util/SpringMvcUtil.java b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java similarity index 92% rename from sa-token-dev/src/main/java/cn/dev33/satoken/util/SpringMvcUtil.java rename to sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java index d89e10d7..40f06ece 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/util/SpringMvcUtil.java +++ b/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/spring/SpringMVCUtil.java @@ -1,4 +1,4 @@ -package cn.dev33.satoken.util; +package cn.dev33.satoken.spring; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -11,11 +11,11 @@ import org.springframework.web.context.request.ServletRequestAttributes; * @author kong * */ -public class SpringMvcUtil { +public class SpringMVCUtil { /** * 获取当前会话的 request - * @return + * @return . */ public static HttpServletRequest getRequest() { ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();// 大善人SpringMVC提供的封装 @@ -27,7 +27,7 @@ public class SpringMvcUtil { /** * 获取当前会话的 response - * @return + * @return . */ public static HttpServletResponse getResponse() { ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();// 大善人SpringMVC提供的封装 diff --git a/sa-token-spring-boot-starter/src/main/resources/META-INF/spring.factories b/sa-token-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..6a715ced --- /dev/null +++ b/sa-token-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.dev33.satoken.autowired.SaTokenSpringAutowired \ No newline at end of file diff --git a/sp-token-core/.gitignore b/sp-token-core/.gitignore new file mode 100644 index 00000000..f56feec7 --- /dev/null +++ b/sp-token-core/.gitignore @@ -0,0 +1,12 @@ +target/ + +node_modules/ +bin/ +.settings/ +unpackage/ +.classpath +.project + +.factorypath + +.idea/ \ No newline at end of file diff --git a/sp-token-core/pom.xml b/sp-token-core/pom.xml new file mode 100644 index 00000000..7e29a7ac --- /dev/null +++ b/sp-token-core/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + + cn.dev33 + sa-token-parent + 1.6.0 + + jar + + sa-token-core + sa-token-core + A Java Web lightweight authority authentication framework, comprehensive function, easy to use + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + + + + diff --git a/sp-token-core/src/main/java/cn/dev33/satoken/SaTokenManager.java b/sp-token-core/src/main/java/cn/dev33/satoken/SaTokenManager.java new file mode 100644 index 00000000..dc01b0b7 --- /dev/null +++ b/sp-token-core/src/main/java/cn/dev33/satoken/SaTokenManager.java @@ -0,0 +1,149 @@ +package cn.dev33.satoken; + +import cn.dev33.satoken.action.SaTokenAction; +import cn.dev33.satoken.action.SaTokenActionDefaultImpl; +import cn.dev33.satoken.config.SaTokenConfig; +import cn.dev33.satoken.config.SaTokenConfigFactory; +import cn.dev33.satoken.cookie.SaTokenCookie; +import cn.dev33.satoken.cookie.SaTokenCookieDefaultImpl; +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.dao.SaTokenDaoDefaultImpl; +import cn.dev33.satoken.servlet.SaTokenServlet; +import cn.dev33.satoken.servlet.SaTokenServletDefaultImpl; +import cn.dev33.satoken.stp.StpInterface; +import cn.dev33.satoken.stp.StpInterfaceDefaultImpl; +import cn.dev33.satoken.util.SaTokenInsideUtil; + +/** + * 管理sa-token所有对象 + * @author kong + * + */ +public class SaTokenManager { + + + /** + * 配置文件 Bean + */ + private static SaTokenConfig config; + public static SaTokenConfig getConfig() { + if (config == null) { + initConfig(); + } + return config; + } + public static void setConfig(SaTokenConfig config) { + SaTokenManager.config = config; + if(config.getIsV()) { + SaTokenInsideUtil.printSaToken(); + } + } + public synchronized static void initConfig() { + if (config == null) { + setConfig(SaTokenConfigFactory.createConfig()); + } + } + + /** + * 持久化 Bean + */ + public static SaTokenDao saTokenDao; + public static SaTokenDao getSaTokenDao() { + if (saTokenDao == null) { + initSaTokenDao(); + } + return saTokenDao; + } + public static void setSaTokenDao(SaTokenDao saTokenDao) { + SaTokenManager.saTokenDao = saTokenDao; + } + public synchronized static void initSaTokenDao() { + if (saTokenDao == null) { + setSaTokenDao(new SaTokenDaoDefaultImpl()); + } + } + + /** + * 权限认证 Bean + */ + public static StpInterface stpInterface; + public static StpInterface getStpInterface() { + if (stpInterface == null) { + initStpInterface(); + } + return stpInterface; + } + public static void setStpInterface(StpInterface stpInterface) { + SaTokenManager.stpInterface = stpInterface; + } + public synchronized static void initStpInterface() { + if (stpInterface == null) { + setStpInterface(new StpInterfaceDefaultImpl()); + } + } + + /** + * 框架行为 Bean + */ + public static SaTokenAction saTokenAction; + public static SaTokenAction getSaTokenAction() { + if (saTokenAction == null) { + initSaTokenAction(); + } + return saTokenAction; + } + public static void setSaTokenAction(SaTokenAction saTokenAction) { + SaTokenManager.saTokenAction = saTokenAction; + } + public synchronized static void initSaTokenAction() { + if (saTokenAction == null) { + setSaTokenAction(new SaTokenActionDefaultImpl()); + } + } + + /** + * Cookie操作 Bean + */ + public static SaTokenCookie saTokenCookie; + public static SaTokenCookie getSaTokenCookie() { + if (saTokenCookie == null) { + initSaTokenCookie(); + } + return saTokenCookie; + } + public static void setSaTokenCookie(SaTokenCookie saTokenCookie) { + SaTokenManager.saTokenCookie = saTokenCookie; + } + public synchronized static void initSaTokenCookie() { + if (saTokenCookie == null) { + setSaTokenCookie(new SaTokenCookieDefaultImpl()); + } + } + + /** + * Servlet操作 Bean + */ + public static SaTokenServlet saTokenServlet; + public static SaTokenServlet getSaTokenServlet() { + if (saTokenServlet == null) { + initSaTokenServlet(); + } + return saTokenServlet; + } + public static void setSaTokenServlet(SaTokenServlet saTokenServlet) { + SaTokenManager.saTokenServlet = saTokenServlet; + } + public synchronized static void initSaTokenServlet() { + if (saTokenServlet == null) { + setSaTokenServlet(new SaTokenServletDefaultImpl()); + } + } + + + + + + + + +} diff --git a/sp-token-core/src/main/java/cn/dev33/satoken/action/SaTokenAction.java b/sp-token-core/src/main/java/cn/dev33/satoken/action/SaTokenAction.java new file mode 100644 index 00000000..20e2c549 --- /dev/null +++ b/sp-token-core/src/main/java/cn/dev33/satoken/action/SaTokenAction.java @@ -0,0 +1,15 @@ +package cn.dev33.satoken.action; + +public interface SaTokenAction { + + + /** + * 生成一个token + * @param loginId 账号id + * @param loginKey 登录标识key + * @return 一个token + */ + public String createToken(Object loginId, String loginKey); + + +} diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/action/SaTokenActionDefaultImpl.java b/sp-token-core/src/main/java/cn/dev33/satoken/action/SaTokenActionDefaultImpl.java similarity index 75% rename from sa-token-dev/src/main/java/cn/dev33/satoken/action/SaTokenActionDefaultImpl.java rename to sp-token-core/src/main/java/cn/dev33/satoken/action/SaTokenActionDefaultImpl.java index b2132bbd..d539bae1 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/action/SaTokenActionDefaultImpl.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/action/SaTokenActionDefaultImpl.java @@ -2,12 +2,8 @@ package cn.dev33.satoken.action; import java.util.UUID; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import cn.dev33.satoken.SaTokenManager; import cn.dev33.satoken.util.SaTokenInsideUtil; -import cn.dev33.satoken.util.SpringMvcUtil; /** * 对 SaTokenAction 接口的默认实现 @@ -16,23 +12,6 @@ import cn.dev33.satoken.util.SpringMvcUtil; */ public class SaTokenActionDefaultImpl implements SaTokenAction { - /** - * 获取当前请求的Request对象 - */ - @Override - public HttpServletRequest getCurrRequest() { - return SpringMvcUtil.getRequest(); - } - - - /** - * 获取当前请求的Response对象 - */ - @Override - public HttpServletResponse getResponse() { - return SpringMvcUtil.getResponse(); - } - /** * 生成一个token diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/annotation/SaCheckLogin.java b/sp-token-core/src/main/java/cn/dev33/satoken/annotation/SaCheckLogin.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/annotation/SaCheckLogin.java rename to sp-token-core/src/main/java/cn/dev33/satoken/annotation/SaCheckLogin.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/annotation/SaCheckPermission.java b/sp-token-core/src/main/java/cn/dev33/satoken/annotation/SaCheckPermission.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/annotation/SaCheckPermission.java rename to sp-token-core/src/main/java/cn/dev33/satoken/annotation/SaCheckPermission.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/config/SaTokenConfig.java b/sp-token-core/src/main/java/cn/dev33/satoken/config/SaTokenConfig.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/config/SaTokenConfig.java rename to sp-token-core/src/main/java/cn/dev33/satoken/config/SaTokenConfig.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/config/SaTokenConfigFactory.java b/sp-token-core/src/main/java/cn/dev33/satoken/config/SaTokenConfigFactory.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/config/SaTokenConfigFactory.java rename to sp-token-core/src/main/java/cn/dev33/satoken/config/SaTokenConfigFactory.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/cookie/SaCookieOper.java b/sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookie.java similarity index 97% rename from sa-token-dev/src/main/java/cn/dev33/satoken/cookie/SaCookieOper.java rename to sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookie.java index bc6c82c0..e501eb11 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/cookie/SaCookieOper.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookie.java @@ -9,7 +9,7 @@ import javax.servlet.http.HttpServletResponse; * @author kong * */ -public interface SaCookieOper { +public interface SaTokenCookie { /** * 获取指定cookie . diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/cookie/SaCookieOperDefaultImpl.java b/sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookieDefaultImpl.java similarity index 69% rename from sa-token-dev/src/main/java/cn/dev33/satoken/cookie/SaCookieOperDefaultImpl.java rename to sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookieDefaultImpl.java index a5d2e09b..f8068e19 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/cookie/SaCookieOperDefaultImpl.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookieDefaultImpl.java @@ -4,41 +4,39 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import cn.dev33.satoken.util.SaCookieUtil; - /** * sa-token 对cookie的相关操作 接口实现类 * @author kong * */ -public class SaCookieOperDefaultImpl implements SaCookieOper { +public class SaTokenCookieDefaultImpl implements SaTokenCookie { /** * 获取指定cookie */ public Cookie getCookie(HttpServletRequest request, String cookieName) { - return SaCookieUtil.getCookie(request, cookieName); + return SaTokenCookieUtil.getCookie(request, cookieName); } /** * 添加cookie */ public void addCookie(HttpServletResponse response, String name, String value, String path, int timeout) { - SaCookieUtil.addCookie(response, name, value, path, timeout); + SaTokenCookieUtil.addCookie(response, name, value, path, timeout); } /** * 删除cookie */ public void delCookie(HttpServletRequest request, HttpServletResponse response, String name) { - SaCookieUtil.delCookie(request, response, name); + SaTokenCookieUtil.delCookie(request, response, name); } /** * 修改cookie的value值 */ public void updateCookie(HttpServletRequest request, HttpServletResponse response, String name, String value) { - SaCookieUtil.updateCookie(request, response, name, value); + SaTokenCookieUtil.updateCookie(request, response, name, value); } } diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/util/SaCookieUtil.java b/sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookieUtil.java similarity index 96% rename from sa-token-dev/src/main/java/cn/dev33/satoken/util/SaCookieUtil.java rename to sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookieUtil.java index 7946a0ae..74edb933 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/util/SaCookieUtil.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/cookie/SaTokenCookieUtil.java @@ -1,4 +1,4 @@ -package cn.dev33.satoken.util; +package cn.dev33.satoken.cookie; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -10,7 +10,7 @@ import javax.servlet.http.HttpServletResponse; * @author kong * */ -public class SaCookieUtil { +public class SaTokenCookieUtil { /** * 获取指定cookie . diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/dao/SaTokenDao.java b/sp-token-core/src/main/java/cn/dev33/satoken/dao/SaTokenDao.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/dao/SaTokenDao.java rename to sp-token-core/src/main/java/cn/dev33/satoken/dao/SaTokenDao.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/dao/SaTokenDaoDefaultImpl.java b/sp-token-core/src/main/java/cn/dev33/satoken/dao/SaTokenDaoDefaultImpl.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/dao/SaTokenDaoDefaultImpl.java rename to sp-token-core/src/main/java/cn/dev33/satoken/dao/SaTokenDaoDefaultImpl.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/exception/NotLoginException.java b/sp-token-core/src/main/java/cn/dev33/satoken/exception/NotLoginException.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/exception/NotLoginException.java rename to sp-token-core/src/main/java/cn/dev33/satoken/exception/NotLoginException.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/exception/NotPermissionException.java b/sp-token-core/src/main/java/cn/dev33/satoken/exception/NotPermissionException.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/exception/NotPermissionException.java rename to sp-token-core/src/main/java/cn/dev33/satoken/exception/NotPermissionException.java diff --git a/sp-token-core/src/main/java/cn/dev33/satoken/exception/SaTokenException.java b/sp-token-core/src/main/java/cn/dev33/satoken/exception/SaTokenException.java new file mode 100644 index 00000000..f1c69e25 --- /dev/null +++ b/sp-token-core/src/main/java/cn/dev33/satoken/exception/SaTokenException.java @@ -0,0 +1,21 @@ +package cn.dev33.satoken.exception; + +/** + * sa-token框架内部逻辑发生错误抛出的异常 + * @author kong + * + */ +public class SaTokenException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 6806129545290130132L; + + + public SaTokenException(String message) { + super(message); + } + + +} diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/action/SaTokenAction.java b/sp-token-core/src/main/java/cn/dev33/satoken/servlet/SaTokenServlet.java similarity index 51% rename from sa-token-dev/src/main/java/cn/dev33/satoken/action/SaTokenAction.java rename to sp-token-core/src/main/java/cn/dev33/satoken/servlet/SaTokenServlet.java index 74adf6f5..d9a891c0 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/action/SaTokenAction.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/servlet/SaTokenServlet.java @@ -1,16 +1,21 @@ -package cn.dev33.satoken.action; +package cn.dev33.satoken.servlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -public interface SaTokenAction { +/** + * Servlet相关操作 + * @author kong + * + */ +public interface SaTokenServlet { + - /** * 获取当前请求的Request对象 * @return 当前请求的Request对象 */ - public HttpServletRequest getCurrRequest(); + public HttpServletRequest getRequest(); /** * 获取当前会话的 response @@ -18,13 +23,5 @@ public interface SaTokenAction { */ public HttpServletResponse getResponse(); - /** - * 生成一个token - * @param loginId 账号id - * @param loginKey 登录标识key - * @return 一个token - */ - public String createToken(Object loginId, String loginKey); - } diff --git a/sp-token-core/src/main/java/cn/dev33/satoken/servlet/SaTokenServletDefaultImpl.java b/sp-token-core/src/main/java/cn/dev33/satoken/servlet/SaTokenServletDefaultImpl.java new file mode 100644 index 00000000..c515f69b --- /dev/null +++ b/sp-token-core/src/main/java/cn/dev33/satoken/servlet/SaTokenServletDefaultImpl.java @@ -0,0 +1,30 @@ +package cn.dev33.satoken.servlet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * sa-token 对Servlet的相关操作 接口默认实现类 + * @author kong + * + */ +public class SaTokenServletDefaultImpl implements SaTokenServlet { + + /** + * 获取当前请求的Request对象 + */ + @Override + public HttpServletRequest getRequest() { + throw new RuntimeException("请实现SaTokenServlet接口后进行Servlet相关操作"); + } + + + /** + * 获取当前请求的Response对象 + */ + @Override + public HttpServletResponse getResponse() { + throw new RuntimeException("请实现SaTokenServlet接口后进行Servlet相关操作"); + } + +} diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/session/SaSession.java b/sp-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java similarity index 97% rename from sa-token-dev/src/main/java/cn/dev33/satoken/session/SaSession.java rename to sp-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java index 21b9864d..a2871405 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/session/SaSession.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java @@ -137,7 +137,7 @@ public class SaSession implements Serializable { * 将这个session从持久库更新一下 */ public void update() { - SaTokenManager.getDao().updateSaSession(this); + SaTokenManager.getSaTokenDao().updateSaSession(this); } diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/session/SaSessionCustomUtil.java b/sp-token-core/src/main/java/cn/dev33/satoken/session/SaSessionCustomUtil.java similarity index 78% rename from sa-token-dev/src/main/java/cn/dev33/satoken/session/SaSessionCustomUtil.java rename to sp-token-core/src/main/java/cn/dev33/satoken/session/SaSessionCustomUtil.java index 385a24b5..0e8f38e3 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/session/SaSessionCustomUtil.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/session/SaSessionCustomUtil.java @@ -23,7 +23,7 @@ public class SaSessionCustomUtil { * @return 是否存在 */ public boolean isExists(String sessionId) { - return SaTokenManager.getDao().getSaSession(getSessionKey(sessionId)) != null; + return SaTokenManager.getSaTokenDao().getSaSession(getSessionKey(sessionId)) != null; } /** @@ -33,10 +33,10 @@ public class SaSessionCustomUtil { * @return SaSession */ public static SaSession getSessionById(String sessionId, boolean isCreate) { - SaSession session = SaTokenManager.getDao().getSaSession(getSessionKey(sessionId)); + SaSession session = SaTokenManager.getSaTokenDao().getSaSession(getSessionKey(sessionId)); if(session == null && isCreate) { session = new SaSession(getSessionKey(sessionId)); - SaTokenManager.getDao().saveSaSession(session, SaTokenManager.getConfig().getTimeout()); + SaTokenManager.getSaTokenDao().saveSaSession(session, SaTokenManager.getConfig().getTimeout()); } return session; } @@ -54,7 +54,7 @@ public class SaSessionCustomUtil { * @param sessionId 删除指定key */ public static void deleteSessionById(String sessionId) { - SaTokenManager.getDao().deleteSaSession(getSessionKey(sessionId)); + SaTokenManager.getSaTokenDao().deleteSaSession(getSessionKey(sessionId)); } diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpInterface.java b/sp-token-core/src/main/java/cn/dev33/satoken/stp/StpInterface.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpInterface.java rename to sp-token-core/src/main/java/cn/dev33/satoken/stp/StpInterface.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpInterfaceDefaultImpl.java b/sp-token-core/src/main/java/cn/dev33/satoken/stp/StpInterfaceDefaultImpl.java similarity index 100% rename from sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpInterfaceDefaultImpl.java rename to sp-token-core/src/main/java/cn/dev33/satoken/stp/StpInterfaceDefaultImpl.java diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpLogic.java b/sp-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java similarity index 85% rename from sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpLogic.java rename to sp-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java index 7dea87b2..3490375c 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpLogic.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java @@ -53,7 +53,7 @@ public class StpLogic { * @return 生成的tokenValue */ public String randomTokenValue(Object loginId) { - return SaTokenManager.getSta().createToken(loginId, loginKey); + return SaTokenManager.getSaTokenAction().createToken(loginId, loginKey); } /** @@ -62,7 +62,7 @@ public class StpLogic { */ public String getTokenValue(){ // 0、获取相应对象 - HttpServletRequest request = SaTokenManager.getSta().getCurrRequest(); + HttpServletRequest request = SaTokenManager.getSaTokenServlet().getRequest(); SaTokenConfig config = SaTokenManager.getConfig(); String keyTokenName = getTokenName(); @@ -86,7 +86,7 @@ public class StpLogic { } // 4、尝试从cookie里读取 if(config.getIsReadCookie() == true){ - Cookie cookie = SaTokenManager.getSaCookieOper().getCookie(request, keyTokenName); + Cookie cookie = SaTokenManager.getSaTokenCookie().getCookie(request, keyTokenName); if(cookie != null){ String tokenValue = cookie.getValue(); if(tokenValue != null) { @@ -104,7 +104,7 @@ public class StpLogic { * @return . */ public String getTokenValueByLoginId(Object loginId) { - return SaTokenManager.getDao().getValue(getKeyLoginId(loginId)); + return SaTokenManager.getSaTokenDao().getValue(getKeyLoginId(loginId)); } /** @@ -128,9 +128,9 @@ public class StpLogic { public void setLoginId(Object loginId) { // 1、获取相应对象 - HttpServletRequest request = SaTokenManager.getSta().getCurrRequest(); + HttpServletRequest request = SaTokenManager.getSaTokenServlet().getRequest(); SaTokenConfig config = SaTokenManager.getConfig(); - SaTokenDao dao = SaTokenManager.getDao(); + SaTokenDao dao = SaTokenManager.getSaTokenDao(); // 2、获取tokenValue String tokenValue = getTokenValueByLoginId(loginId); // 获取旧tokenValue @@ -150,7 +150,7 @@ public class StpLogic { dao.setValue(getKeyLoginId(loginId), tokenValue, config.getTimeout()); // uid -> token request.setAttribute(SaTokenInsideUtil.JUST_CREATED_SAVE_KEY, tokenValue); // 保存到本次request里 if(config.getIsReadCookie() == true){ - SaTokenManager.getSaCookieOper().addCookie(SaTokenManager.getSta().getResponse(), getTokenName(), tokenValue, "/", (int)config.getTimeout()); // cookie注入 + SaTokenManager.getSaTokenCookie().addCookie(SaTokenManager.getSaTokenServlet().getResponse(), getTokenName(), tokenValue, "/", (int)config.getTimeout()); // cookie注入 } } @@ -165,10 +165,10 @@ public class StpLogic { } // 如果打开了cookie模式,第一步,先把cookie清除掉 if(SaTokenManager.getConfig().getIsReadCookie() == true){ - SaTokenManager.getSaCookieOper().delCookie(SaTokenManager.getSta().getCurrRequest(), SaTokenManager.getSta().getResponse(), getTokenName()); + SaTokenManager.getSaTokenCookie().delCookie(SaTokenManager.getSaTokenServlet().getRequest(), SaTokenManager.getSaTokenServlet().getResponse(), getTokenName()); } // 尝试从db中获取loginId值 - String loginId = SaTokenManager.getDao().getValue(getKeyTokenValue(tokenValue)); + String loginId = SaTokenManager.getSaTokenDao().getValue(getKeyTokenValue(tokenValue)); // 如果根本查不到loginId,那么也无需执行任何操作 if(loginId == null) { return; @@ -194,9 +194,9 @@ public class StpLogic { } // 清除相关数据 - SaTokenManager.getDao().delKey(getKeyTokenValue(tokenValue)); // 清除token-id键值对 - SaTokenManager.getDao().delKey(getKeyLoginId(loginId)); // 清除id-token键值对 - SaTokenManager.getDao().deleteSaSession(getKeySession(loginId)); // 清除其session + SaTokenManager.getSaTokenDao().delKey(getKeyTokenValue(tokenValue)); // 清除token-id键值对 + SaTokenManager.getSaTokenDao().delKey(getKeyLoginId(loginId)); // 清除id-token键值对 + SaTokenManager.getSaTokenDao().deleteSaSession(getKeySession(loginId)); // 清除其session } /** @@ -212,9 +212,9 @@ public class StpLogic { } // 清除相关数据 - SaTokenManager.getDao().updateValue(getKeyTokenValue(tokenValue), NotLoginException.KICK_OUT); // 标记:已被踢下线 - SaTokenManager.getDao().delKey(getKeyLoginId(loginId)); // 清除id-token键值对 - SaTokenManager.getDao().deleteSaSession(getKeySession(loginId)); // 清除其session + SaTokenManager.getSaTokenDao().updateValue(getKeyTokenValue(tokenValue), NotLoginException.KICK_OUT); // 标记:已被踢下线 + SaTokenManager.getSaTokenDao().delKey(getKeyLoginId(loginId)); // 清除id-token键值对 + SaTokenManager.getSaTokenDao().deleteSaSession(getKeySession(loginId)); // 清除其session } // 查询相关 @@ -246,7 +246,7 @@ public class StpLogic { throw NotLoginException.newInstance(loginKey, NotLoginException.NOT_TOKEN); } // 查找此token对应loginId, 则抛出:无效token - String loginId = SaTokenManager.getDao().getValue(getKeyTokenValue(tokenValue)); + String loginId = SaTokenManager.getSaTokenDao().getValue(getKeyTokenValue(tokenValue)); if(loginId == null) { throw NotLoginException.newInstance(loginKey, NotLoginException.INVALID_TOKEN); } @@ -302,7 +302,7 @@ public class StpLogic { return null; } // loginId为null或者在异常项里面,均视为未登录 - Object loginId = SaTokenManager.getDao().getValue(getKeyTokenValue(tokenValue)); + Object loginId = SaTokenManager.getSaTokenDao().getValue(getKeyTokenValue(tokenValue)); if(loginId == null || NotLoginException.ABNORMAL_LIST.contains(loginId)) { return null; } @@ -348,7 +348,7 @@ public class StpLogic { */ public Object getLoginIdByToken(String tokenValue) { if(tokenValue != null) { - Object loginId = SaTokenManager.getDao().getValue(getKeyTokenValue(tokenValue)); + Object loginId = SaTokenManager.getSaTokenDao().getValue(getKeyTokenValue(tokenValue)); if(loginId != null) { return loginId; } @@ -366,10 +366,10 @@ public class StpLogic { * @return . */ protected SaSession getSessionBySessionId(String sessionId, boolean isCreate) { - SaSession session = SaTokenManager.getDao().getSaSession(sessionId); + SaSession session = SaTokenManager.getSaTokenDao().getSaSession(sessionId); if(session == null && isCreate) { session = new SaSession(sessionId); - SaTokenManager.getDao().saveSaSession(session, SaTokenManager.getConfig().getTimeout()); + SaTokenManager.getSaTokenDao().saveSaSession(session, SaTokenManager.getConfig().getTimeout()); } return session; } @@ -412,7 +412,7 @@ public class StpLogic { * @return . */ public boolean hasPermission(Object loginId, Object pcode) { - List pcodeList = SaTokenManager.getStp().getPermissionCodeList(loginId, loginKey); + List pcodeList = SaTokenManager.getStpInterface().getPermissionCodeList(loginId, loginKey); return !(pcodeList == null || pcodeList.contains(pcode) == false); } @@ -441,7 +441,7 @@ public class StpLogic { */ public void checkPermissionAnd(Object... pcodeArray){ Object loginId = getLoginId(); - List pcodeList = SaTokenManager.getStp().getPermissionCodeList(loginId, loginKey); + List pcodeList = SaTokenManager.getStpInterface().getPermissionCodeList(loginId, loginKey); for (Object pcode : pcodeArray) { if(pcodeList.contains(pcode) == false) { throw new NotPermissionException(pcode, this.loginKey); // 没有权限抛出异常 @@ -455,7 +455,7 @@ public class StpLogic { */ public void checkPermissionOr(Object... pcodeArray){ Object loginId = getLoginId(); - List pcodeList = SaTokenManager.getStp().getPermissionCodeList(loginId, loginKey); + List pcodeList = SaTokenManager.getStpInterface().getPermissionCodeList(loginId, loginKey); for (Object pcode : pcodeArray) { if(pcodeList.contains(pcode) == true) { return; // 有的话提前退出 diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpUtil.java b/sp-token-core/src/main/java/cn/dev33/satoken/stp/StpUtil.java similarity index 98% rename from sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpUtil.java rename to sp-token-core/src/main/java/cn/dev33/satoken/stp/StpUtil.java index 70433c10..f7ac33db 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/stp/StpUtil.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/stp/StpUtil.java @@ -2,15 +2,12 @@ package cn.dev33.satoken.stp; import java.util.Map; -import org.springframework.stereotype.Service; - import cn.dev33.satoken.session.SaSession; /** * 一个默认的实现 * @author kong */ -@Service public class StpUtil { /** diff --git a/sa-token-dev/src/main/java/cn/dev33/satoken/util/SaTokenInsideUtil.java b/sp-token-core/src/main/java/cn/dev33/satoken/util/SaTokenInsideUtil.java similarity index 94% rename from sa-token-dev/src/main/java/cn/dev33/satoken/util/SaTokenInsideUtil.java rename to sp-token-core/src/main/java/cn/dev33/satoken/util/SaTokenInsideUtil.java index b4f16d0c..447c8c53 100644 --- a/sa-token-dev/src/main/java/cn/dev33/satoken/util/SaTokenInsideUtil.java +++ b/sp-token-core/src/main/java/cn/dev33/satoken/util/SaTokenInsideUtil.java @@ -18,7 +18,7 @@ public class SaTokenInsideUtil { /** * sa-token 开源地址 */ - public static final String GITHUB_URL= "https://github.com/click33/sa-token"; + public static final String GITHUB_URL = "https://github.com/click33/sa-token"; /** * 打印 sa-token