refactor: 移动 SaToken 配置到 webapi 模块

This commit is contained in:
2024-07-01 22:08:02 +08:00
parent 44811fc932
commit d733b7f166
25 changed files with 29 additions and 29 deletions

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.continew.admin.config.satoken;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 密码配置属性
*
* @author Charles7c
* @since 2024/6/15 22:15
*/
@Data
@Component
@ConfigurationProperties(prefix = "auth.password")
public class LoginPasswordProperties {
/**
* 排除(放行)路径配置
*/
private String[] excludes = new String[0];
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.continew.admin.config.satoken;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.continew.admin.common.model.dto.LoginUser;
import top.continew.admin.common.util.helper.LoginHelper;
import top.continew.starter.auth.satoken.autoconfigure.SaTokenExtensionProperties;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.validate.CheckUtils;
/**
* Sa-Token 配置
*
* @author Charles7c
* @since 2022/12/19 22:13
*/
@Configuration
@RequiredArgsConstructor
public class SaTokenConfiguration {
private final SaTokenExtensionProperties properties;
private final LoginPasswordProperties loginPasswordProperties;
/**
* Sa-Token 权限认证配置
*/
@Bean
public StpInterface stpInterface() {
return new SaTokenPermissionImpl();
}
/**
* SaToken 拦截器配置
*/
@Bean
public SaInterceptor saInterceptor() {
return new SaInterceptor(handle -> SaRouter.match(StringConstants.PATH_PATTERN)
.notMatch(properties.getSecurity().getExcludes())
.check(r -> {
LoginUser loginUser = LoginHelper.getLoginUser();
if (SaRouter.isMatchCurrURI(loginPasswordProperties.getExcludes())) {
return;
}
CheckUtils.throwIf(loginUser.isPasswordExpired(), "密码已过期,请修改密码");
}));
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* 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 top.continew.admin.config.satoken;
import cn.dev33.satoken.stp.StpInterface;
import top.continew.admin.common.model.dto.LoginUser;
import top.continew.admin.common.util.helper.LoginHelper;
import java.util.ArrayList;
import java.util.List;
/**
* Sa-Token 权限认证实现
*
* @author Charles7c
* @since 2023/3/1 22:28
*/
public class SaTokenPermissionImpl implements StpInterface {
@Override
public List<String> getPermissionList(Object loginId, String loginType) {
LoginUser loginUser = LoginHelper.getLoginUser();
return new ArrayList<>(loginUser.getPermissions());
}
@Override
public List<String> getRoleList(Object loginId, String loginType) {
LoginUser loginUser = LoginHelper.getLoginUser();
return new ArrayList<>(loginUser.getRoleCodes());
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.auth;
package top.continew.admin.controller.auth;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.auth;
package top.continew.admin.controller.auth;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.common;
package top.continew.admin.controller.common;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.date.LocalDateTimeUtil;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.common;
package top.continew.admin.controller.common;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.tree.Tree;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.common;
package top.continew.admin.controller.common;
import com.alicp.jetcache.anno.CachePenetrationProtect;
import com.alicp.jetcache.anno.CacheRefresh;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.monitor;
package top.continew.admin.controller.monitor;
import lombok.RequiredArgsConstructor;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RestController;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RestController;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RestController;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import io.swagger.v3.oas.annotations.tags.Tag;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RestController;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import com.xkcoding.justauth.AuthRequestFactory;
import io.swagger.v3.oas.annotations.Operation;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.system;
package top.continew.admin.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.ReUtil;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.webapi.tool;
package top.continew.admin.controller.tool;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;

View File

@@ -61,16 +61,16 @@ springdoc:
- /error
- group: auth
display-name: 系统认证
packages-to-scan: ${project.base-package}.webapi.auth
packages-to-scan: ${project.base-package}.controller.auth
- group: common
display-name: 通用接口
packages-to-scan: ${project.base-package}.webapi.common
packages-to-scan: ${project.base-package}.controller.common
- group: system
display-name: 系统管理
packages-to-scan: ${project.base-package}.webapi.system
packages-to-scan: ${project.base-package}.controller.system
- group: monitor
display-name: 系统监控
packages-to-scan: ${project.base-package}.webapi.monitor
packages-to-scan: ${project.base-package}.controller.monitor
## 组件配置
components:
# 鉴权配置