更新项目基础框架版本依赖与适配
This commit is contained in:
parent
79ddfb022b
commit
b812021e5b
2
pom.xml
2
pom.xml
|
|
@ -40,7 +40,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chinaweal.youfool</groupId>
|
<groupId>com.chinaweal.youfool</groupId>
|
||||||
<artifactId>youfool-framework-springboot</artifactId>
|
<artifactId>youfool-framework-springboot</artifactId>
|
||||||
<version>3.2.0-SNAPSHOT</version>
|
<version>3.3.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--postgresql-->
|
<!--postgresql-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.chinaweal.youfool.prj.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* session常量
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2022/7/19 11:02
|
||||||
|
**/
|
||||||
|
public interface SessionConstants {
|
||||||
|
|
||||||
|
String USER_KEY = "user";
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,114 @@
|
||||||
package com.chinaweal.youfool.prj.common.util;
|
package com.chinaweal.youfool.prj.common.util;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串工具类
|
* 字符串工具类
|
||||||
|
*
|
||||||
* @author lroyia
|
* @author lroyia
|
||||||
* @since 2022/4/20 15:04
|
* @since 2022/4/20 15:04
|
||||||
**/
|
**/
|
||||||
public abstract class StringUtils {
|
public abstract class StringUtils extends com.chinaweal.youfool.framework.springboot.common.util.StringUtils {
|
||||||
|
|
||||||
|
private static final char[] HEX_DIGITS_LOW = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
|
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||||
|
|
||||||
|
public static final char[] FILE_NAME_SPECIFY_CHARS = new char[]{'/', '\\', ':', '*', '"', '<', '>', '|'};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否全为非空
|
||||||
|
*
|
||||||
|
* @param str 判断字串(可选参数)
|
||||||
|
* @return 判断结果
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2023年5月26日 11:39:29
|
||||||
|
*/
|
||||||
|
public static boolean isNotBlankALl(String... str) {
|
||||||
|
for (String each : str) {
|
||||||
|
if (isBlank(each)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否全为空
|
||||||
|
*
|
||||||
|
* @param str 判断字串(可选参数)
|
||||||
|
* @return 判断结果
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2023年5月26日 11:35:29
|
||||||
|
*/
|
||||||
|
public static boolean isBlankAll(String... str) {
|
||||||
|
for (String each : str) {
|
||||||
|
if (isNotBlank(each)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 16进制字符串转byte数组
|
||||||
|
*
|
||||||
|
* @param hex 16进制字符串
|
||||||
|
* @return 转换结果
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2022年7月12日 15:13:13
|
||||||
|
*/
|
||||||
|
public static byte[] hexFromString(String hex) {
|
||||||
|
int len = hex.length();
|
||||||
|
byte[] buf = new byte[(len + 1) / 2];
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
if (len % 2 == 1)
|
||||||
|
buf[j++] = (byte) fromDigit(hex.charAt(i++));
|
||||||
|
while (i < len)
|
||||||
|
buf[j++] = (byte) (fromDigit(hex.charAt(i++)) << 4 | fromDigit(hex.charAt(i++)));
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [0-9][A-F][a-f]转整形
|
||||||
|
*
|
||||||
|
* @param ch 字符
|
||||||
|
* @return 转换结果
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2022年7月12日 15:11:59
|
||||||
|
*/
|
||||||
|
public static int fromDigit(char ch) {
|
||||||
|
if (ch >= '0' && ch <= '9')
|
||||||
|
return ch - 48;
|
||||||
|
if (ch >= 'A' && ch <= 'F')
|
||||||
|
return (ch - 65) + 10;
|
||||||
|
if (ch >= 'a' && ch <= 'f')
|
||||||
|
return (ch - 97) + 10;
|
||||||
|
else
|
||||||
|
throw new IllegalArgumentException("invalid hex digit '" + ch + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不是数字
|
||||||
|
*
|
||||||
|
* @param cs 字符
|
||||||
|
* @return 判断结果
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2022年8月22日 14:56:01
|
||||||
|
*/
|
||||||
|
public static boolean isNotNumeric(CharSequence cs) {
|
||||||
|
return !isNumeric(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个UUID
|
||||||
|
*
|
||||||
|
* @return UUID
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2022年9月15日 10:27:03
|
||||||
|
*/
|
||||||
|
public static String getUUID() {
|
||||||
|
return UUID.randomUUID().toString().replace("-", EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
package com.chinaweal.youfool.prj.config;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.context.model.SaRequest;
|
|
||||||
import cn.dev33.satoken.context.model.SaResponse;
|
|
||||||
import cn.dev33.satoken.router.SaRouteFunction;
|
|
||||||
import cn.dev33.satoken.router.SaRouter;
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SaToken权限与鉴权配置
|
|
||||||
* @author lroyia
|
|
||||||
* @since 2022/4/20 16:37
|
|
||||||
**/
|
|
||||||
public class SaTokenConfig implements SaRouteFunction {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(SaRequest request, SaResponse response, Object handler) {
|
|
||||||
// 根据路由划分模块,不同模块不同鉴权
|
|
||||||
// SaRouter.match("/user/**", r -> StpUtil.checkPermission("user"));
|
|
||||||
// SaRouter.match("/admin/**", r -> StpUtil.checkPermission("admin"));
|
|
||||||
// SaRouter.match("/goods/**", r -> StpUtil.checkPermission("goods"));
|
|
||||||
// SaRouter.match("/orders/**", r -> StpUtil.checkPermission("orders"));
|
|
||||||
// SaRouter.match("/notice/**", r -> StpUtil.checkPermission("notice"));
|
|
||||||
// SaRouter.match("/comment/**", r -> StpUtil.checkPermission("comment"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
package com.chinaweal.youfool.prj.config;
|
|
||||||
|
|
||||||
import com.chinaweal.youfool.framework.springboot.user.shiro.JWTRestfulFilter;
|
|
||||||
import com.chinaweal.youfool.framework.springboot.user.shiro.RestShiroFilterFactoryBean;
|
|
||||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
|
||||||
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
|
||||||
import org.apache.shiro.mgt.SecurityManager;
|
|
||||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
|
||||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
|
||||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
|
||||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
|
||||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* shiro配置
|
|
||||||
* 自youfool-framework3.2.0版本起,弃用shiro,改用sa-token作为权限支持,本类可删除
|
|
||||||
*/
|
|
||||||
//@Configuration
|
|
||||||
@Deprecated
|
|
||||||
public class ShiroConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ShiroFilterFactoryBean factory(SecurityManager securityManager) {
|
|
||||||
ShiroFilterFactoryBean factoryBean = new RestShiroFilterFactoryBean();
|
|
||||||
factoryBean.setSecurityManager(securityManager);
|
|
||||||
|
|
||||||
Map<String, Filter> filterMap = factoryBean.getFilters();
|
|
||||||
//注:restful如: /xxx==GET = jwtRestful[org:dept:list]这里的 getUrl,getMethod 和 getPerms 分别对应 /xxx,GET 和 org:dept:list。
|
|
||||||
filterMap.put("jwtRestful", new JWTRestfulFilter());
|
|
||||||
factoryBean.setFilters(filterMap);
|
|
||||||
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
|
|
||||||
filterChainDefinitionMap.put("/xxx==GET", "jwtRestful[org:dept:list]");
|
|
||||||
filterChainDefinitionMap.put("/**", "jwtRestful");
|
|
||||||
factoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
|
||||||
return factoryBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void loadShiro() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注入 securityManager
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public SecurityManager securityManager() {
|
|
||||||
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
|
|
||||||
//securityManager.setRealm(userRealm);
|
|
||||||
/*
|
|
||||||
* 关闭shiro自带的session,详情见文档
|
|
||||||
* http://shiro.apache.org/session-management.html#SessionManagement-StatelessApplications%28Sessionless%29
|
|
||||||
*/
|
|
||||||
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
|
||||||
DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
|
||||||
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
|
||||||
subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
|
|
||||||
securityManager.setSubjectDAO(subjectDAO);
|
|
||||||
return securityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加注解支持
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
|
|
||||||
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
|
||||||
// 强制使用cglib,防止重复代理和可能引起代理出错的问题
|
|
||||||
// https://zhuanlan.zhihu.com/p/29161098
|
|
||||||
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
|
|
||||||
return defaultAdvisorAutoProxyCreator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public static LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
|
|
||||||
return new LifecycleBeanPostProcessor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public AuthorizationAttributeSourceAdvisor authorizationAttribute() {
|
|
||||||
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
|
|
||||||
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager());
|
|
||||||
return authorizationAttributeSourceAdvisor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +1,45 @@
|
||||||
package com.chinaweal.youfool.prj.config;
|
package com.chinaweal.youfool.prj.config;
|
||||||
|
|
||||||
import cn.dev33.satoken.interceptor.SaRouteInterceptor;
|
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||||
|
import cn.dev33.satoken.router.SaRouter;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* spring mvc 配置
|
* spring mvc 配置
|
||||||
|
*
|
||||||
* @author lroyia
|
* @author lroyia
|
||||||
* @since 2022/2/8 18:04
|
* @since 2022/2/8 18:04
|
||||||
**/
|
**/
|
||||||
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SpringMvcConfig implements WebMvcConfigurer {
|
public class SpringMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拦截器注册
|
* 拦截器注册
|
||||||
|
*
|
||||||
* @param registry 注册对象
|
* @param registry 注册对象
|
||||||
* @author lroyia
|
* @author lroyia
|
||||||
* @since 2022年4月20日 16:41:54
|
* @since 2022年4月20日 16:41:54
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// SaToken路由拦截与鉴权
|
// 注册 Sa-Token 拦截器,定义详细认证规则
|
||||||
registry.addInterceptor(new SaRouteInterceptor(new SaTokenConfig()))
|
registry.addInterceptor(new SaInterceptor(handler -> {
|
||||||
.addPathPatterns("/**")
|
// // 根据路由划分模块,不同模块不同鉴权
|
||||||
.excludePathPatterns("/user/auth/**");
|
// SaRouter.match("/user/**", r -> StpUtil.checkPermission("user"));
|
||||||
|
// SaRouter.match("/admin/**", r -> StpUtil.checkPermission("admin"));
|
||||||
|
// SaRouter.match("/goods/**", r -> StpUtil.checkPermission("goods"));
|
||||||
|
// SaRouter.match("/orders/**", r -> StpUtil.checkPermission("orders"));
|
||||||
|
// SaRouter.match("/notice/**", r -> StpUtil.checkPermission("notice"));
|
||||||
|
// SaRouter.match("/comment/**", r -> StpUtil.checkPermission("comment"));
|
||||||
|
// 指定一条 match 规则
|
||||||
|
SaRouter.notMatch("/user/auth/**", "/test/**", "/doc.html**", "/cross/**", "/swagger*",
|
||||||
|
"/cms/index.html", "/cms/static/**", "/cms/favicon.ico", "/cms/user/login", "/network/ping", "/error", "/static/data/**")
|
||||||
|
.match("/**", r -> StpUtil.checkLogin());
|
||||||
|
})).addPathPatterns("/**");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
package com.chinaweal.youfool.prj.controller;
|
package com.chinaweal.youfool.prj.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.session.SaSession;
|
import cn.dev33.satoken.session.SaSession;
|
||||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.chinaweal.youfool.framework.springboot.common.base.BaseController;
|
import com.chinaweal.youfool.framework.springboot.common.base.BaseController;
|
||||||
import com.chinaweal.youfool.framework.springboot.common.util.AssertUtils;
|
import com.chinaweal.youfool.framework.springboot.common.util.AssertUtils;
|
||||||
import com.chinaweal.youfool.framework.springboot.common.util.RSAUtil;
|
import com.chinaweal.youfool.framework.springboot.common.util.RSAUtil;
|
||||||
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
||||||
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
|
import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
|
||||||
import com.chinaweal.youfool.framework.springboot.user.entity.LoginInfo;
|
|
||||||
import com.chinaweal.youfool.framework.springboot.user.entity.UserBase;
|
import com.chinaweal.youfool.framework.springboot.user.entity.UserBase;
|
||||||
|
import com.chinaweal.youfool.prj.common.constants.SessionConstants;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
@ -89,15 +88,13 @@ public class LoginController extends BaseController {
|
||||||
* @since 2022年4月20日 15:58:26
|
* @since 2022年4月20日 15:58:26
|
||||||
*/
|
*/
|
||||||
@GetMapping("login/info")
|
@GetMapping("login/info")
|
||||||
public RestResult<LoginInfo<UserBase>> loginInfo() {
|
public RestResult<UserBase> loginInfo() {
|
||||||
boolean login = StpUtil.isLogin();
|
boolean login = StpUtil.isLogin();
|
||||||
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
|
|
||||||
LoginInfo<UserBase> userInfo = new LoginInfo<>(login, null);
|
|
||||||
if (login) {
|
if (login) {
|
||||||
SaSession session = getSession();
|
SaSession session = getSession();
|
||||||
userInfo.setUserInfo((UserBase) session.get("user"));
|
return RestResult.ok((UserBase) session.get(SessionConstants.USER_KEY));
|
||||||
}
|
}
|
||||||
return RestResult.ok(userInfo);
|
return RestResult.ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,40 @@
|
||||||
package com.chinaweal.youfool.prj.service.impl;
|
package com.chinaweal.youfool.prj.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
|
import cn.dev33.satoken.session.SaSession;
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
|
||||||
|
import com.chinaweal.youfool.framework.springboot.user.entity.UserBase;
|
||||||
import com.chinaweal.youfool.framework.springboot.user.service.UserBaseService;
|
import com.chinaweal.youfool.framework.springboot.user.service.UserBaseService;
|
||||||
|
import com.chinaweal.youfool.prj.common.constants.SessionConstants;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户
|
* 用户
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserBaseServiceImpl implements UserBaseService {
|
public class UserBaseServiceImpl implements UserBaseService {
|
||||||
|
@Override
|
||||||
|
public RestResult<UserBase> login(String userName, String password, boolean frameworkLogin) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidToken(String token) {
|
public UserBase getCurrentUser() {
|
||||||
return false;
|
try {
|
||||||
|
SaSession session = StpUtil.getSession();
|
||||||
|
return session.get(SessionConstants.USER_KEY, null);
|
||||||
|
} catch (NotLoginException e) {
|
||||||
|
UserBase userBase = new UserBase();
|
||||||
|
userBase.setUsername("guest");
|
||||||
|
return userBase;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserBase> getUserInfoByLoginId(List<String> loginIdList) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue