diff --git a/continew-starter-auth/continew-starter-auth-satoken/pom.xml b/continew-starter-auth/continew-starter-auth-satoken/pom.xml
new file mode 100644
index 00000000..82f4211b
--- /dev/null
+++ b/continew-starter-auth/continew-starter-auth-satoken/pom.xml
@@ -0,0 +1,31 @@
+
+
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.gnu.org/licenses/lgpl.html + *
+ * 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. + */ + +package top.charles7c.continew.starter.auth.satoken.autoconfigure; + +import cn.dev33.satoken.dao.SaTokenDao; +import cn.dev33.satoken.interceptor.SaInterceptor; +import cn.dev33.satoken.jwt.StpLogicJwtForSimple; +import cn.dev33.satoken.stp.StpInterface; +import cn.dev33.satoken.stp.StpLogic; +import cn.dev33.satoken.stp.StpUtil; +import cn.hutool.core.util.ReflectUtil; +import jakarta.annotation.PostConstruct; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * Sa-Token 自动配置 + * + * @author Charles7c + * @since 1.0.0 + */ +@Slf4j +@AutoConfiguration +@RequiredArgsConstructor +@EnableConfigurationProperties(SaTokenExtensionProperties.class) +@ConditionalOnProperty(prefix = "sa-token.extension", name = "enabled", havingValue = "true") +public class SaTokenAutoConfiguration implements WebMvcConfigurer { + + private final SaTokenExtensionProperties properties; + + @Override + public void addInterceptors(InterceptorRegistry registry) { + // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验 + registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())).addPathPatterns("/**") + .excludePathPatterns(properties.getSecurity().getExcludes()); + } + + /** + * 整合 JWT(简单模式) + */ + @Bean + public StpLogic stpLogic() { + return new StpLogicJwtForSimple(); + } + + /** + * 自定义缓存实现 + */ + @Bean + @ConditionalOnMissingBean + public SaTokenDao saTokenDao() { + return ReflectUtil.newInstance(properties.getDaoImpl()); + } + + /** + * 权限认证实现 + */ + @Bean + @ConditionalOnMissingBean + public StpInterface stpInterface() { + return ReflectUtil.newInstance(properties.getPermissionImpl()); + } + + @PostConstruct + public void postConstruct() { + log.info("[ContiNew Starter] - Auto Configuration 'SaToken' completed initialization."); + } +} diff --git a/continew-starter-auth/continew-starter-auth-satoken/src/main/java/top/charles7c/continew/starter/auth/satoken/autoconfigure/SaTokenExtensionProperties.java b/continew-starter-auth/continew-starter-auth-satoken/src/main/java/top/charles7c/continew/starter/auth/satoken/autoconfigure/SaTokenExtensionProperties.java new file mode 100644 index 00000000..312e639f --- /dev/null +++ b/continew-starter-auth/continew-starter-auth-satoken/src/main/java/top/charles7c/continew/starter/auth/satoken/autoconfigure/SaTokenExtensionProperties.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.gnu.org/licenses/lgpl.html + *
+ * 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.
+ */
+
+package top.charles7c.continew.starter.auth.satoken.autoconfigure;
+
+import cn.dev33.satoken.dao.SaTokenDao;
+import cn.dev33.satoken.stp.StpInterface;
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+
+/**
+ * SaToken 扩展配置属性
+ *
+ * @author Charles7c
+ * @since 1.0.0
+ */
+@Data
+@ConfigurationProperties(prefix = "sa-token.extension")
+public class SaTokenExtensionProperties {
+
+ /**
+ * 是否启用扩展
+ */
+ private boolean enabled = false;
+
+ /**
+ * 自定义缓存实现
+ */
+ private Class extends SaTokenDao> daoImpl;
+
+ /**
+ * 权限认证实现
+ */
+ private Class extends StpInterface> permissionImpl;
+
+ /**
+ * 安全配置
+ */
+ private SecurityProperties security;
+
+ /**
+ * 安全配置属性
+ */
+ @Data
+ public static class SecurityProperties {
+
+ /**
+ * 排除(放行)路径配置
+ */
+ private String[] excludes = new String[0];
+ }
+}
diff --git a/continew-starter-auth/continew-starter-auth-satoken/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/continew-starter-auth/continew-starter-auth-satoken/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 00000000..667befd1
--- /dev/null
+++ b/continew-starter-auth/continew-starter-auth-satoken/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+top.charles7c.continew.starter.auth.satoken.autoconfigure.SaTokenAutoConfiguration
\ No newline at end of file
diff --git a/continew-starter-auth/pom.xml b/continew-starter-auth/pom.xml
new file mode 100644
index 00000000..8e6bcab3
--- /dev/null
+++ b/continew-starter-auth/pom.xml
@@ -0,0 +1,29 @@
+
+