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