diff --git a/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java b/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java index 28b6167..a46841a 100644 --- a/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java +++ b/opsli-api/src/main/java/org/opsli/api/utils/ValidationUtil.java @@ -43,6 +43,9 @@ public final class ValidationUtil { /** 编码格式 */ private static final String CHARSET_NAME = "utf-8"; + /** NULL */ + private static final String NULL = "null"; + /** * 验证对象 * @param obj @@ -112,7 +115,9 @@ public final class ValidationUtil { break; // 字母,数字和下划线 case IS_GENERAL: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)) { + break; + } boolean general = Validator.isGeneral(value); if(!general){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_GENERAL; @@ -122,7 +127,9 @@ public final class ValidationUtil { break; // 数字 case IS_NUMBER: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean number = Validator.isNumber(value); if(!number){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_NUMBER; @@ -132,7 +139,9 @@ public final class ValidationUtil { break; // 纯字母 case IS_LETTER: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean letter = Validator.isLetter(value); if(!letter){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_LETTER; @@ -142,7 +151,9 @@ public final class ValidationUtil { break; // 大写 case IS_UPPER_CASE: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean upperCase = Validator.isUpperCase(value); if(!upperCase){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_UPPER_CASE; @@ -152,7 +163,9 @@ public final class ValidationUtil { break; // 小写 case IS_LOWER_CASE: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean lowerCase = Validator.isLowerCase(value); if(!lowerCase){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_LOWER_CASE; @@ -162,7 +175,9 @@ public final class ValidationUtil { break; // IPV4 case IS_IPV4: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean ipv4 = Validator.isIpv4(value); if(!ipv4){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_IPV4; @@ -172,7 +187,9 @@ public final class ValidationUtil { break; // 金额 case IS_MONEY: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean money = Validator.isMoney(value); if(!money){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MONEY; @@ -182,7 +199,9 @@ public final class ValidationUtil { break; // 邮箱 case IS_EMAIL: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean email = Validator.isEmail(value); if(!email){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_EMAIL; @@ -192,7 +211,9 @@ public final class ValidationUtil { break; // 手机号 case IS_MOBILE: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean mobile = Validator.isMobile(value); if(!mobile){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MOBILE; @@ -202,7 +223,9 @@ public final class ValidationUtil { break; // 18位身份证 case IS_CITIZENID: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean citizenId = Validator.isCitizenId(value); if(!citizenId){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_CITIZENID; @@ -212,7 +235,9 @@ public final class ValidationUtil { break; // 邮编 case IS_ZIPCODE: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean zipCode = Validator.isZipCode(value); if(!zipCode){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_ZIPCODE; @@ -222,7 +247,9 @@ public final class ValidationUtil { break; // URL case IS_URL: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean url = Validator.isUrl(value); if(!url){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_URL; @@ -232,7 +259,9 @@ public final class ValidationUtil { break; // 汉字 case IS_CHINESE: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean chinese = Validator.isChinese(value); if(!chinese){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_CHINESE; @@ -242,7 +271,9 @@ public final class ValidationUtil { break; // 汉字,字母,数字和下划线 case IS_GENERAL_WITH_CHINESE: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean generalWithChinese = Validator.isGeneralWithChinese(value); if(!generalWithChinese){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_GENERAL_WITH_CHINESE; @@ -252,7 +283,9 @@ public final class ValidationUtil { break; // MAC地址 case IS_MAC: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean mac = Validator.isMac(value); if(!mac){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MAC; @@ -262,7 +295,9 @@ public final class ValidationUtil { break; // 中国车牌 case IS_PLATE_NUMBER: - if(StringUtils.isEmpty(value) || "null".equals(value)) break; + if(StringUtils.isEmpty(value) || NULL.equals(value)){ + break; + } boolean plateNumber = Validator.isPlateNumber(value); if(!plateNumber){ ValidationMsg msg = ValidationMsg.EXCEPTION_IS_PLATE_NUMBER; @@ -299,7 +334,7 @@ public final class ValidationUtil { // 循环验证 try { String value = String.valueOf(fieldValue); - if(value != null && !"null".equals(value)){ + if(value != null && !NULL.equals(value)){ // 转换为 数据库真实 长度 int strLength = value.getBytes(CHARSET_NAME).length; if(strLength > maxLength){ @@ -332,7 +367,7 @@ public final class ValidationUtil { // 循环验证 try { String value = String.valueOf(fieldValue); - if(value != null && !"null".equals(value)){ + if(value != null && !NULL.equals(value)){ // 转换为 数据库真实 长度 int strLength = value.getBytes(CHARSET_NAME).length; if(strLength < minLength){ diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java index f2dbf62..15c2cea 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/api/TokenThreadLocal.java @@ -25,21 +25,21 @@ package org.opsli.common.api; public class TokenThreadLocal { /** 临时线程存储 token 容器 */ - private static final ThreadLocal tokenData = new ThreadLocal<>(); + private static final ThreadLocal TOKEN_DATA = new ThreadLocal<>(); public static void put(String token) { - if (tokenData.get() == null) { - tokenData.set(token); + if (TOKEN_DATA.get() == null) { + TOKEN_DATA.set(token); } } public static String get() { - return tokenData.get(); + return TOKEN_DATA.get(); } public static void remove() { try { - tokenData.remove(); + TOKEN_DATA.remove(); }catch (Exception e){} } } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java index 0e96c09..8e6852c 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/constants/MyBatisConstants.java @@ -27,14 +27,12 @@ import org.opsli.common.utils.Props; */ public final class MyBatisConstants { - private static final Props prop = new Props("application.yaml"); /** 逻辑删除值 */ - public static final char LOGIC_DELETE_VALUE = - prop.getChar("mybatis-plus.global-config.db-config.logic-delete-value",'1'); + public static final char LOGIC_DELETE_VALUE; /** 逻辑不删除值 */ - public static final char LOGIC_NOT_DELETE_VALUE = - prop.getChar("mybatis-plus.global-config.db-config.logic-not-delete-value",'0'); + public static final char LOGIC_NOT_DELETE_VALUE; + /** ID */ public static final String FIELD_ID = "id"; @@ -55,5 +53,12 @@ public final class MyBatisConstants { /** 多租户字段 */ public static final String FIELD_TENANT = "tenantId"; + + static { + Props props = new Props("application.yaml"); + LOGIC_DELETE_VALUE = props.getChar("mybatis-plus.global-config.db-config.logic-delete-value",'1'); + LOGIC_NOT_DELETE_VALUE = props.getChar("mybatis-plus.global-config.db-config.logic-not-delete-value",'0'); + } + private MyBatisConstants(){} } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/thread/factory/NameableThreadFactory.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/thread/factory/NameableThreadFactory.java index bf15259..84c6b16 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/thread/factory/NameableThreadFactory.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/thread/factory/NameableThreadFactory.java @@ -50,10 +50,12 @@ public class NameableThreadFactory implements ThreadFactory{ Thread t = new Thread(threadGroup, r, namePrefix + threadNumber.getAndIncrement(), 0); - if (t.isDaemon()) + if (t.isDaemon()){ t.setDaemon(false); - if (t.getPriority() != Thread.NORM_PRIORITY) + } + if (t.getPriority() != Thread.NORM_PRIORITY){ t.setPriority(Thread.NORM_PRIORITY); + } return t; } } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/BigDecimalUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/BigDecimalUtil.java index 6679f59..31c29e8 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/BigDecimalUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/BigDecimalUtil.java @@ -32,8 +32,8 @@ public class BigDecimalUtil { * @return 两个参数的和 */ public static double add(double value1,double value2){ - BigDecimal b1 = new BigDecimal(Double.toString(value1)); - BigDecimal b2 = new BigDecimal(Double.toString(value2)); + BigDecimal b1 = BigDecimal.valueOf(value1); + BigDecimal b2 = BigDecimal.valueOf(value2); return b1.add(b2).doubleValue(); } @@ -44,8 +44,8 @@ public class BigDecimalUtil { * @return 两个参数的差 */ public static double sub(double value1,double value2){ - BigDecimal b1 = new BigDecimal(Double.toString(value1)); - BigDecimal b2 = new BigDecimal(Double.toString(value2)); + BigDecimal b1 = BigDecimal.valueOf(value1); + BigDecimal b2 = BigDecimal.valueOf(value2); return b1.subtract(b2).doubleValue(); } @@ -56,8 +56,8 @@ public class BigDecimalUtil { * @return 两个参数的积 */ public static double mul(double value1,double value2){ - BigDecimal b1 = new BigDecimal(Double.toString(value1)); - BigDecimal b2 = new BigDecimal(Double.toString(value2)); + BigDecimal b1 = BigDecimal.valueOf(value1); + BigDecimal b2 = BigDecimal.valueOf(value2); return b1.multiply(b2).doubleValue(); } @@ -83,8 +83,8 @@ public class BigDecimalUtil { if(scale<0){ throw new IllegalAccessException("精确度不能小于0"); } - BigDecimal b1 = new BigDecimal(Double.toString(value1)); - BigDecimal b2 = new BigDecimal(Double.toString(value2)); + BigDecimal b1 = BigDecimal.valueOf(value1); + BigDecimal b2 = BigDecimal.valueOf(value2); return b1.divide(b2, scale, model).doubleValue(); } public static double div(double value1,double value2,int scale) throws IllegalAccessException{ @@ -92,8 +92,8 @@ public class BigDecimalUtil { if(scale<0){ throw new IllegalAccessException("精确度不能小于0"); } - BigDecimal b1 = new BigDecimal(Double.toString(value1)); - BigDecimal b2 = new BigDecimal(Double.toString(value2)); + BigDecimal b1 = BigDecimal.valueOf(value1); + BigDecimal b2 = BigDecimal.valueOf(value2); return b1.divide(b2, scale,4).doubleValue(); } } diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java index 64fc1af..8652697 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java @@ -39,7 +39,7 @@ public final class HumpUtil { public static String underlineToHump(String para) { StringBuilder result = new StringBuilder(); - String a[] = para.split(UNDERLINE); + String[] a = para.split(UNDERLINE); for (String s : a) { if (!para.contains(UNDERLINE)) { result.append(s); diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java index 55a5762..b36ec61 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/IPUtil.java @@ -26,6 +26,8 @@ import javax.servlet.http.HttpServletRequest; */ public final class IPUtil { + private static final String UNKNOWN = "unknown"; + /** * 获取客户端ip地址(可以穿透代理) * @@ -34,19 +36,19 @@ public final class IPUtil { */ public static String getRemoteAddr(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.equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.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.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_CLIENT_IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED_FOR"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; @@ -73,7 +75,7 @@ public final class IPUtil { public static String getClientIpAddress(HttpServletRequest request) { for (String header : HEADERS_TO_TRY) { String ip = request.getHeader(header); - if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { + if (ip != null && ip.length() != 0 && !UNKNOWN.equalsIgnoreCase(ip)) { return ip; } } @@ -86,37 +88,37 @@ public final class IPUtil { */ public static String getClientIpAddr(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.equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.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.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED_FOR"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_CLUSTER_CLIENT_IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_CLIENT_IP"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_FORWARDED_FOR"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_FORWARDED"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_VIA"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getHeader("REMOTE_ADDR"); } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; @@ -124,12 +126,12 @@ public final class IPUtil { public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("X-Real-IP"); if (null != ip && !"".equals(ip.trim()) - && !"unknown".equalsIgnoreCase(ip)) { + && !UNKNOWN.equalsIgnoreCase(ip)) { return ip; } ip = request.getHeader("X-Forwarded-For"); if (null != ip && !"".equals(ip.trim()) - && !"unknown".equalsIgnoreCase(ip)) { + && !UNKNOWN.equalsIgnoreCase(ip)) { // get first ip from proxy ip int index = ip.indexOf(','); if (index != -1) { @@ -143,5 +145,6 @@ public final class IPUtil { // =============== + private IPUtil(){} } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java index 8f4018e..77157f3 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/CacheDataAop.java @@ -190,7 +190,9 @@ public class CacheDataAop { try { // 获得方法 Method objMethod = this.getMethod(point); - if(objMethod == null) return null; + if(objMethod == null) { + return null; + } // 获取注解参数 HotDataPut aCache= objMethod.getAnnotation(HotDataPut.class); @@ -239,7 +241,9 @@ public class CacheDataAop { try { // 获得方法 Method objMethod = this.getMethod(point); - if(objMethod == null) return null; + if(objMethod == null) { + return null; + } // 获取注解参数 HotDataDel aCache= objMethod.getAnnotation(HotDataDel.class); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java index 01614db..585bda5 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/aspect/ValitaionArgsAop.java @@ -45,6 +45,8 @@ import static org.opsli.common.constants.OrderConstants.PARAM_VALIDATE_AOP_SORT; @Component public class ValitaionArgsAop { + /** post请求 */ + private static final String POST_TYPE = "POST"; @Pointcut("execution(public * org.opsli.modulars*..*.*Controller*.*(..))") public void requestMapping() { @@ -60,12 +62,14 @@ public class ValitaionArgsAop { try { RequestAttributes ra = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes sra = (ServletRequestAttributes) ra; - if(sra == null) return; + if(sra == null){ + return; + } HttpServletRequest request = sra.getRequest(); String method = request.getMethod(); // 只有 post 请求 才会去验证数据 - if("POST".equals(method)){ + if(POST_TYPE.equals(method)){ for (Object arg : args) { // 参数校验 if(arg instanceof ApiWrapper){ diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java index f1b5358..ccf66cb 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/concroller/BaseRestController.java @@ -79,11 +79,11 @@ public abstract class BaseRestController entityClazz; /** Entity 泛型游标 */ - private static final int entityIndex = 0; + private static final int ENTITY_INDEX = 0; /** Model Clazz 类 */ protected Class modelClazz; /** Model 泛型游标 */ - private static final int modelIndex = 1; + private static final int MODEL_INDEX = 1; @Autowired(required = false) protected S IService; @@ -326,7 +326,7 @@ public abstract class BaseRestController getModelClass(){ Class tClass = null; - Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), modelIndex); + Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), MODEL_INDEX); if(typeArgument != null){ tClass = (Class) typeArgument; } @@ -339,7 +339,7 @@ public abstract class BaseRestController getEntityClass(){ Class tClass = null; - Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), entityIndex); + Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), ENTITY_INDEX); if(typeArgument != null){ tClass = (Class) typeArgument; } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java index 4810a7a..51c99ca 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/base/service/impl/CrudServiceImpl.java @@ -66,11 +66,11 @@ public abstract class CrudServiceImpl, T extends BaseEnt /** Entity Clazz 类 */ protected Class entityClazz; /** Entity 泛型游标 */ - private static final int entityIndex = 1; + private static final int ENTITY_INDEX = 1; /** Model Clazz 类 */ protected Class modelClazz; /** Model 泛型游标 */ - private static final int modelIndex = 2; + private static final int MODEL_INDEX = 2; @Override public E get(String id) { @@ -81,7 +81,9 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override public E get(E model) { - if(model == null) return null; + if(model == null){ + return null; + } return transformT2M( super.getById(model.getId()) ); @@ -90,7 +92,9 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override @Transactional(readOnly = false) public E insert(E model) { - if(model == null) return null; + if(model == null){ + return null; + } // 默认清空 创建人和修改人 if(model.getIzManual() != null && !model.getIzManual()){ @@ -111,7 +115,9 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override @Transactional(readOnly = false) public boolean insertBatch(List models) { - if(models == null || models.size() == 0) return false; + if(models == null || models.size() == 0){ + return false; + } for (E model : models) { // 默认清空 创建人和修改人 @@ -131,7 +137,9 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override @Transactional(readOnly = false) public E update(E model) { - if(model == null) return null; + if(model == null){ + return null; + } // 默认清空 创建人和修改人 if(model.getIzManual() != null && !model.getIzManual()){ @@ -150,7 +158,9 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override @Transactional(readOnly = false) public E save(E model) { - if(model == null) return null; + if(model == null){ + return null; + } // 修改 if(StringUtils.isNotBlank(model.getId())){ @@ -171,14 +181,18 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override @Transactional(readOnly = false) public boolean delete(E model) { - if(model == null) return false; + if(model == null){ + return false; + } return super.removeById(model.getId()); } @Override @Transactional(readOnly = false) public boolean deleteAll(String[] ids) { - if(ids == null) return false; + if(ids == null){ + return false; + } List idList = Convert.toList(String.class, ids); return super.removeByIds(idList); } @@ -186,7 +200,9 @@ public abstract class CrudServiceImpl, T extends BaseEnt @Override @Transactional(readOnly = false) public boolean deleteAll(Collection models) { - if(models == null || models.isEmpty()) return false; + if(models == null || models.isEmpty()){ + return false; + } List idList = Lists.newArrayListWithCapacity(models.size()); for (E entity : models) { idList.add(entity.getId()); @@ -287,7 +303,7 @@ public abstract class CrudServiceImpl, T extends BaseEnt */ private Class getModelClazz(){ Class tClass = null; - Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), modelIndex); + Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), MODEL_INDEX); if(typeArgument != null){ tClass = (Class) typeArgument; } @@ -300,7 +316,7 @@ public abstract class CrudServiceImpl, T extends BaseEnt */ private Class getEntityClazz(){ Class tClass = null; - Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), entityIndex); + Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), ENTITY_INDEX); if(typeArgument != null){ tClass = (Class) typeArgument; } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java index cf99d4a..e9319ce 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/DictHandler.java @@ -57,14 +57,18 @@ public class DictHandler implements RedisPushSubHandler{ Collection dicts = (Collection) msgJson.get(MsgArgsType.DICT_MODELS.toString()); for (Object dictObj : dicts) { JSONObject jsonObject = msgJson.getJSONObject(MsgArgsType.DICT_MODEL.toString()); - if(jsonObject == null) continue; + if(jsonObject == null){ + continue; + } DictWrapper dictWrapperModel = jsonObject.toJavaObject(DictWrapper.class); this.handler(dictWrapperModel, type); } } else if(DictModelType.OBJECT == dictModelType){ JSONObject jsonObject = msgJson.getJSONObject(MsgArgsType.DICT_MODEL.toString()); - if(jsonObject == null) return; + if(jsonObject == null){ + return; + } DictWrapper dictWrapperModel = jsonObject.toJavaObject(DictWrapper.class); this.handler(dictWrapperModel, type); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java index 295e11d..02d014b 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/MenuHandler.java @@ -57,7 +57,9 @@ public class MenuHandler implements RedisPushSubHandler{ private void menuHandler(JSONObject msgJson){ JSONObject data = msgJson.getJSONObject(MsgArgsType.MENU_MODEL_DATA.toString()); // 数据为空则不执行 - if(data == null) return; + if(data == null){ + return; + } // 获得菜单编号 String menuCode = (String) msgJson.get(MsgArgsType.MENU_CODE.toString()); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/OrgHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/OrgHandler.java index e66fcf0..792d5b7 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/OrgHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/OrgHandler.java @@ -58,7 +58,9 @@ public class OrgHandler implements RedisPushSubHandler{ private void orgHandler(JSONObject msgJson){ JSONObject data = msgJson.getJSONObject(MsgArgsType.ORG_USER_DATA.toString()); // 数据为空则不执行 - if(data == null) return; + if(data == null){ + return; + } // 获得用户ID String userId = (String) msgJson.get(MsgArgsType.ORG_USER_ID.toString()); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java index 955c772..213eb3e 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/cache/pushsub/handler/UserHandler.java @@ -77,7 +77,9 @@ public class UserHandler implements RedisPushSubHandler{ private void userHandler(JSONObject msgJson){ JSONObject data = msgJson.getJSONObject(MsgArgsType.USER_MODEL_DATA.toString()); // 数据为空则不执行 - if(data == null) return; + if(data == null){ + return; + } // 获得用户ID 和 用户名 String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); @@ -101,7 +103,9 @@ public class UserHandler implements RedisPushSubHandler{ private void userRolesHandler(JSONObject msgJson){ JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString()); // 数据为空则不执行 - if(dataArray == null || dataArray.isEmpty()) return; + if(dataArray == null || dataArray.isEmpty()){ + return; + } // 获得用户ID String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); @@ -122,7 +126,9 @@ public class UserHandler implements RedisPushSubHandler{ private void userPermsHandler(JSONObject msgJson){ JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString()); // 数据为空则不执行 - if(dataArray == null || dataArray.isEmpty()) return; + if(dataArray == null || dataArray.isEmpty()){ + return; + } // 获得用户ID String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); @@ -143,7 +149,9 @@ public class UserHandler implements RedisPushSubHandler{ private void userMenusHandler(JSONObject msgJson){ JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString()); // 数据为空则不执行 - if(dataArray == null || dataArray.isEmpty()) return; + if(dataArray == null || dataArray.isEmpty()){ + return; + } // 获得用户ID String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java index d415d92..1cff3e6 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/ShiroConfig.java @@ -16,6 +16,7 @@ package org.opsli.core.conf; import cn.hutool.core.collection.CollUtil; +import com.google.common.collect.Maps; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.session.mgt.SessionManager; import org.apache.shiro.spring.LifecycleBeanPostProcessor; @@ -71,11 +72,11 @@ public class ShiroConfig { shiroFilter.setSecurityManager(securityManager); //oauth过滤 - Map filters = new HashMap<>(); + Map filters = Maps.newHashMapWithExpectedSize(1); filters.put("oauth2", new OAuth2Filter()); shiroFilter.setFilters(filters); - Map filterMap = new LinkedHashMap<>(); + Map filterMap = Maps.newLinkedHashMap(); filterMap.put("/webjars/**", "anon"); filterMap.put("/druid/**", "anon"); filterMap.put("/app/**", "anon"); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java index 274f649..298d87b 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/conf/mybatis/AutoFillInterceptor.java @@ -51,6 +51,8 @@ import java.util.*; @Intercepts(@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})) public class AutoFillInterceptor implements Interceptor { + private static final String ET = "et"; + @Override public Object intercept(Invocation invocation) throws IllegalAccessException, InvocationTargetException { fillField(invocation); @@ -69,11 +71,12 @@ public class AutoFillInterceptor implements Interceptor { //String className = arg.getClass().getName(); //log.info(i + " 参数类型:" + className); //第一个参数处理。根据它判断是否给“操作属性”赋值。 - if (arg instanceof MappedStatement) {//如果是第一个参数 MappedStatement + //如果是第一个参数 MappedStatement + if (arg instanceof MappedStatement) { MappedStatement ms = (MappedStatement) arg; sqlCommandType = ms.getSqlCommandType(); - //log.info("操作类型:" + sqlCommandType); - if (sqlCommandType == SqlCommandType.INSERT || sqlCommandType == SqlCommandType.UPDATE) {//如果是“增加”或“更新”操作,则继续进行默认操作信息赋值。否则,则退出 + //如果是“增加”或“更新”操作,则继续进行默认操作信息赋值。否则,则退出 + if (sqlCommandType == SqlCommandType.INSERT || sqlCommandType == SqlCommandType.UPDATE) { continue; } else { break; @@ -96,7 +99,9 @@ public class AutoFillInterceptor implements Interceptor { * @param arg */ public void insertFill(Object arg) { - if(arg == null ) return; + if(arg == null ){ + return; + } Field[] fields = ReflectUtil.getFields(arg.getClass()); for (Field f : fields) { @@ -162,14 +167,16 @@ public class AutoFillInterceptor implements Interceptor { * @param arg */ public void updateFill(Object arg) { - if(arg == null ) return; + if(arg == null ){ + return; + } // 2020-09-19 // 修改这儿 有可能会拿到一个 MapperMethod,需要特殊处理 Field[] fields; if (arg instanceof MapperMethod.ParamMap) { MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) arg; - if (paramMap.containsKey("et")) { + if (paramMap.containsKey(ET)) { arg = paramMap.get("et"); } else { arg = paramMap.get("param1"); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java index 5940955..f4dc438 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/handler/GlobalExceptionHandler.java @@ -43,6 +43,8 @@ import static org.opsli.common.constants.OrderConstants.EXCEPTION_HANDLER_ORDER; @Order(EXCEPTION_HANDLER_ORDER) public class GlobalExceptionHandler { + private static final String SQL_EXCEPTION = "doesn't have a default value"; + /* 算数异常类:ArithmeticException 空指针异常类型:NullPointerException @@ -197,7 +199,7 @@ public class GlobalExceptionHandler { public ResultVo sqlException(SQLException e) { //log.error("数据异常:{}",e.getMessage(),e); // 默认值异常 - if(StringUtils.contains(e.getMessage(),"doesn't have a default value")){ + if(StringUtils.contains(e.getMessage(),SQL_EXCEPTION)){ String Field = e.getMessage().replaceAll("Field '","") .replaceAll("' doesn't have a default value",""); String msg = StrFormatter.format(CoreMsg.SQL_EXCEPTION_NOT_HAVE_DEFAULT_VALUE.getMessage(), Field); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java index 448c3c0..ae4cd4e 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/msg/JwtMsg.java @@ -26,6 +26,7 @@ import org.opsli.common.base.msg.BaseMsg; */ public enum JwtMsg implements BaseMsg { + /** 异常消息 */ EXCEPTION_TOKEN(11000,"认证解密异常: {}"), EXCEPTION_DECODE(10101,"解密异常: {}"), EXCEPTION_ENCODE(10102,"加密异常: {}"), diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java index 3288991..a1b0a6c 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/persistence/Page.java @@ -113,7 +113,7 @@ public class Page extends PageSeriali * @return map对象 */ public Map getBootstrapData(){ - Map map = new HashMap<>(); + Map map = new HashMap<>(2); map.put("rows", this.getList()); map.put("total", this.getTotal()); return map; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java index d6e171f..c2ea417 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/realm/OAuth2Realm.java @@ -25,6 +25,9 @@ import java.util.List; @Component public class OAuth2Realm extends AuthorizingRealm { + /** 账号锁定状态 */ + private static final char LOCK_VAL = '1'; + @Override public boolean supports(AuthenticationToken token) { return token instanceof OAuth2Token; @@ -73,7 +76,7 @@ public class OAuth2Realm extends AuthorizingRealm { UserModel user = UserUtil.getUser(userId); // 3. 校验账户是否锁定 - if(user == null || user.getLocked().equals('1')){ + if(user == null || user.getLocked().equals(LOCK_VAL)){ // 账号已被锁定,请联系管理员 // token失效,请重新登录 throw new TokenException( diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/utils/ShiroUtils.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/utils/ShiroUtils.java index 5295926..8a85cdf 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/utils/ShiroUtils.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/security/shiro/utils/ShiroUtils.java @@ -24,7 +24,7 @@ import org.opsli.api.wrapper.system.user.UserModel; /** * Shiro工具类 - * + * * @author 孙志强 * @date 2016年11月12日 上午9:49:19 @@ -32,12 +32,12 @@ import org.opsli.api.wrapper.system.user.UserModel; public class ShiroUtils { /** 加密算法 */ - public final static String hashAlgorithmName = "MD5"; + public final static String HASH_ALGORITHM_NAME = "MD5"; /** 循环次数 */ - public final static int hashIterations = 1; + public final static int HASH_ITERATIONS = 1; public static String sha256(String password, String salt) { - return new SimpleHash(hashAlgorithmName, password, salt, hashIterations).toString(); + return new SimpleHash(HASH_ALGORITHM_NAME, password, salt, HASH_ITERATIONS).toString(); } public static Session getSession() { @@ -55,7 +55,7 @@ public class ShiroUtils { public static String getUserId() { return getUser().getId(); } - + public static void setSessionAttribute(Object key, Object value) { getSession().setAttribute(key, value); } @@ -71,7 +71,7 @@ public class ShiroUtils { public static void logout() { SecurityUtils.getSubject().logout(); } - + public static String getKaptcha(String key) throws RuntimeException { Object kaptcha = getSessionAttribute(key); if(kaptcha == null){ diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java index b84b240..e834808 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/CaptchaUtil.java @@ -90,7 +90,9 @@ public class CaptchaUtil{ * @return */ public static boolean validate(String uuid, String code) { - if(StringUtils.isEmpty(uuid)) return false; + if(StringUtils.isEmpty(uuid)){ + return false; + } // 验证码 String codeTemp = (String) redisPlugin.get(PREFIX_NAME + PREFIX + uuid); @@ -112,7 +114,9 @@ public class CaptchaUtil{ * @return */ public static boolean delCaptcha(String uuid) { - if(StringUtils.isEmpty(uuid)) return false; + if(StringUtils.isEmpty(uuid)){ + return false; + } //删除验证码 return redisPlugin.del(PREFIX_NAME + PREFIX + uuid); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java index 55fcd97..2702b14 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/DictUtil.java @@ -81,7 +81,9 @@ public class DictUtil { if (cacheModel != null){ dictName = cacheModel.getDictName(); } - if (StringUtils.isNotEmpty(dictName)) return dictName; + if (StringUtils.isNotEmpty(dictName)){ + return dictName; + } // 防止缓存穿透判断 @@ -112,7 +114,9 @@ public class DictUtil { if (cacheModel != null){ dictName = cacheModel.getDictName(); } - if (StringUtils.isNotEmpty(dictName)) return dictName; + if (StringUtils.isNotEmpty(dictName)){ + return dictName; + } // 查询数据库 并保存到缓存内 ResultVo> resultVo = dictDetailApi.findListByTypeCode(typeCode); @@ -168,7 +172,9 @@ public class DictUtil { if (cacheModel != null){ dictValue = cacheModel.getDictValue(); } - if (StringUtils.isNotEmpty(dictValue)) return dictValue; + if (StringUtils.isNotEmpty(dictValue)){ + return dictValue; + } // 防止缓存穿透判断 boolean hasNilFlag = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_NAME + typeCode + ":" + dictName); @@ -196,7 +202,9 @@ public class DictUtil { if (cacheModel != null){ dictValue = cacheModel.getDictValue(); } - if (StringUtils.isNotEmpty(dictValue)) return dictValue; + if (StringUtils.isNotEmpty(dictValue)){ + return dictValue; + } // 查询数据库 并保存到缓存内 ResultVo> resultVo = dictDetailApi.findListByTypeCode(typeCode); diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java index 6903bc9..701e7e1 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/ExcelUtil.java @@ -177,7 +177,9 @@ public class ExcelUtil extends ExcelPlugin { String typeCode = entry.getValue(); List dictWrapperList = DictUtil.getDictList(typeCode); // 如果字典 List 为空 则走下一个 - if(dictWrapperList == null || dictWrapperList.size() == 0) continue; + if(dictWrapperList == null || dictWrapperList.size() == 0){ + continue; + } typeCodeAndValue.put(typeCode, dictWrapperList); } return typeCodeAndValue; diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java index bf98879..70143e9 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/JwtUtil.java @@ -32,7 +32,7 @@ public final class JwtUtil { /** * JWT认证加密私钥(Base64加密) */ - private static final String encryptJWTKey="a30ade6452725123436288ccae58570738ee"; + private static final String ENCRYPT_JWT_KEY = "a30ade6452725123436288ccae58570738ee"; static { Props props = new Props("application.yaml"); @@ -48,7 +48,7 @@ public final class JwtUtil { */ public static boolean verify(String token) { try { - String secret = getClaim(token, SignConstants.ACCOUNT) + Base64ConvertUtil.decode(encryptJWTKey); + String secret = getClaim(token, SignConstants.ACCOUNT) + Base64ConvertUtil.decode(ENCRYPT_JWT_KEY); Algorithm algorithm = Algorithm.HMAC256(secret); JWTVerifier verifier = JWT.require(algorithm).build(); verifier.verify(token); @@ -85,7 +85,7 @@ public final class JwtUtil { public static String sign(String account, String userId) { try { // 帐号加JWT私钥加密 - String secret = account + Base64ConvertUtil.decode(encryptJWTKey); + String secret = account + Base64ConvertUtil.decode(ENCRYPT_JWT_KEY); // 此处过期时间是以毫秒为单位,所以乘以1000 Date date = new Date(System.currentTimeMillis() + EXPIRE); Algorithm algorithm = Algorithm.HMAC256(secret); @@ -114,5 +114,6 @@ public final class JwtUtil { } // ================== + private JwtUtil(){} } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java index 9ed5956..5a9bd71 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/LogUtil.java @@ -61,7 +61,9 @@ public final class LogUtil { RequestAttributes ra = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes sra = (ServletRequestAttributes) ra; - if(sra == null) return; + if(sra == null){ + return; + } HttpServletRequest request = sra.getRequest(); // EnableLog 如果不被 EnableLog修饰 则直接退出 diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java index 755c6c4..c822b36 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/TokenGenerator.java @@ -35,7 +35,7 @@ public final class TokenGenerator { return generateValue(UUID.randomUUID().toString()); } - private static final char[] hexCode = "0123456789abcdef".toCharArray(); + private static final char[] HEX_CODE = "0123456789abcdef".toCharArray(); /** @@ -64,13 +64,14 @@ public final class TokenGenerator { } StringBuilder r = new StringBuilder(data.length*2); for ( byte b : data) { - r.append(hexCode[(b >> 4) & 0xF]); - r.append(hexCode[(b & 0xF)]); + r.append(HEX_CODE[(b >> 4) & 0xF]); + r.append(HEX_CODE[(b & 0xF)]); } return r.toString(); } // ========================= + private TokenGenerator(){} } diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java index 000a391..82bff86 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/utils/UserTokenUtil.java @@ -153,7 +153,9 @@ public class UserTokenUtil { * @return */ public static String getUserIdByToken(String token) { - if(StringUtils.isEmpty(token)) return null; + if(StringUtils.isEmpty(token)){ + return null; + } String userId = ""; try { userId = JwtUtil.getClaim(token, SignConstants.USER_ID); @@ -167,7 +169,9 @@ public class UserTokenUtil { * @return */ public static String getUserNameByToken(String token) { - if(StringUtils.isEmpty(token)) return null; + if(StringUtils.isEmpty(token)){ + return null; + } String username = ""; try { username = JwtUtil.getClaim(token, SignConstants.ACCOUNT); @@ -182,7 +186,9 @@ public class UserTokenUtil { * @param token */ public static void logout(String token) { - if(StringUtils.isEmpty(token)) return; + if(StringUtils.isEmpty(token)){ + return; + } try { // 生成MD5 16进制码 用于缩减存储 String signTokenHex = new Md5Hash(token).toHex(); @@ -207,7 +213,9 @@ public class UserTokenUtil { * @param token */ public static boolean verify(String token) { - if(StringUtils.isEmpty(token)) return false; + if(StringUtils.isEmpty(token)){ + return false; + } try { // 1. 校验是否是有效的 token diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java index ea2545a..9e6d3bd 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/XSSFilterKit.java @@ -27,6 +27,34 @@ import java.util.regex.Pattern; * */ public final class XSSFilterKit { + private static final Pattern SCRIPT_ALL_PATTERN; + private static final Pattern SCRIPT_INNER_PATTERN; + private static final Pattern SCRIPT_PATTERN; + private static final Pattern EVAL_PATTERN; + private static final Pattern EXPRESSION_PATTERN; + private static final Pattern JAVASCRIPT_PATTERN; + private static final Pattern VBSCRIPT_PATTERN; + private static final Pattern ONLOAD_PATTERN; + static { + SCRIPT_ALL_PATTERN = Pattern.compile("", Pattern.CASE_INSENSITIVE); + SCRIPT_INNER_PATTERN = Pattern.compile("", Pattern.CASE_INSENSITIVE + | Pattern.MULTILINE | Pattern.DOTALL); + SCRIPT_PATTERN = Pattern.compile("", Pattern.CASE_INSENSITIVE); + + EVAL_PATTERN = Pattern.compile("eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE + | Pattern.MULTILINE | Pattern.DOTALL); + + EXPRESSION_PATTERN = Pattern.compile("expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE + | Pattern.MULTILINE | Pattern.DOTALL); + + JAVASCRIPT_PATTERN = Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE); + + VBSCRIPT_PATTERN = Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE); + + ONLOAD_PATTERN = Pattern.compile("onload(.*?)=", Pattern.CASE_INSENSITIVE + | Pattern.MULTILINE | Pattern.DOTALL); + } + /** * @Description 过滤XSS脚本内容 * @param value @@ -43,8 +71,7 @@ public final class XSSFilterKit { rlt = value.replaceAll("", ""); // Avoid anything between script tags - Pattern scriptPattern = Pattern.compile("", Pattern.CASE_INSENSITIVE); - rlt = scriptPattern.matcher(rlt).replaceAll(""); + rlt = SCRIPT_ALL_PATTERN.matcher(rlt).replaceAll(""); // Avoid anything in a src='...' type of expression /*scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE @@ -56,36 +83,25 @@ public final class XSSFilterKit { rlt = scriptPattern.matcher(rlt).replaceAll("");*/ // Remove any lonesome tag - scriptPattern = Pattern.compile("", Pattern.CASE_INSENSITIVE); - rlt = scriptPattern.matcher(rlt).replaceAll(""); + rlt = SCRIPT_PATTERN.matcher(rlt).replaceAll(""); // Remove any lonesome