mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 08:57:17 +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.context.annotation.*;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
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.PropertiesConstants;
|
||||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||||
import top.charles7c.continew.starter.core.util.GeneralPropertySourceFactory;
|
import top.charles7c.continew.starter.core.util.GeneralPropertySourceFactory;
|
||||||
@@ -66,12 +67,13 @@ public class SaTokenAutoConfiguration implements WebMvcConfigurer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限认证实现类
|
* 自定义权限认证配置
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty(prefix = "sa-token.extension.permission", name = PropertiesConstants.ENABLED, havingValue = "true")
|
||||||
public StpInterface stpInterface() {
|
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;
|
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.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||||
import top.charles7c.continew.starter.auth.satoken.properties.SaTokenDaoProperties;
|
import top.charles7c.continew.starter.auth.satoken.autoconfigure.dao.SaTokenDaoProperties;
|
||||||
import top.charles7c.continew.starter.auth.satoken.properties.SaTokenSecurityProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SaToken 扩展配置属性
|
* SaToken 扩展配置属性
|
||||||
@@ -36,17 +34,18 @@ public class SaTokenExtensionProperties {
|
|||||||
*/
|
*/
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限认证实现
|
|
||||||
*/
|
|
||||||
private Class<? extends StpInterface> permissionImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 持久层配置
|
* 持久层配置
|
||||||
*/
|
*/
|
||||||
@NestedConfigurationProperty
|
@NestedConfigurationProperty
|
||||||
private SaTokenDaoProperties dao;
|
private SaTokenDaoProperties dao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限认证配置
|
||||||
|
*/
|
||||||
|
@NestedConfigurationProperty
|
||||||
|
private SaTokenPermissionProperties permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安全配置
|
* 安全配置
|
||||||
*/
|
*/
|
||||||
@@ -61,14 +60,6 @@ public class SaTokenExtensionProperties {
|
|||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<? extends StpInterface> getPermissionImpl() {
|
|
||||||
return permissionImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermissionImpl(Class<? extends StpInterface> permissionImpl) {
|
|
||||||
this.permissionImpl = permissionImpl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SaTokenDaoProperties getDao() {
|
public SaTokenDaoProperties getDao() {
|
||||||
return dao;
|
return dao;
|
||||||
}
|
}
|
||||||
@@ -77,6 +68,14 @@ public class SaTokenExtensionProperties {
|
|||||||
this.dao = dao;
|
this.dao = dao;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SaTokenPermissionProperties getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermission(SaTokenPermissionProperties permission) {
|
||||||
|
this.permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
public SaTokenSecurityProperties getSecurity() {
|
public SaTokenSecurityProperties getSecurity() {
|
||||||
return security;
|
return security;
|
||||||
}
|
}
|
||||||
@@ -87,6 +86,6 @@ public class SaTokenExtensionProperties {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package top.charles7c.continew.starter.auth.satoken.properties;
|
package top.charles7c.continew.starter.auth.satoken.autoconfigure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SaToken 安全配置属性
|
* SaToken 安全配置属性
|
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* 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.dev33.satoken.dao.SaTokenDao;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
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.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
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.auth.satoken.core.SaTokenDaoRedisImpl;
|
||||||
import top.charles7c.continew.starter.cache.redisson.autoconfigure.RedissonAutoConfiguration;
|
import top.charles7c.continew.starter.cache.redisson.autoconfigure.RedissonAutoConfiguration;
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ import top.charles7c.continew.starter.cache.redisson.autoconfigure.RedissonAutoC
|
|||||||
* @author Charles7c
|
* @author Charles7c
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
abstract class SaTokenDaoConfiguration {
|
public class SaTokenDaoConfiguration {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(SaTokenDaoConfiguration.class);
|
private static final Logger log = LoggerFactory.getLogger(SaTokenDaoConfiguration.class);
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ abstract class SaTokenDaoConfiguration {
|
|||||||
@ConditionalOnMissingBean(SaTokenDao.class)
|
@ConditionalOnMissingBean(SaTokenDao.class)
|
||||||
@AutoConfigureBefore(RedissonAutoConfiguration.class)
|
@AutoConfigureBefore(RedissonAutoConfiguration.class)
|
||||||
@ConditionalOnProperty(name = "sa-token.extension.dao.type", havingValue = "redis")
|
@ConditionalOnProperty(name = "sa-token.extension.dao.type", havingValue = "redis")
|
||||||
static class Redis {
|
public static class Redis {
|
||||||
static {
|
static {
|
||||||
log.debug("[ContiNew Starter] - Auto Configuration 'SaToken-SaTokenDao-Redis' completed initialization.");
|
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")
|
@ConditionalOnProperty(name = "sa-token.extension.dao.type", havingValue = "custom")
|
||||||
static class Custom {
|
public static class Custom {
|
||||||
static {
|
static {
|
||||||
log.debug("[ContiNew Starter] - Auto Configuration 'SaToken-SaTokenDao-Custom' completed initialization.");
|
log.debug("[ContiNew Starter] - Auto Configuration 'SaToken-SaTokenDao-Custom' completed initialization.");
|
||||||
}
|
}
|
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* 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 cn.dev33.satoken.dao.SaTokenDao;
|
||||||
import top.charles7c.continew.starter.auth.satoken.enums.SaTokenDaoType;
|
import top.charles7c.continew.starter.auth.satoken.enums.SaTokenDaoType;
|
Reference in New Issue
Block a user