diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/AutoPoiDictConfig.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/AutoPoiDictConfig.java index 52608ae0..d5e6c164 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/AutoPoiDictConfig.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/AutoPoiDictConfig.java @@ -17,9 +17,9 @@ import java.util.List; * 举例: @Excel(name = "性别", width = 15, dicCode = "sex") * 1、导出的时候会根据字典配置,把值1,2翻译成:男、女; * 2、导入的时候,会把男、女翻译成1,2存进数据库; - * - * @Author:scott - * @since:2019-04-09 + * + * @Author:scott + * @since:2019-04-09 * @Version:1.0 */ @Slf4j @@ -31,14 +31,14 @@ public class AutoPoiDictConfig implements AutoPoiDictServiceI { /** * 通过字典查询easypoi,所需字典文本 - * - * @Author:scott + * + * @Author:scott * @since:2019-04-09 * @return */ @Override public String[] queryDict(String dicTable, String dicCode, String dicText) { - List dictReplaces = new ArrayList(); + List dictReplaces = new ArrayList<>(); List dictList = null; // step.1 如果没有字典表则使用系统字典表 if (oConvertUtils.isEmpty(dicTable)) { @@ -56,10 +56,10 @@ public class AutoPoiDictConfig implements AutoPoiDictServiceI { dictReplaces.add(t.getText() + "_" + t.getValue()); } } - if (dictReplaces != null && dictReplaces.size() != 0) { + if (!dictReplaces.isEmpty()) { log.info("---AutoPoi--Get_DB_Dict------"+ dictReplaces.toString()); return dictReplaces.toArray(new String[dictReplaces.size()]); } - return null; + return new String[0]; } } diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CorsFilterCondition.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CorsFilterCondition.java index dd3a858f..7e534777 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CorsFilterCondition.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CorsFilterCondition.java @@ -14,9 +14,6 @@ public class CorsFilterCondition implements Condition { public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Object object = context.getEnvironment().getProperty(CommonConstant.CLOUD_SERVER_KEY); //如果没有服务注册发现的配置 说明是单体应用 则加载跨域配置 返回true - if(object==null){ - return true; - } - return false; + return object == null; } } diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CsrfFilter.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CsrfFilter.java index 2ce5432a..1a7de7fd 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CsrfFilter.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/CsrfFilter.java @@ -7,15 +7,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import org.springframework.util.ResourceUtils; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.*; +import java.io.PrintWriter; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.List; @@ -28,6 +25,8 @@ import java.util.List; @Component public class CsrfFilter implements Filter { + + private static final String UNKNOWN_CONSTANT = "unknown"; /** * LOGGER */ @@ -106,13 +105,13 @@ public class CsrfFilter implements Filter { */ public String getIp(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN_CONSTANT.equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN_CONSTANT.equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN_CONSTANT.equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } if (ip.equals("0:0:0:0:0:0:0:1")) { @@ -122,6 +121,6 @@ public class CsrfFilter implements Filter { } @Override public void destroy() { - + // do other } } diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/DruidConfig.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/DruidConfig.java index 1cba97d1..39f1d1f4 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/DruidConfig.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/DruidConfig.java @@ -47,7 +47,7 @@ public class DruidConfig { DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); // 提取common.js的配置路径 String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; - String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); + String commonJsPattern = pattern.replace("\\*", "js/common.js"); // 获取common.js String text = Utils.readFromResource(FILE_PATH); // 屏蔽 this.buildFooter(); 不构建广告 diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/JeroCloudCondition.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/JeroCloudCondition.java index ff33e8c0..a8e8f65c 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/JeroCloudCondition.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/JeroCloudCondition.java @@ -14,9 +14,6 @@ public class JeroCloudCondition implements Condition { public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Object object = context.getEnvironment().getProperty(CommonConstant.CLOUD_SERVER_KEY); //如果没有服务注册发现的配置 说明是单体应用 - if(object==null){ - return false; - } - return true; + return object != null; } } diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/Swagger2Config.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/Swagger2Config.java index 36bce302..c1975069 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/Swagger2Config.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/Swagger2Config.java @@ -2,13 +2,10 @@ package com.jero.config; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; -import io.swagger.annotations.ApiOperation; -import lombok.extern.slf4j.Slf4j; import com.jero.common.constant.CommonConstant; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import io.swagger.annotations.ApiOperation; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - import org.springframework.context.annotation.Import; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/WebMvcConfiguration.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/WebMvcConfiguration.java index eb773da6..8c1ad619 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/WebMvcConfiguration.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/WebMvcConfiguration.java @@ -1,18 +1,13 @@ package com.jero.config; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisInterceptor.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisInterceptor.java index 8af57233..c8d2a645 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisInterceptor.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisInterceptor.java @@ -10,6 +10,7 @@ import org.apache.shiro.SecurityUtils; import com.jero.common.system.vo.LoginUser; import com.jero.common.util.oConvertUtils; import org.springframework.stereotype.Component; +import org.springframework.util.ReflectionUtils; import java.lang.reflect.Field; import java.util.Date; @@ -44,51 +45,42 @@ public class MybatisInterceptor implements Interceptor { for (Field field : fields) { log.debug("------field.name------" + field.getName()); try { - if ("createBy".equals(field.getName())) { - field.setAccessible(true); - Object local_createBy = field.get(parameter); - field.setAccessible(false); - if (local_createBy == null || local_createBy.equals("")) { - if (sysUser != null) { - // 登录人账号 - field.setAccessible(true); - field.set(parameter, sysUser.getUsername()); - field.setAccessible(false); - } + if ("createBy".equals(field.getName()) && sysUser != null) { + ReflectionUtils.makeAccessible(field); + Object localCreateBy = ReflectionUtils.getField(field,parameter); + if (localCreateBy == null || "".equals(localCreateBy)) { + // 登录人账号 + ReflectionUtils.makeAccessible(field); + ReflectionUtils.setField(field,parameter,sysUser.getUsername()); } } // 注入创建时间 if ("createTime".equals(field.getName())) { - field.setAccessible(true); - Object local_createDate = field.get(parameter); - field.setAccessible(false); - if (local_createDate == null || local_createDate.equals("")) { - field.setAccessible(true); - field.set(parameter, new Date()); - field.setAccessible(false); + ReflectionUtils.makeAccessible(field); + Object localCreateDate = ReflectionUtils.getField(field,parameter); + if (localCreateDate == null || "".equals(localCreateDate)) { + ReflectionUtils.makeAccessible(field); + ReflectionUtils.setField(field,parameter,new Date()); } } //注入部门编码 - if ("sysOrgCode".equals(field.getName())) { - field.setAccessible(true); - Object local_sysOrgCode = field.get(parameter); - field.setAccessible(false); - if (local_sysOrgCode == null || local_sysOrgCode.equals("")) { + if ("sysOrgCode".equals(field.getName()) && sysUser != null) { + ReflectionUtils.makeAccessible(field); + Object localSysOrgCode = ReflectionUtils.getField(field,parameter); + if (localSysOrgCode == null || "".equals(localSysOrgCode)) { // 获取登录用户信息 - if (sysUser != null) { - field.setAccessible(true); - field.set(parameter, sysUser.getOrgCode()); - field.setAccessible(false); - } + ReflectionUtils.makeAccessible(field); + ReflectionUtils.setField(field,parameter,sysUser.getOrgCode()); } } } catch (Exception e) { + log.error("异常", e); } } } if (SqlCommandType.UPDATE == sqlCommandType) { LoginUser sysUser = this.getLoginUser(); - Field[] fields = null; + Field[] fields; if (parameter instanceof ParamMap) { ParamMap p = (ParamMap) parameter; //update-begin-author:scott date:20190729 for:批量更新报错issues/IZA3Q-- @@ -113,22 +105,18 @@ public class MybatisInterceptor implements Interceptor { for (Field field : fields) { log.debug("------field.name------" + field.getName()); try { - if ("updateBy".equals(field.getName())) { + if ("updateBy".equals(field.getName()) && sysUser != null) { //获取登录用户信息 - if (sysUser != null) { - // 登录账号 - field.setAccessible(true); - field.set(parameter, sysUser.getUsername()); - field.setAccessible(false); - } + // 登录账号 + ReflectionUtils.makeAccessible(field); + ReflectionUtils.setField(field,parameter,sysUser.getUsername()); } if ("updateTime".equals(field.getName())) { - field.setAccessible(true); - field.set(parameter, new Date()); - field.setAccessible(false); + ReflectionUtils.makeAccessible(field); + ReflectionUtils.setField(field,parameter,new Date()); } } catch (Exception e) { - e.printStackTrace(); + log.error("异常", e); } } } @@ -151,7 +139,6 @@ public class MybatisInterceptor implements Interceptor { try { sysUser = SecurityUtils.getSubject().getPrincipal() != null ? (LoginUser) SecurityUtils.getSubject().getPrincipal() : null; } catch (Exception e) { - //e.printStackTrace(); sysUser = null; } return sysUser; diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisPlusSaasConfig.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisPlusSaasConfig.java index 6c40e990..03702794 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisPlusSaasConfig.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/MybatisPlusSaasConfig.java @@ -29,7 +29,7 @@ public class MybatisPlusSaasConfig { /** * 哪些表需要做多租户 表需要添加一个字段 tenant_id */ - private static final List tenantTable = new ArrayList(); + private static final List tenantTable = new ArrayList<>(); static { tenantTable.add("demo"); @@ -43,8 +43,8 @@ public class MybatisPlusSaasConfig { interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() { @Override public Expression getTenantId() { - String tenant_id = oConvertUtils.getString(TenantContext.getTenant(),"0"); - return new LongValue(tenant_id); + String tenantId = oConvertUtils.getString(TenantContext.getTenant(),"0"); + return new LongValue(tenantId); } @Override diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/TenantContext.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/TenantContext.java index 035e6937..8e092e7d 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/TenantContext.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/mybatis/TenantContext.java @@ -8,6 +8,10 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class TenantContext { + private TenantContext(){ + + } + private static ThreadLocal currentTenant = new ThreadLocal<>(); public static void setTenant(String tenant) { @@ -22,4 +26,4 @@ public class TenantContext { public static void clear(){ currentTenant.remove(); } -} \ No newline at end of file +} diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroConfig.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroConfig.java index 7eb43394..80e3dff8 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroConfig.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroConfig.java @@ -1,5 +1,9 @@ package com.jero.config.shiro; +import com.jero.common.constant.CommonConstant; +import com.jero.common.util.oConvertUtils; +import com.jero.config.shiro.filters.CustomShiroFilterFactoryBean; +import com.jero.config.shiro.filters.JwtFilter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.apache.shiro.mgt.DefaultSessionStorageEvaluator; @@ -13,17 +17,13 @@ import org.crazycake.shiro.IRedisManager; import org.crazycake.shiro.RedisCacheManager; import org.crazycake.shiro.RedisClusterManager; import org.crazycake.shiro.RedisManager; -import com.jero.common.constant.CommonConstant; -import com.jero.common.util.oConvertUtils; -import com.jero.config.shiro.filters.CustomShiroFilterFactoryBean; -import com.jero.config.shiro.filters.JwtFilter; import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; import org.springframework.core.env.Environment; +import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.util.StringUtils; import redis.clients.jedis.HostAndPort; @@ -47,7 +47,7 @@ public class ShiroConfig { private String excludeUrls; @Resource LettuceConnectionFactory lettuceConnectionFactory; - @Autowired + @Resource private Environment env; @@ -63,7 +63,7 @@ public class ShiroConfig { CustomShiroFilterFactoryBean shiroFilterFactoryBean = new CustomShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); // 拦截器 - Map filterChainDefinitionMap = new LinkedHashMap(); + Map filterChainDefinitionMap = new LinkedHashMap<>(); if(oConvertUtils.isNotEmpty(excludeUrls)){ String[] permissionUrl = excludeUrls.split(","); for(String url : permissionUrl){ @@ -134,7 +134,7 @@ public class ShiroConfig { filterChainDefinitionMap.put("/actuator/**", "anon"); // 添加自己的过滤器并且取名为jwt - Map filterMap = new HashMap(1); + Map filterMap = new HashMap<>(1); //如果cloudServer为空 则说明是单体 需要加载跨域配置【微服务跨域切换】 Object cloudServer = env.getProperty(CommonConstant.CLOUD_SERVER_KEY); filterMap.put("jwt", new JwtFilter(cloudServer==null)); @@ -227,7 +227,8 @@ public class ShiroConfig { log.info("===============(2)创建RedisManager,连接Redis.."); IRedisManager manager; // redis 单机支持,在集群为空,或者集群无机器时候使用 add by jzyadmin@163.com - if (lettuceConnectionFactory.getClusterConfiguration() == null || lettuceConnectionFactory.getClusterConfiguration().getClusterNodes().isEmpty()) { + RedisClusterConfiguration redisClusterConfiguration = lettuceConnectionFactory.getClusterConfiguration(); + if (lettuceConnectionFactory.getClusterConfiguration() == null || (!Objects.isNull(redisClusterConfiguration) && redisClusterConfiguration.getClusterNodes().isEmpty())) { RedisManager redisManager = new RedisManager(); redisManager.setHost(lettuceConnectionFactory.getHostName()); redisManager.setPort(lettuceConnectionFactory.getPort()); @@ -241,11 +242,13 @@ public class ShiroConfig { // redis集群支持,优先使用集群配置 RedisClusterManager redisManager = new RedisClusterManager(); Set portSet = new HashSet<>(); - lettuceConnectionFactory.getClusterConfiguration().getClusterNodes().forEach(node -> portSet.add(new HostAndPort(node.getHost() , node.getPort()))); + if(!Objects.isNull(redisClusterConfiguration)){ + redisClusterConfiguration.getClusterNodes().forEach(node -> portSet.add(new HostAndPort(node.getHost() , node.getPort()))); + } //update-begin--Author:scott Date:20210531 for:修改集群模式下未设置redis密码的bug issues/I3QNIC if (oConvertUtils.isNotEmpty(lettuceConnectionFactory.getPassword())) { JedisCluster jedisCluster = new JedisCluster(portSet, 2000, 2000, 5, - lettuceConnectionFactory.getPassword(), new GenericObjectPoolConfig()); + lettuceConnectionFactory.getPassword(), new GenericObjectPoolConfig<>()); redisManager.setPassword(lettuceConnectionFactory.getPassword()); redisManager.setJedisCluster(jedisCluster); } else { diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroRealm.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroRealm.java index ce003abc..3c75aba4 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroRealm.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/ShiroRealm.java @@ -69,13 +69,11 @@ public class ShiroRealm extends AuthorizingRealm { // 设置用户拥有的角色集合,比如“admin,test” Set roleSet = commonAPI.queryUserRoles(username); - System.out.println(roleSet.toString()); info.setRoles(roleSet); // 设置用户拥有的权限集合,比如“sys:role:add,sys:user:add” Set permissionSet = commonAPI.queryUserAuths(username); info.addStringPermissions(permissionSet); - System.out.println(permissionSet); log.info("===============Shiro权限认证成功=============="); return info; } @@ -131,10 +129,8 @@ public class ShiroRealm extends AuthorizingRealm { String userTenantIds = loginUser.getRelTenantIds(); if(oConvertUtils.isNotEmpty(userTenantIds)){ String contextTenantId = TenantContext.getTenant(); - if(oConvertUtils.isNotEmpty(contextTenantId) && !"0".equals(contextTenantId)){ - if(String.join(",",userTenantIds).indexOf(contextTenantId)<0){ - throw new AuthenticationException("用户租户信息变更,请重新登陆!"); - } + if(oConvertUtils.isNotEmpty(contextTenantId) && !"0".equals(contextTenantId) && !String.join(",", userTenantIds).contains(contextTenantId)){ + throw new AuthenticationException("用户租户信息变更,请重新登陆!"); } } //update-end-author:taoyan date:20210609 for:校验用户的tenant_id和前端传过来的是否一致 diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/filters/JwtFilter.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/filters/JwtFilter.java index a1780b8d..24e98140 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/filters/JwtFilter.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/shiro/filters/JwtFilter.java @@ -94,8 +94,8 @@ public class JwtFilter extends BasicHttpAuthenticationFilter { return false; } //update-begin-author:taoyan date:20200708 for:多租户用到 - String tenant_id = httpServletRequest.getHeader(CommonConstant.TENANT_ID); - TenantContext.setTenant(tenant_id); + String tenantId = httpServletRequest.getHeader(CommonConstant.TENANT_ID); + TenantContext.setTenant(tenantId); //update-end-author:taoyan date:20200708 for:多租户用到 return super.preHandle(request, response); } diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/interceptor/SignAuthInterceptor.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/interceptor/SignAuthInterceptor.java index 7ee3d932..c0c68ce0 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/interceptor/SignAuthInterceptor.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/interceptor/SignAuthInterceptor.java @@ -27,7 +27,7 @@ public class SignAuthInterceptor implements HandlerInterceptor { /** * 5分钟有效期 */ - private final static long MAX_EXPIRE = 5 * 60; + private static final long MAX_EXPIRE = 5 * 60L; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/BodyReaderHttpServletRequestWrapper.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/BodyReaderHttpServletRequestWrapper.java index cdec2033..9613ebc9 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/BodyReaderHttpServletRequestWrapper.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/BodyReaderHttpServletRequestWrapper.java @@ -6,7 +6,7 @@ import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; import java.io.*; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * 保存过滤器里面的流 @@ -22,7 +22,7 @@ public class BodyReaderHttpServletRequestWrapper extends HttpServletRequestWrapp super(request); String sessionStream = getBodyString(request); - body = sessionStream.getBytes(Charset.forName("UTF-8")); + body = sessionStream.getBytes(StandardCharsets.UTF_8); } /** @@ -35,7 +35,7 @@ public class BodyReaderHttpServletRequestWrapper extends HttpServletRequestWrapp StringBuilder sb = new StringBuilder(); try (InputStream inputStream = cloneInputStream(request.getInputStream()); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")))) { + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { sb.append(line); diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/HttpUtils.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/HttpUtils.java index 4daed574..6daabd25 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/HttpUtils.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/HttpUtils.java @@ -1,8 +1,8 @@ package com.jero.config.sign.util; -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; +import com.alibaba.fastjson.JSON; import com.jero.common.util.oConvertUtils; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpMethod; import javax.servlet.http.HttpServletRequest; @@ -11,10 +11,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.util.HashMap; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; +import java.util.*; /** * http 工具类 获取请求中的参数 @@ -25,6 +22,10 @@ import java.util.TreeMap; @Slf4j public class HttpUtils { + private HttpUtils(){ + + } + /** * 将URL的参数和body参数合并 * @@ -41,7 +42,7 @@ public class HttpUtils { log.info(" pathVariable: {}",pathVariable); String deString = URLDecoder.decode(pathVariable, "UTF-8"); log.info(" pathVariable decode: {}",deString); - result.put(SignUtil.xPathVariable, deString); + result.put(SignUtil.X_PATH_VARIABLE, deString); } // 获取URL上的参数 Map urlParams = getUrlParams(request); @@ -79,7 +80,7 @@ public class HttpUtils { log.info(" pathVariable: {}",pathVariable); String deString = URLDecoder.decode(pathVariable, "UTF-8"); log.info(" pathVariable decode: {}",deString); - result.put(SignUtil.xPathVariable, deString); + result.put(SignUtil.X_PATH_VARIABLE, deString); } // 获取URL上的参数 Map urlParams = getUrlParams(queryString); @@ -105,8 +106,9 @@ public class HttpUtils { * * @date 15:04 20210621 * @param request + * @return */ - public static Map getAllRequestParam(final HttpServletRequest request) throws IOException { + public static Map getAllRequestParam(final HttpServletRequest request) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream())); String str = ""; @@ -116,7 +118,7 @@ public class HttpUtils { wholeStr.append(str); } // 转化成json对象 - return JSONObject.parseObject(wholeStr.toString(), Map.class); + return JSON.parseObject(wholeStr.toString(), Map.class); } /** @@ -125,13 +127,13 @@ public class HttpUtils { * @date 15:04 20210621 * @param body */ - public static Map getAllRequestParam(final byte[] body) throws IOException { + public static Map getAllRequestParam(final byte[] body){ if(body==null){ - return null; + return Collections.emptyMap(); } String wholeStr = new String(body); // 转化成json对象 - return JSONObject.parseObject(wholeStr.toString(), Map.class); + return JSON.parseObject(wholeStr, Map.class); } /** @@ -160,7 +162,7 @@ public class HttpUtils { /** * 将URL请求参数转换成Map - * + * * @param queryString */ public static Map getUrlParams(String queryString) { @@ -181,4 +183,4 @@ public class HttpUtils { } return result; } -} \ No newline at end of file +} diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/SignUtil.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/SignUtil.java index f2e58f61..fa2ca0fb 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/SignUtil.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/config/sign/util/SignUtil.java @@ -1,5 +1,6 @@ package com.jero.config.sign.util; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import com.jero.common.exception.JeroBootException; @@ -8,18 +9,24 @@ import com.jero.common.util.oConvertUtils; import com.jero.config.StaticConfig; import org.springframework.util.DigestUtils; import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.PathVariable; import java.util.SortedMap; /** * 签名工具类 - * + * * @author jeecg * @date 20210621 */ @Slf4j public class SignUtil { - public static final String xPathVariable = "x-path-variable"; + + private SignUtil(){ + + } + + public static final String X_PATH_VARIABLE = "x-path-variable"; /** * @param params @@ -44,7 +51,7 @@ public class SignUtil { public static String getParamsSign(SortedMap params) { //去掉 Url 里的时间戳 params.remove("_t"); - String paramsJsonStr = JSONObject.toJSONString(params); + String paramsJsonStr = JSON.toJSONString(params); log.info("Param paramsJsonStr : {}", paramsJsonStr); StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class); String signatureSecret = staticConfig.getSignatureSecret(); @@ -53,4 +60,4 @@ public class SignUtil { } return DigestUtils.md5DigestAsHex((paramsJsonStr + signatureSecret).getBytes()).toUpperCase(); } -} \ No newline at end of file +} diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/BaseCommonService.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/BaseCommonService.java index 81733b55..3102882e 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/BaseCommonService.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/BaseCommonService.java @@ -16,19 +16,19 @@ public interface BaseCommonService { /** * 保存日志 - * @param LogContent + * @param logContent * @param logType * @param operateType * @param user */ - void addLog(String LogContent, Integer logType, Integer operateType, LoginUser user); + void addLog(String logContent, Integer logType, Integer operateType, LoginUser user); /** * 保存日志 - * @param LogContent + * @param logContent * @param logType * @param operateType */ - void addLog(String LogContent, Integer logType, Integer operateType); + void addLog(String logContent, Integer logType, Integer operateType); } diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/impl/BaseCommonServiceImpl.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/impl/BaseCommonServiceImpl.java index 8c93f605..7872f9e3 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/impl/BaseCommonServiceImpl.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/modules/base/service/impl/BaseCommonServiceImpl.java @@ -64,7 +64,7 @@ public class BaseCommonServiceImpl implements BaseCommonService { try { user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); } catch (Exception e) { - //e.printStackTrace(); + log.error("异常",e.getMessage()); } } if(user!=null){