mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-08 16:57:09 +08:00
refactor(auth/satoken): 权限认证配置支持启用、关闭
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import top.charles7c.continew.starter.auth.satoken.autoconfigure.dao.SaTokenDaoConfiguration;
|
||||
import top.charles7c.continew.starter.core.constant.PropertiesConstants;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
import top.charles7c.continew.starter.core.util.GeneralPropertySourceFactory;
|
||||
@@ -66,12 +67,13 @@ public class SaTokenAutoConfiguration implements WebMvcConfigurer {
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限认证实现类
|
||||
* 自定义权限认证配置
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnProperty(prefix = "sa-token.extension.permission", name = PropertiesConstants.ENABLED, havingValue = "true")
|
||||
public StpInterface stpInterface() {
|
||||
return ReflectUtil.newInstance(properties.getPermissionImpl());
|
||||
return ReflectUtil.newInstance(properties.getPermission().getImpl());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -16,11 +16,9 @@
|
||||
|
||||
package top.charles7c.continew.starter.auth.satoken.autoconfigure;
|
||||
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import top.charles7c.continew.starter.auth.satoken.properties.SaTokenDaoProperties;
|
||||
import top.charles7c.continew.starter.auth.satoken.properties.SaTokenSecurityProperties;
|
||||
import top.charles7c.continew.starter.auth.satoken.autoconfigure.dao.SaTokenDaoProperties;
|
||||
|
||||
/**
|
||||
* SaToken 扩展配置属性
|
||||
@@ -36,17 +34,18 @@ public class SaTokenExtensionProperties {
|
||||
*/
|
||||
private boolean enabled = false;
|
||||
|
||||
/**
|
||||
* 权限认证实现
|
||||
*/
|
||||
private Class<? extends StpInterface> permissionImpl;
|
||||
|
||||
/**
|
||||
* 持久层配置
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private SaTokenDaoProperties dao;
|
||||
|
||||
/**
|
||||
* 权限认证配置
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private SaTokenPermissionProperties permission;
|
||||
|
||||
/**
|
||||
* 安全配置
|
||||
*/
|
||||
@@ -61,14 +60,6 @@ public class SaTokenExtensionProperties {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Class<? extends StpInterface> getPermissionImpl() {
|
||||
return permissionImpl;
|
||||
}
|
||||
|
||||
public void setPermissionImpl(Class<? extends StpInterface> permissionImpl) {
|
||||
this.permissionImpl = permissionImpl;
|
||||
}
|
||||
|
||||
public SaTokenDaoProperties getDao() {
|
||||
return dao;
|
||||
}
|
||||
@@ -77,6 +68,14 @@ public class SaTokenExtensionProperties {
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public SaTokenPermissionProperties getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setPermission(SaTokenPermissionProperties permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public SaTokenSecurityProperties getSecurity() {
|
||||
return security;
|
||||
}
|
||||
@@ -87,6 +86,6 @@ public class SaTokenExtensionProperties {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SaTokenExtensionProperties{" + "enabled=" + enabled + ", permissionImpl=" + permissionImpl + ", dao=" + dao + ", security=" + security + '}';
|
||||
return "SaTokenExtensionProperties{" + "enabled=" + enabled + ", dao=" + dao + ", permission=" + permission + ", security=" + security + '}';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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.stp.StpInterface;
|
||||
|
||||
/**
|
||||
* SaToken 权限认证配置属性
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class SaTokenPermissionProperties {
|
||||
|
||||
/**
|
||||
* 是否启用权限认证
|
||||
*/
|
||||
private boolean enabled = false;
|
||||
|
||||
/**
|
||||
* 自定义权限认证实现类(当 enabled 为 true 时必填)
|
||||
*/
|
||||
private Class<? extends StpInterface> impl;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Class<? extends StpInterface> getImpl() {
|
||||
return impl;
|
||||
}
|
||||
|
||||
public void setImpl(Class<? extends StpInterface> impl) {
|
||||
this.impl = impl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SaTokenPermissionProperties{" + "enabled=" + enabled + ", impl=" + impl + '}';
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.starter.auth.satoken.properties;
|
||||
package top.charles7c.continew.starter.auth.satoken.autoconfigure;
|
||||
|
||||
/**
|
||||
* SaToken 安全配置属性
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.starter.auth.satoken.autoconfigure;
|
||||
package top.charles7c.continew.starter.auth.satoken.autoconfigure.dao;
|
||||
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
@@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import top.charles7c.continew.starter.auth.satoken.autoconfigure.SaTokenExtensionProperties;
|
||||
import top.charles7c.continew.starter.auth.satoken.core.SaTokenDaoRedisImpl;
|
||||
import top.charles7c.continew.starter.cache.redisson.autoconfigure.RedissonAutoConfiguration;
|
||||
|
||||
@@ -35,7 +36,7 @@ import top.charles7c.continew.starter.cache.redisson.autoconfigure.RedissonAutoC
|
||||
* @author Charles7c
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class SaTokenDaoConfiguration {
|
||||
public class SaTokenDaoConfiguration {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SaTokenDaoConfiguration.class);
|
||||
|
||||
@@ -49,7 +50,7 @@ abstract class SaTokenDaoConfiguration {
|
||||
@ConditionalOnMissingBean(SaTokenDao.class)
|
||||
@AutoConfigureBefore(RedissonAutoConfiguration.class)
|
||||
@ConditionalOnProperty(name = "sa-token.extension.dao.type", havingValue = "redis")
|
||||
static class Redis {
|
||||
public static class Redis {
|
||||
static {
|
||||
log.debug("[ContiNew Starter] - Auto Configuration 'SaToken-SaTokenDao-Redis' completed initialization.");
|
||||
}
|
||||
@@ -63,8 +64,9 @@ abstract class SaTokenDaoConfiguration {
|
||||
/**
|
||||
* 自定义持久层实现类-自定义
|
||||
*/
|
||||
@ConditionalOnMissingBean(SaTokenDao.class)
|
||||
@ConditionalOnProperty(name = "sa-token.extension.dao.type", havingValue = "custom")
|
||||
static class Custom {
|
||||
public static class Custom {
|
||||
static {
|
||||
log.debug("[ContiNew Starter] - Auto Configuration 'SaToken-SaTokenDao-Custom' completed initialization.");
|
||||
}
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.starter.auth.satoken.properties;
|
||||
package top.charles7c.continew.starter.auth.satoken.autoconfigure.dao;
|
||||
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import top.charles7c.continew.starter.auth.satoken.enums.SaTokenDaoType;
|
Reference in New Issue
Block a user