1
0
mirror of synced 2026-05-22 14:43:15 +00:00

refactor: API Sign 模块拆分独立插件包:sa-token-sign

This commit is contained in:
click33
2025-05-15 21:21:21 +08:00
parent 9fcaf89412
commit df91c2ece0
52 changed files with 835 additions and 274 deletions
@@ -42,6 +42,20 @@
<optional>true</optional>
</dependency>
<!-- API Key (optional) -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-apikey</artifactId>
<optional>true</optional>
</dependency>
<!-- API Sign (optional) -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-sign</artifactId>
<optional>true</optional>
</dependency>
<!-- redisx + snack3 -->
<dependency>
<groupId>org.noear</groupId>
@@ -17,8 +17,6 @@ package cn.dev33.satoken.solon;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.annotation.handler.SaAnnotationHandlerInterface;
import cn.dev33.satoken.apikey.SaApiKeyTemplate;
import cn.dev33.satoken.apikey.loader.SaApiKeyDataLoader;
import cn.dev33.satoken.config.SaTokenConfig;
import cn.dev33.satoken.context.SaTokenContext;
import cn.dev33.satoken.dao.SaTokenDao;
@@ -37,7 +35,6 @@ import cn.dev33.satoken.plugin.SaTokenPluginHolder;
import cn.dev33.satoken.same.SaSameTemplate;
import cn.dev33.satoken.secure.totp.SaTotpTemplate;
import cn.dev33.satoken.serializer.SaSerializerTemplate;
import cn.dev33.satoken.sign.SaSignTemplate;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.stp.StpUtil;
@@ -222,39 +219,6 @@ public class SaBeanInject {
SaManager.setSaSerializerTemplate(saSerializerTemplate);
}
/**
* 注入自定义的 参数签名 Bean
*
* @param saSignTemplate 参数签名 Bean
*/
@Condition(onBean = SaSignTemplate.class)
@Bean
public void setSaSignTemplate(SaSignTemplate saSignTemplate) {
SaManager.setSaSignTemplate(saSignTemplate);
}
/**
* 注入自定义的 ApiKey 模块 Bean
*
* @param apiKeyTemplate /
*/
@Condition(onBean = SaApiKeyTemplate.class)
@Bean
public void setSaApiKeyTemplate(SaApiKeyTemplate apiKeyTemplate) {
SaManager.setSaApiKeyTemplate(apiKeyTemplate);
}
/**
* 注入自定义的 ApiKey 数据加载器 Bean
*
* @param apiKeyDataLoader /
*/
@Condition(onBean = SaApiKeyDataLoader.class)
@Bean
public void setSaApiKeyDataLoader(SaApiKeyDataLoader apiKeyDataLoader) {
SaManager.setSaApiKeyDataLoader(apiKeyDataLoader);
}
/**
* 注入自定义的 TOTP 算法 Bean
*
@@ -15,8 +15,12 @@
*/
package cn.dev33.satoken.solon;
import cn.dev33.satoken.solon.apikey.SaApiKeyBeanInject;
import cn.dev33.satoken.solon.apikey.SaApiKeyBeanRegister;
import cn.dev33.satoken.solon.oauth2.SaOAuth2BeanInject;
import cn.dev33.satoken.solon.oauth2.SaOAuth2BeanRegister;
import cn.dev33.satoken.solon.sign.SaSignBeanInject;
import cn.dev33.satoken.solon.sign.SaSignBeanRegister;
import cn.dev33.satoken.solon.sso.SaSsoBeanInject;
import cn.dev33.satoken.solon.sso.SaSsoBeanRegister;
import org.noear.solon.core.AppContext;
@@ -30,16 +34,24 @@ public class SaSolonPlugin implements Plugin {
@Override
public void start(AppContext context) {
//sa-token
// sa-token
context.beanMake(SaBeanRegister.class);
context.beanMake(SaBeanInject.class);
//sa-sso
// sa-sso
context.beanMake(SaSsoBeanRegister.class);
context.beanMake(SaSsoBeanInject.class);
//sa-oauth2
// sa-oauth2
context.beanMake(SaOAuth2BeanRegister.class);
context.beanMake(SaOAuth2BeanInject.class);
// sa-apikey
context.beanMake(SaApiKeyBeanRegister.class);
context.beanMake(SaApiKeyBeanInject.class);
// sa-sign
context.beanMake(SaSignBeanRegister.class);
context.beanMake(SaSignBeanInject.class);
}
}
@@ -0,0 +1,69 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* 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.
*/
package cn.dev33.satoken.solon.apikey;
import cn.dev33.satoken.apikey.SaApiKeyManager;
import cn.dev33.satoken.apikey.config.SaApiKeyConfig;
import cn.dev33.satoken.apikey.loader.SaApiKeyDataLoader;
import cn.dev33.satoken.apikey.template.SaApiKeyTemplate;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
/**
* 注入 Sa-Token API Key 所需要的 Bean
*
* @author click33
* @since 1.43.0
*/
@Condition(onClass=SaApiKeyManager.class)
@Configuration
public class SaApiKeyBeanInject {
/**
* 注入 API Key 配置对象
*
* @param saApiKeyConfig 配置对象
*/
@Bean
@Condition(onBean = SaApiKeyConfig.class)
public void setSaApiKeyConfig(SaApiKeyConfig saApiKeyConfig) {
SaApiKeyManager.setConfig(saApiKeyConfig);
}
/**
* 注入自定义的 API Key 模版方法 Bean
*
* @param apiKeyTemplate /
*/
@Bean
@Condition(onBean = SaApiKeyTemplate.class)
public void setSaApiKeyTemplate(SaApiKeyTemplate apiKeyTemplate) {
SaApiKeyManager.setSaApiKeyTemplate(apiKeyTemplate);
}
/**
* 注入自定义的 API Key 数据加载器 Bean
*
* @param apiKeyDataLoader /
*/
@Bean
@Condition(onBean = SaApiKeyDataLoader.class)
public void setSaApiKeyDataLoader(SaApiKeyDataLoader apiKeyDataLoader) {
SaApiKeyManager.setSaApiKeyDataLoader(apiKeyDataLoader);
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* 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.
*/
package cn.dev33.satoken.solon.apikey;
import cn.dev33.satoken.apikey.SaApiKeyManager;
import cn.dev33.satoken.apikey.config.SaApiKeyConfig;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
/**
* 注册 Sa-Token API Key 所需要的 Bean
*
* @author click33
* @since 1.43.0
*/
@Configuration
@Condition(onClass= SaApiKeyManager.class)
public class SaApiKeyBeanRegister {
/**
* 获取 API Key 配置对象
* @return 配置对象
*/
@Bean
public SaApiKeyConfig getSaApiKeyConfig(@Inject(value = "${sa-token.api-key}", required = false) SaApiKeyConfig saApiKeyConfig) {
if (saApiKeyConfig == null) {
return new SaApiKeyConfig();
} else {
return saApiKeyConfig;
}
}
}
@@ -0,0 +1,69 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* 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.
*/
package cn.dev33.satoken.solon.sign;
import cn.dev33.satoken.sign.SaSignManager;
import cn.dev33.satoken.sign.config.SaSignConfig;
import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper;
import cn.dev33.satoken.sign.template.SaSignTemplate;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
/**
* 注入 Sa-Token API 参数签名 所需要的 Bean
*
* @author click33
* @since 1.43.0
*/
@Configuration
@Condition(onClass= SaSignManager.class)
public class SaSignBeanInject {
/**
* 注入 API 参数签名配置对象
*
* @param saSignConfig 配置对象
*/
@Bean
@Condition(onBean = SaSignConfig.class)
public void setSignConfig(SaSignConfig saSignConfig) {
SaSignManager.setConfig(saSignConfig);
}
/**
* 注入 API 参数签名配置对象
*
* @param signManyConfigWrapper 配置对象
*/
@Bean
@Condition(onBean = SaSignManyConfigWrapper.class)
public void setSignManyConfig(SaSignManyConfigWrapper signManyConfigWrapper) {
SaSignManager.setSignMany(signManyConfigWrapper.getSignMany());
}
/**
* 注入自定义的 参数签名 模版方法 Bean
*
* @param saSignTemplate 参数签名 Bean
*/
@Bean
@Condition(onBean = SaSignTemplate.class)
public void setSaSignTemplate(SaSignTemplate saSignTemplate) {
SaSignManager.setSaSignTemplate(saSignTemplate);
}
}
@@ -0,0 +1,62 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* 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.
*/
package cn.dev33.satoken.solon.sign;
import cn.dev33.satoken.sign.SaSignManager;
import cn.dev33.satoken.sign.config.SaSignConfig;
import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;
/**
* 注册 Sa-Token API 参数签名所需要的 Bean
*
* @author click33
* @since 1.43.0
*/
@Configuration
@Condition(onClass= SaSignManager.class)
public class SaSignBeanRegister {
/**
* 获取 API 参数签名配置对象
* @return 配置对象
*/
@Bean
public SaSignConfig getSaSignConfig(@Inject(value = "${sa-token.sign}", required = false) SaSignConfig saSignConfig) {
if (saSignConfig == null) {
return new SaSignConfig();
} else {
return saSignConfig;
}
}
/**
* 获取 API 参数签名 Many 配置对象
* @return 配置对象
*/
@Bean
public SaSignManyConfigWrapper getSaSignManyConfigWrapper(@Inject(value = "${sa-token}", required = false) SaSignManyConfigWrapper signManyConfigWrapper) {
if (signManyConfigWrapper == null) {
return new SaSignManyConfigWrapper();
} else {
return signManyConfigWrapper;
}
}
}
@@ -43,7 +43,7 @@ public class SaSsoBeanRegister {
* @return 配置对象
*/
@Bean
public SaSsoServerConfig getSaSsoServerConfig(@Inject(value = "${sa-token.sso-server)", required = false) SaSsoServerConfig serverConfig) {
public SaSsoServerConfig getSaSsoServerConfig(@Inject(value = "${sa-token.sso-server}", required = false) SaSsoServerConfig serverConfig) {
if (serverConfig == null) {
return new SaSsoServerConfig();
} else {
@@ -70,6 +70,13 @@
<optional>true</optional>
</dependency>
<!-- API Sign (optional) -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-sign</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
@@ -35,7 +35,6 @@ import cn.dev33.satoken.plugin.SaTokenPluginHolder;
import cn.dev33.satoken.same.SaSameTemplate;
import cn.dev33.satoken.secure.totp.SaTotpTemplate;
import cn.dev33.satoken.serializer.SaSerializerTemplate;
import cn.dev33.satoken.sign.SaSignTemplate;
import cn.dev33.satoken.spring.pathmatch.SaPathMatcherHolder;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpLogic;
@@ -207,16 +206,6 @@ public class SaBeanInject {
SaManager.setSaSerializerTemplate(saSerializerTemplate);
}
/**
* 注入自定义的 参数签名 Bean
*
* @param saSignTemplate 参数签名 Bean
*/
@Autowired(required = false)
public void setSaSignTemplate(SaSignTemplate saSignTemplate) {
SaManager.setSaSignTemplate(saSignTemplate);
}
/**
* 注入自定义的 TOTP 算法 Bean
*
@@ -37,7 +37,7 @@ public class SaApiKeyBeanInject {
* @param saApiKeyConfig 配置对象
*/
@Autowired(required = false)
public void setSaOAuth2Config(SaApiKeyConfig saApiKeyConfig) {
public void setSaApiKeyConfig(SaApiKeyConfig saApiKeyConfig) {
SaApiKeyManager.setConfig(saApiKeyConfig);
}
@@ -25,7 +25,7 @@ import org.springframework.context.annotation.Bean;
* 注册 Sa-Token API Key 所需要的 Bean
*
* @author click33
* @since 1.34.0
* @since 1.43.0
*/
@ConditionalOnClass(SaApiKeyManager.class)
public class SaApiKeyBeanRegister {
@@ -0,0 +1,64 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* 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.
*/
package cn.dev33.satoken.spring.sign;
import cn.dev33.satoken.sign.SaSignManager;
import cn.dev33.satoken.sign.config.SaSignConfig;
import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper;
import cn.dev33.satoken.sign.template.SaSignTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
/**
* 注入 Sa-Token API 参数签名 所需要的 Bean
*
* @author click33
* @since 1.43.0
*/
@ConditionalOnClass(SaSignManager.class)
public class SaSignBeanInject {
/**
* 注入 API 参数签名配置对象
*
* @param saSignConfig 配置对象
*/
@Autowired(required = false)
public void setSignConfig(SaSignConfig saSignConfig) {
SaSignManager.setConfig(saSignConfig);
}
/**
* 注入 API 参数签名配置对象
*
* @param signManyConfigWrapper 配置对象
*/
@Autowired(required = false)
public void setSignManyConfig(SaSignManyConfigWrapper signManyConfigWrapper) {
SaSignManager.setSignMany(signManyConfigWrapper.getSignMany());
}
/**
* 注入自定义的 参数签名 模版方法 Bean
*
* @param saSignTemplate 参数签名 Bean
*/
@Autowired(required = false)
public void setSaSignTemplate(SaSignTemplate saSignTemplate) {
SaSignManager.setSaSignTemplate(saSignTemplate);
}
}
@@ -0,0 +1,54 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* 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.
*/
package cn.dev33.satoken.spring.sign;
import cn.dev33.satoken.sign.SaSignManager;
import cn.dev33.satoken.sign.config.SaSignConfig;
import cn.dev33.satoken.sign.config.SaSignManyConfigWrapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
/**
* 注册 Sa-Token API 参数签名所需要的 Bean
*
* @author click33
* @since 1.43.0
*/
@ConditionalOnClass(SaSignManager.class)
public class SaSignBeanRegister {
/**
* 获取 API 参数签名配置对象
* @return 配置对象
*/
@Bean
@ConfigurationProperties(prefix = "sa-token.sign")
public SaSignConfig getSaSignConfig() {
return new SaSignConfig();
}
/**
* 获取 API 参数签名 Many 配置对象
* @return 配置对象
*/
@Bean
@ConfigurationProperties(prefix = "sa-token")
public SaSignManyConfigWrapper getSaSignManyConfigWrapper() {
return new SaSignManyConfigWrapper();
}
}
@@ -0,0 +1,19 @@
/*
* Copyright 2020-2099 sa-token.cc
*
* 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.
*/
/**
* sa-token-sign 模块自动化配置(只有引入了 sa-token-sign 模块后,此包下的代码才会开始工作)
*/
package cn.dev33.satoken.spring.sign;
@@ -4,4 +4,8 @@ cn.dev33.satoken.spring.SaBeanInject,\
cn.dev33.satoken.spring.sso.SaSsoBeanRegister,\
cn.dev33.satoken.spring.sso.SaSsoBeanInject,\
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanRegister,\
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanInject
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanInject,\
cn.dev33.satoken.spring.apikey.SaApiKeyBeanRegister,\
cn.dev33.satoken.spring.apikey.SaApiKeyBeanInject,\
cn.dev33.satoken.spring.sign.SaSignBeanRegister,\
cn.dev33.satoken.spring.sign.SaSignBeanInject
@@ -3,4 +3,8 @@ cn.dev33.satoken.spring.SaBeanInject
cn.dev33.satoken.spring.sso.SaSsoBeanRegister
cn.dev33.satoken.spring.sso.SaSsoBeanInject
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanRegister
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanInject
cn.dev33.satoken.spring.oauth2.SaOAuth2BeanInject
cn.dev33.satoken.spring.apikey.SaApiKeyBeanRegister
cn.dev33.satoken.spring.apikey.SaApiKeyBeanInject
cn.dev33.satoken.spring.sign.SaSignBeanRegister
cn.dev33.satoken.spring.sign.SaSignBeanInject