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