fix the error of ali coding specification

This commit is contained in:
weiweiw 2024-07-05 09:13:22 +08:00
parent 65f2afd201
commit 3179cc57ee
54 changed files with 388 additions and 177 deletions

View File

@ -28,12 +28,21 @@ public interface RemoteLogService
*
* @param sysOperLog 日志实体
* @param source 请求来源
* @throws Exception 异常
* @return 结果
*/
@PostMapping("/operlog")
public R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;
/**
* 保存系统日志
*
* @param sysLogsVo 日志实体
* @param source 请求来源
* @throws Exception 异常
* @return 结果
*/
@PostMapping("/operlog/addLogs")
public R<Boolean> addLogs(@RequestBody SysLogsVo sysLogsVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source) throws Exception;

View File

@ -22,7 +22,11 @@ import java.util.Collection;
import java.util.Map;
import java.util.UUID;
/**
* 日志实体
*
* @author bonus
*/
@Data
@Alias("SysLogsVo")
public class SysLogsVo {
@ -138,7 +142,7 @@ public class SysLogsVo {
vo.setOperaUserName(loginUser.getUsername());
}
Long userId=loginUser.getUserid();
if (userId!=null && userId!=0l) {
if (userId!=null && userId!=0L) {
vo.setUserId(userId.toString());
}
return vo;

View File

@ -125,6 +125,12 @@
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -150,7 +150,12 @@ public @interface Excel
public enum Type
{
ALL(0), EXPORT(1), IMPORT(2);
//导出导入
ALL(0),
//仅导出
EXPORT(1),
//仅导入
IMPORT(2);
private final int value;
Type(int value)
@ -166,7 +171,14 @@ public @interface Excel
public enum ColumnType
{
NUMERIC(0), STRING(1), IMAGE(2), TEXT(3);
//数字
NUMERIC(0),
//字符串
STRING(1),
//图片
IMAGE(2),
//文本
TEXT(3);
private final int value;
ColumnType(int value)

View File

@ -40,7 +40,7 @@ public class SecurityContextHolder
Map<String, Object> map = THREAD_LOCAL.get();
if (map == null)
{
map = new ConcurrentHashMap<String, Object>();
map = new ConcurrentHashMap<String, Object>(16);
THREAD_LOCAL.set(map);
}
return map;

View File

@ -8,6 +8,7 @@ import com.bonus.common.core.constant.Constants;
*
* @author bonus
*/
public class R<T> implements Serializable
{
private static final long serialVersionUID = 1L;

View File

@ -7,7 +7,12 @@ package com.bonus.common.core.enums;
*/
public enum UserStatus
{
OK("0", "正常"), DISABLE("1", "停用"), DELETED("2", "删除");
//正常
OK("0", "正常"),
//停用
DISABLE("1", "停用"),
//删除
DELETED("2", "删除");
private final String code;
private final String info;

View File

@ -29,6 +29,17 @@ public class TaskException extends Exception
public enum Code
{
TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE
//任务存在
TASK_EXISTS,
//任务不存在
NO_TASK_EXISTS,
//任务已经开始
TASK_ALREADY_STARTED,
//未知
UNKNOWN,
//配置出错
CONFIG_ERROR,
//任务节点不可用
TASK_NODE_NOT_AVAILABLE
}
}

View File

@ -889,6 +889,7 @@ public class Convert
* @param input String.
* @return 全角字符串.
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String toSBC(String input)
{
return toSBC(input, null);
@ -901,6 +902,7 @@ public class Convert
* @param notConvertSet 不替换的字符集合
* @return 全角字符串.
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String toSBC(String input, Set<Character> notConvertSet)
{
char[] c = input.toCharArray();
@ -931,6 +933,7 @@ public class Convert
* @param input String.
* @return 半角字符串
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String toDBC(String input)
{
return toDBC(input, null);
@ -943,6 +946,7 @@ public class Convert
* @param notConvertSet 不替换的字符集合
* @return 替换后的字符
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String toDBC(String text, Set<Character> notConvertSet)
{
char[] c = text.toCharArray();

View File

@ -6,6 +6,11 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
* Base64 utils
*
* @author bonus
*/
public class Base64Utils {
private static final String BASE64_MSG = "base64";
@ -49,7 +54,8 @@ public class Base64Utils {
}
public static String getFileNameFromURL(String url) {
@SuppressWarnings("MagicNumber")
public static String getFileNameFromUrl(String url) {
if (url.toLowerCase().startsWith("file:")) {
try {
URL urlObj = new URL(url);

View File

@ -106,7 +106,7 @@ public class ServletUtils
*/
public static Map<String, String> getParamMap(ServletRequest request)
{
Map<String, String> params = new HashMap<>();
Map<String, String> params = new HashMap<>(16);
for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
{
params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
@ -217,6 +217,7 @@ public class ServletUtils
*
* @param request
*/
public static boolean isAjaxRequest(HttpServletRequest request)
{
String accept = request.getHeader("accept");

View File

@ -405,7 +405,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
{
sb.append(SEPARATOR);
}
else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
else if (i != 0 && !preCharIsUpperCase && curreCharIsUpperCase)
{
sb.append(SEPARATOR);
}
@ -443,6 +443,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String convertToCamelCase(String name)
{
StringBuilder result = new StringBuilder();

View File

@ -11,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile;
*
* @author bonus
*/
public class FileTypeUtils
{
/**
@ -70,6 +71,8 @@ public class FileTypeUtils
* @param photoByte 文件字节码
* @return 后缀不含".")
*/
public static String getFileExtendName(byte[] photoByte)
{
String strFileExtendName = "JPG";

View File

@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
*
* @author bonus
*/
public class FileUtils
{
/** 字符常量:斜杠 {@code '/'} */

View File

@ -7,6 +7,7 @@ import com.bonus.common.core.utils.StringUtils;
*
* @author bonus
*/
public class EscapeUtil
{
public static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
@ -21,11 +22,16 @@ public class EscapeUtil
}
// special HTML characters
TEXT['\''] = "&#039;".toCharArray(); // 单引号
TEXT['"'] = "&#34;".toCharArray(); // 双引号
TEXT['&'] = "&#38;".toCharArray(); // &
TEXT['<'] = "&#60;".toCharArray(); // 小于号
TEXT['>'] = "&#62;".toCharArray(); // 大于号
// 单引号
TEXT['\''] = "&#039;".toCharArray();
// 双引号
TEXT['"'] = "&#34;".toCharArray();
// &
TEXT['&'] = "&#38;".toCharArray();
// 小于号
TEXT['<'] = "&#60;".toCharArray();
// 大于号
TEXT['>'] = "&#62;".toCharArray();
}
/**

View File

@ -15,6 +15,8 @@ import java.util.regex.Pattern;
*
* @author bonus
*/
//@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public final class HTMLFilter
{
/**
@ -45,7 +47,9 @@ public final class HTMLFilter
private static final Pattern P_RIGHT_ARROW = Pattern.compile(">");
private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>");
// @xxx could grow large... maybe use sesat's ReferenceMap
/**
* @xxx could grow large... maybe use sesat's ReferenceMap
*/
private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>();
private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>();
@ -104,28 +108,29 @@ public final class HTMLFilter
{
vAllowed = new HashMap<>();
final ArrayList<String> a_atts = new ArrayList<>();
a_atts.add("href");
a_atts.add("target");
vAllowed.put("a", a_atts);
final ArrayList<String> aAtts = new ArrayList<>();
aAtts.add("href");
aAtts.add("target");
vAllowed.put("a", aAtts);
final ArrayList<String> img_atts = new ArrayList<>();
img_atts.add("src");
img_atts.add("width");
img_atts.add("height");
img_atts.add("alt");
vAllowed.put("img", img_atts);
final ArrayList<String> imgAtts = new ArrayList<>();
imgAtts.add("src");
imgAtts.add("width");
imgAtts.add("height");
imgAtts.add("alt");
vAllowed.put("img", imgAtts);
final ArrayList<String> no_atts = new ArrayList<>();
vAllowed.put("b", no_atts);
vAllowed.put("strong", no_atts);
vAllowed.put("i", no_atts);
vAllowed.put("em", no_atts);
final ArrayList<String> noAtts = new ArrayList<>();
vAllowed.put("b", noAtts);
vAllowed.put("strong", noAtts);
vAllowed.put("i", noAtts);
vAllowed.put("em", noAtts);
vSelfClosingTags = new String[] { "img" };
vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" };
vDisallowed = new String[] {};
vAllowedProtocols = new String[] { "http", "mailto", "https" }; // no ftp.
// no ftp.
vAllowedProtocols = new String[] { "http", "mailto", "https" };
vProtocolAtts = new String[] { "src", "href" };
vRemoveBlanks = new String[] { "a", "b", "strong", "i", "em" };
vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" };
@ -170,8 +175,11 @@ public final class HTMLFilter
vTagCounts.clear();
}
// ---------------------------------------------------------------
// my versions of some PHP library functions
/**
* my versions of some PHP library functions
*
* @param decimal 十进制的整数
*/
public static String chr(final int decimal)
{
return String.valueOf((char) decimal);
@ -229,7 +237,8 @@ public final class HTMLFilter
final StringBuffer buf = new StringBuffer();
if (m.find())
{
final String match = m.group(1); // (.*?)
// (.*?)
final String match = m.group(1);
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
}
m.appendTail(buf);
@ -237,6 +246,7 @@ public final class HTMLFilter
return buf.toString();
}
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
private String balanceHTML(String s)
{
if (alwaysMakeTags)
@ -317,9 +327,9 @@ public final class HTMLFilter
return result;
}
private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s)
private static String regexReplace(final Pattern regexPattern, final String replacement, final String s)
{
Matcher m = regex_pattern.matcher(s);
Matcher m = regexPattern.matcher(s);
return m.replaceAll(replacement);
}
@ -362,13 +372,17 @@ public final class HTMLFilter
final List<String> paramValues = new ArrayList<>();
while (m2.find())
{
paramNames.add(m2.group(1)); // ([a-z0-9]+)
paramValues.add(m2.group(3)); // (.*?)
// ([a-z0-9]+)
paramNames.add(m2.group(1));
// (.*?)
paramValues.add(m2.group(3));
}
while (m3.find())
{
paramNames.add(m3.group(1)); // ([a-z0-9]+)
paramValues.add(m3.group(3)); // ([^\"\\s']+)
// ([a-z0-9]+)
paramNames.add(m3.group(1));
// ([^\"\\s']+)
paramValues.add(m3.group(3));
}
String paramName, paramValue;
@ -377,10 +391,6 @@ public final class HTMLFilter
paramName = paramNames.get(ii).toLowerCase();
paramValue = paramValues.get(ii);
// debug( "paramName='" + paramName + "'" );
// debug( "paramValue='" + paramValue + "'" );
// debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
if (allowedAttribute(name, paramName))
{
if (inArray(paramName, vProtocolAtts))
@ -503,8 +513,10 @@ public final class HTMLFilter
Matcher m = P_VALID_ENTITIES.matcher(s);
while (m.find())
{
final String one = m.group(1); // ([^&;]*)
final String two = m.group(2); // (?=(;|&|$))
// ([^&;]*)
final String one = m.group(1);
// (?=(;|&|$))
final String two = m.group(2);
m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two)));
}
m.appendTail(buf);
@ -520,9 +532,12 @@ public final class HTMLFilter
Matcher m = P_VALID_QUOTES.matcher(s);
while (m.find())
{
final String one = m.group(1); // (>|^)
final String two = m.group(2); // ([^<]+?)
final String three = m.group(3); // (<|$)
// (>|^)
final String one = m.group(1);
// ([^<]+?)
final String two = m.group(2);
// (<|$)
final String three = m.group(3);
// 不替换双引号为&quot;防止json格式无效 regexReplace(P_QUOTE, "&quot;", two)
m.appendReplacement(buf, Matcher.quoteReplacement(one + two + three));
}

View File

@ -11,13 +11,18 @@ import com.bonus.common.core.utils.StringUtils;
*
* @author bonus
*/
public class IpUtils
{
public final static String REGX_0_255 = "(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]\\d|\\d)";
// 匹配 ip
/**
* 匹配 ip
*/
public final static String REGX_IP = "((" + REGX_0_255 + "\\.){3}" + REGX_0_255 + ")";
public final static String REGX_IP_WILDCARD = "(((\\*\\.){3}\\*)|(" + REGX_0_255 + "(\\.\\*){3})|(" + REGX_0_255 + "\\." + REGX_0_255 + ")(\\.\\*){2}" + "|((" + REGX_0_255 + "\\.){3}\\*))";
// 匹配网段
/**
* 匹配网段
*/
public final static String REGX_IP_SEG = "(" + REGX_IP + "\\-" + REGX_IP + ")";
/**
@ -86,6 +91,7 @@ public class IpUtils
* @param addr byte地址
* @return 结果
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
private static boolean internalIp(byte[] addr)
{
if (StringUtils.isNull(addr) || addr.length < 2)
@ -95,13 +101,19 @@ public class IpUtils
final byte b0 = addr[0];
final byte b1 = addr[1];
// 10.x.x.x/8
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
final byte SECTION_1 = 0x0A;
// 172.16.x.x/12
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
final byte SECTION_2 = (byte) 0xAC;
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
final byte SECTION_3 = (byte) 0x10;
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
final byte SECTION_4 = (byte) 0x1F;
// 192.168.x.x/16
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
final byte SECTION_5 = (byte) 0xC0;
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
final byte SECTION_6 = (byte) 0xA8;
switch (b0)
{
@ -117,6 +129,8 @@ public class IpUtils
{
case SECTION_6:
return true;
default:
return false;
}
default:
return false;
@ -283,6 +297,7 @@ public class IpUtils
/**
* 是否为IP
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static boolean isIP(String ip)
{
return StringUtils.isNotBlank(ip) && ip.matches(REGX_IP);
@ -304,7 +319,7 @@ public class IpUtils
String[] s1 = ipWildCard.split("\\.");
String[] s2 = ip.split("\\.");
boolean isMatchedSeg = true;
for (int i = 0; i < s1.length && !s1[i].equals("*"); i++)
for (int i = 0; i < s1.length && !"*".equals(s1[i]); i++)
{
if (!s1[i].equals(s2[i]))
{
@ -318,6 +333,7 @@ public class IpUtils
/**
* 是否为特定格式如:10.10.10.1-10.10.10.99的ip段字符串
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static boolean isIPSegment(String ipSeg)
{
return StringUtils.isNotBlank(ipSeg) && ipSeg.matches(REGX_IP_SEG);

View File

@ -69,6 +69,7 @@ import com.bonus.common.core.utils.reflect.ReflectUtils;
*
* @author bonus
*/
public class ExcelUtil<T>
{
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
@ -80,7 +81,7 @@ public class ExcelUtil<T>
/**
* Excel sheet最大行数默认65536
*/
public static final int sheetSize = 65536;
public static final int SHEETSIZE = 65536;
/**
* 工作表名称
@ -522,7 +523,7 @@ public class ExcelUtil<T>
public void writeSheet()
{
// 取出一共有多少个sheet.
int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize));
int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / SHEETSIZE));
for (int index = 0; index < sheetNo; index++)
{
createSheet(sheetNo, index);
@ -565,8 +566,8 @@ public class ExcelUtil<T>
@SuppressWarnings("unchecked")
public void fillExcelData(int index, Row row)
{
int startNo = index * sheetSize;
int endNo = Math.min(startNo + sheetSize, list.size());
int startNo = index * SHEETSIZE;
int endNo = Math.min(startNo + SHEETSIZE, list.size());
int rowNo = (1 + rownum) - startNo;
for (int i = startNo; i < endNo; i++)
{
@ -1019,10 +1020,12 @@ public class ExcelUtil<T>
* @param firstCol 开始列
* @param endCol 结束列
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public void setXSSFValidationWithHidden(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, int firstCol, int endCol)
{
String hideSheetName = "combo_" + firstCol + "_" + endCol;
Sheet hideSheet = wb.createSheet(hideSheetName); // 用于存储 下拉菜单数据
// 用于存储 下拉菜单数据
Sheet hideSheet = wb.createSheet(hideSheetName);
for (int i = 0; i < textlist.length; i++)
{
hideSheet.createRow(i).createCell(0).setCellValue(textlist[i]);
@ -1380,7 +1383,8 @@ public class ExcelUtil<T>
val = cell.getNumericCellValue();
if (DateUtil.isCellDateFormatted(cell))
{
val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换
// POI Excel 日期格式转换
val = DateUtil.getJavaDate((Double) val);
}
else
{

View File

@ -20,7 +20,7 @@ import com.bonus.common.core.utils.DateUtils;
*
* @author bonus
*/
@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes","all"})
public class ReflectUtils
{
private static final String SETTER_PREFIX = "set";
@ -35,7 +35,7 @@ public class ReflectUtils
* 调用Getter方法.
* 支持多级对象名.对象名.方法
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"all","unchecked"})
public static <E> E invokeGetter(Object obj, String propertyName)
{
Object object = obj;
@ -102,7 +102,6 @@ public class ReflectUtils
Field field = getAccessibleField(obj, fieldName);
if (field == null)
{
// throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
return;
}

View File

@ -5,6 +5,7 @@ package com.bonus.common.core.utils.sign;
*
* @author bonus
*/
public final class Base64
{
static private final int BASELENGTH = 128;
@ -15,48 +16,48 @@ public final class Base64
static private final int FOURBYTE = 4;
static private final int SIGN = -128;
static private final char PAD = '=';
static final private byte[] base64Alphabet = new byte[BASELENGTH];
static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH];
static final private byte[] BASE64ALPHABET = new byte[BASELENGTH];
static final private char[] LOOKUPBASE64ALPHABET = new char[LOOKUPLENGTH];
static
{
for (int i = 0; i < BASELENGTH; ++i)
{
base64Alphabet[i] = -1;
BASE64ALPHABET[i] = -1;
}
for (int i = 'Z'; i >= 'A'; i--)
{
base64Alphabet[i] = (byte) (i - 'A');
BASE64ALPHABET[i] = (byte) (i - 'A');
}
for (int i = 'z'; i >= 'a'; i--)
{
base64Alphabet[i] = (byte) (i - 'a' + 26);
BASE64ALPHABET[i] = (byte) (i - 'a' + 26);
}
for (int i = '9'; i >= '0'; i--)
{
base64Alphabet[i] = (byte) (i - '0' + 52);
BASE64ALPHABET[i] = (byte) (i - '0' + 52);
}
base64Alphabet['+'] = 62;
base64Alphabet['/'] = 63;
BASE64ALPHABET['+'] = 62;
BASE64ALPHABET['/'] = 63;
for (int i = 0; i <= 25; i++)
{
lookUpBase64Alphabet[i] = (char) ('A' + i);
LOOKUPBASE64ALPHABET[i] = (char) ('A' + i);
}
for (int i = 26, j = 0; i <= 51; i++, j++)
{
lookUpBase64Alphabet[i] = (char) ('a' + j);
LOOKUPBASE64ALPHABET[i] = (char) ('a' + j);
}
for (int i = 52, j = 0; i <= 61; i++, j++)
{
lookUpBase64Alphabet[i] = (char) ('0' + j);
LOOKUPBASE64ALPHABET[i] = (char) ('0' + j);
}
lookUpBase64Alphabet[62] = (char) '+';
lookUpBase64Alphabet[63] = (char) '/';
LOOKUPBASE64ALPHABET[62] = (char) '+';
LOOKUPBASE64ALPHABET[63] = (char) '/';
}
private static boolean isWhiteSpace(char octect)
@ -71,7 +72,7 @@ public final class Base64
private static boolean isData(char octect)
{
return (octect < BASELENGTH && base64Alphabet[octect] != -1);
return (octect < BASELENGTH && BASE64ALPHABET[octect] != -1);
}
/**
@ -96,7 +97,7 @@ public final class Base64
int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP;
int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP;
int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets;
char encodedData[] = null;
char []encodedData = null;
encodedData = new char[numberQuartet * 4];
@ -118,10 +119,10 @@ public final class Base64
byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3];
encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[val1];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[val2 | (k << 4)];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[(l << 2) | val3];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[b3 & 0x3f];
}
// form integral number of 6-bit groups
@ -130,8 +131,8 @@ public final class Base64
b1 = binaryData[dataIndex];
k = (byte) (b1 & 0x03);
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[val1];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[k << 4];
encodedData[encodedIndex++] = PAD;
encodedData[encodedIndex++] = PAD;
}
@ -145,9 +146,9 @@ public final class Base64
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[val1];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[val2 | (k << 4)];
encodedData[encodedIndex++] = LOOKUPBASE64ALPHABET[l << 2];
encodedData[encodedIndex++] = PAD;
}
return new String(encodedData);
@ -172,7 +173,8 @@ public final class Base64
if (len % FOURBYTE != 0)
{
return null;// should be divisible by four
// should be divisible by four
return null;
}
int numberQuadruple = (len / FOURBYTE);
@ -182,7 +184,7 @@ public final class Base64
return new byte[0];
}
byte decodedData[] = null;
byte []decodedData = null;
byte b1 = 0, b2 = 0, b3 = 0, b4 = 0;
char d1 = 0, d2 = 0, d3 = 0, d4 = 0;
@ -200,10 +202,10 @@ public final class Base64
return null;
} // if found "no data" just return null
b1 = base64Alphabet[d1];
b2 = base64Alphabet[d2];
b3 = base64Alphabet[d3];
b4 = base64Alphabet[d4];
b1 = BASE64ALPHABET[d1];
b2 = BASE64ALPHABET[d2];
b3 = BASE64ALPHABET[d3];
b4 = BASE64ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
@ -212,11 +214,12 @@ public final class Base64
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])))
{
return null;// if found "no data" just return null
// if found "no data" just return null
return null;
}
b1 = base64Alphabet[d1];
b2 = base64Alphabet[d2];
b1 = BASE64ALPHABET[d1];
b2 = BASE64ALPHABET[d2];
d3 = base64Data[dataIndex++];
d4 = base64Data[dataIndex++];
@ -224,7 +227,8 @@ public final class Base64
{// Check if they are PAD characters
if (isPad(d3) && isPad(d4))
{
if ((b2 & 0xf) != 0)// last 4 bits should be zero
// last 4 bits should be zero
if ((b2 & 0xf) != 0)
{
return null;
}
@ -235,8 +239,9 @@ public final class Base64
}
else if (!isPad(d3) && isPad(d4))
{
b3 = base64Alphabet[d3];
if ((b3 & 0x3) != 0)// last 2 bits should be zero
b3 = BASE64ALPHABET[d3];
// last 2 bits should be zero
if ((b3 & 0x3) != 0)
{
return null;
}
@ -253,8 +258,8 @@ public final class Base64
}
else
{ // No PAD e.g 3cQl
b3 = base64Alphabet[d3];
b4 = base64Alphabet[d4];
b3 = BASE64ALPHABET[d3];
b4 = BASE64ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);

View File

@ -12,6 +12,7 @@ public class IdUtils
*
* @return 随机UUID
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String randomUUID()
{
return UUID.randomUUID().toString();
@ -22,6 +23,7 @@ public class IdUtils
*
* @return 简化的UUID去掉了横线
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String simpleUUID()
{
return UUID.randomUUID().toString(true);
@ -33,6 +35,7 @@ public class IdUtils
*
* @return 简化的UUID去掉了横线 转大写
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String simpleUUIDUp()
{
return UUID.randomUUID().toString(true).toUpperCase();
@ -43,6 +46,7 @@ public class IdUtils
*
* @return 随机UUID
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String fastUUID()
{
return UUID.fastUUID().toString();
@ -53,6 +57,7 @@ public class IdUtils
*
* @return 简化的UUID去掉了横线
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static String fastSimpleUUID()
{
return UUID.fastUUID().toString(true);

View File

@ -9,20 +9,30 @@ import com.bonus.common.core.utils.StringUtils;
*/
public class Seq
{
// 通用序列类型
public static final String commSeqType = "COMMON";
/**
* 通用序列类型
*/
public static final String COMMSEQTYPE = "COMMON";
// 上传序列类型
public static final String uploadSeqType = "UPLOAD";
/**
* 上传序列类型
*/
public static final String UPLOADSEQTYPE = "UPLOAD";
// 通用接口序列数
/**
* 通用接口序列数
*/
private static AtomicInteger commSeq = new AtomicInteger(1);
// 上传接口序列数
/**
* 上传接口序列数
*/
private static AtomicInteger uploadSeq = new AtomicInteger(1);
// 机器标识
private static final String machineCode = "A";
/**
* 机器标识
*/
private static final String MACHINECODE = "A";
/**
* 获取通用序列号
@ -31,7 +41,7 @@ public class Seq
*/
public static String getId()
{
return getId(commSeqType);
return getId(COMMSEQTYPE);
}
/**
@ -42,7 +52,7 @@ public class Seq
public static String getId(String type)
{
AtomicInteger atomicInt = commSeq;
if (uploadSeqType.equals(type))
if (UPLOADSEQTYPE.equals(type))
{
atomicInt = uploadSeq;
}
@ -59,7 +69,7 @@ public class Seq
public static String getId(AtomicInteger atomicInt, int length)
{
String result = DateUtils.dateTimeNow();
result += machineCode;
result += MACHINECODE;
result += getSeq(atomicInt, length);
return result;
}

View File

@ -12,6 +12,7 @@ import com.bonus.common.core.exception.UtilException;
*
* @author bonus
*/
public final class UUID implements java.io.Serializable, Comparable<UUID>
{
private static final long serialVersionUID = -1185015143654744140L;
@ -22,7 +23,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*/
private static class Holder
{
static final SecureRandom numberGenerator = getSecureRandom();
static final SecureRandom NUMBERGENERATOR = getSecureRandom();
}
/** 此UUID的最高64有效位 */
@ -70,6 +71,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return 随机生成的 {@code UUID}
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static UUID fastUUID()
{
return randomUUID(false);
@ -80,6 +82,8 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return 随机生成的 {@code UUID}
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static UUID randomUUID()
{
return randomUUID(true);
@ -91,16 +95,21 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @param isSecure 是否使用{@link SecureRandom}如果是可以获得更安全的随机码否则可以得到更好的性能
* @return 随机生成的 {@code UUID}
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static UUID randomUUID(boolean isSecure)
{
final Random ng = isSecure ? Holder.numberGenerator : getRandom();
final Random ng = isSecure ? Holder.NUMBERGENERATOR : getRandom();
byte[] randomBytes = new byte[16];
ng.nextBytes(randomBytes);
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */
randomBytes[8] &= 0x3f; /* clear variant */
randomBytes[8] |= 0x80; /* set to IETF variant */
/* clear version */
randomBytes[6] &= 0x0f;
/* set to version 4 */
randomBytes[6] |= 0x40;
/* clear variant */
randomBytes[8] &= 0x3f;
/* set to IETF variant */
randomBytes[8] |= 0x80;
return new UUID(randomBytes);
}
@ -111,6 +120,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
*
* @return 根据指定数组生成的 {@code UUID}
*/
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public static UUID nameUUIDFromBytes(byte[] name)
{
MessageDigest md;
@ -123,10 +133,14 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
throw new InternalError("MD5 not supported");
}
byte[] md5Bytes = md.digest(name);
md5Bytes[6] &= 0x0f; /* clear version */
md5Bytes[6] |= 0x30; /* set to version 3 */
md5Bytes[8] &= 0x3f; /* clear variant */
md5Bytes[8] |= 0x80; /* set to IETF variant */
/* clear version */
md5Bytes[6] &= 0x0f;
/* set to version 3 */
md5Bytes[6] |= 0x30;
/* clear variant */
md5Bytes[8] &= 0x3f;
/* set to IETF variant */
md5Bytes[8] |= 0x80;
return new UUID(md5Bytes);
}

View File

@ -106,7 +106,7 @@ public class BaseEntity implements Serializable
{
if (params == null)
{
params = new HashMap<>();
params = new HashMap<>(16);
}
return params;
}

View File

@ -7,6 +7,7 @@ import com.bonus.common.core.utils.StringUtils;
*
* @author bonus
*/
public class PageDomain
{
/** 当前记录起始索引 */

View File

@ -2,7 +2,6 @@ package com.bonus.common.core.web.page;
import com.bonus.common.core.text.Convert;
import com.bonus.common.core.utils.ServletUtils;
//import org.jetbrains.annotations.NotNull;
/**
* 表格数据处理

View File

@ -0,0 +1,32 @@
package com.bonus.common.core.utils.ip;
//import com.alibaba.nacos.common.JustForTest;
//import com.bonus.common.core.utils.ServletUtils;
//import com.bonus.common.core.utils.StringUtils;
//
//import javax.servlet.http.HttpServletRequest;
//import java.net.InetAddress;
//import java.net.UnknownHostException;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* 获取IP方法
*
* @author bonus
*/
public class IpUtilsTests
{
@Test
public void testIpIsInWildCardNoCheck(){
assertTrue(IpUtils.ipIsInWildCardNoCheck("192.168.1.*", "192.168.1.100"));
assertTrue(IpUtils.ipIsInWildCardNoCheck("192.168.*.*", "192.168.1.100"));
assertFalse(IpUtils.ipIsInWildCardNoCheck("192.168.1.*", "192.168.2.100"));
}
@Test
public void testInternalIp(){
assertTrue(IpUtils.internalIp("192.168.1.100"));
assertFalse(IpUtils.internalIp("12.213.54.34"));
}
}

View File

@ -109,7 +109,6 @@ public class LogAspect
sysLogsVo.setFailureReason("操作成功");
}
//操作模块及路径
// sysLogsVo.setTitle(controllerLog.title());
sysLogsVo.setModel(controllerLog.module());
sysLogsVo.setOperaType(controllerLog.businessType());
sysLogsVo.setLogType(controllerLog.logType());
@ -133,7 +132,7 @@ public class LogAspect
sysLogsVo.setOperaUserName(username);
}
Long userId = SecurityUtils.getUserId();
if (userId!=null && userId!=0l) {
if (userId!=null && userId!=0L) {
sysLogsVo.setUserId(userId.toString());
}
sysLogsVo.setOperaUri(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
@ -166,11 +165,8 @@ public class LogAspect
public void getControllerMethodDescription(JoinPoint joinPoint, SysLog log, SysLogsVo sysLogsVo, Object jsonResult) throws Exception
{
// 设置action动作
//. operLog.setBusinessType(log.businessType().ordinal());
// 设置标题
sysLogsVo.setTitle(log.title());
// 设置操作人类别
// operLog.setOperatorType(log.operatorType().ordinal());
// 是否需要保存request参数和值
if (log.isSaveRequestData())
{
@ -194,8 +190,8 @@ public class LogAspect
{
String requestMethod = operLog.getMethod();
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
if (StringUtils.isEmpty(paramsMap)
&& (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)))
boolean bResult = HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod);
if (StringUtils.isEmpty(paramsMap) && bResult)
{
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
operLog.setParams(StringUtils.substring(params, 0, 2000));

View File

@ -13,6 +13,9 @@ import org.springframework.scheduling.annotation.EnableAsync;
import com.bonus.common.security.config.ApplicationConfig;
import com.bonus.common.security.feign.FeignAutoConfiguration;
/**
* @author bonus
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented

View File

@ -33,7 +33,8 @@ public class InnerAuthAspect implements Ordered
String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID);
String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME);
// 用户信息验证
if (innerAuth.isUser() && (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)))
boolean bResult = StringUtils.isEmpty(userid) || StringUtils.isEmpty(username);
if (innerAuth.isUser() && bResult)
{
throw new InnerAuthException("没有设置用户信息,不允许访问 ");
}

View File

@ -19,6 +19,9 @@ import java.io.IOException;
import static cn.hutool.http.Method.POST;
import static jdk.nashorn.internal.runtime.PropertyDescriptor.GET;
/**
* @author bonus
*/
@Component
@WebFilter("/*")
public class MyFilter extends OncePerRequestFilter {

View File

@ -14,19 +14,19 @@ import com.bonus.common.security.interceptor.HeaderInterceptor;
public class WebMvcConfig implements WebMvcConfigurer
{
/** 不需要拦截地址 "/logout",*/
public static final String[] excludeUrls = { "/login", "/refresh" };
public static final String[] EXCLUDEURLS = { "/login", "/refresh" };
@Override
public void addInterceptors(InterceptorRegistry registry)
{
registry.addInterceptor(getHeaderInterceptor())
.addPathPatterns("/**")
.excludePathPatterns(excludeUrls)
.excludePathPatterns(EXCLUDEURLS)
.order(-10);
//自定义拦截器
registry.addInterceptor(getParamSecureInterceptor())
.addPathPatterns("/**")
.excludePathPatterns(excludeUrls)
.excludePathPatterns(EXCLUDEURLS)
.order(-10);
}

View File

@ -38,8 +38,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(NotPermissionException.class)
public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
String requestUri = request.getRequestURI();
log.error("请求地址'{}',权限码校验失败'{}'", requestUri, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
}
@ -49,8 +49,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(NotRoleException.class)
public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
String requestUri = request.getRequestURI();
log.error("请求地址'{}',角色权限校验失败'{}'", requestUri, e.getMessage());
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
}
@ -60,8 +60,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
String requestUri = request.getRequestURI();
log.error("请求地址'{}',不支持'{}'请求", requestUri, e.getMethod());
return AjaxResult.error(e.getMessage());
}
@ -82,8 +82,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(MissingPathVariableException.class)
public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
String requestUri = request.getRequestURI();
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestUri, e);
return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
}
@ -93,8 +93,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
String requestUri = request.getRequestURI();
log.error("请求参数类型不匹配'{}',发生系统异常.", requestUri, e);
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
}
@ -124,8 +124,8 @@ public class GlobalExceptionHandler
@ExceptionHandler(Exception.class)
public AjaxResult handleException(Exception e, HttpServletRequest request)
{
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e);
String requestUri = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestUri, e);
return AjaxResult.error(e.getMessage());
}

View File

@ -33,6 +33,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
@Slf4j
public class ParamSecureHandler implements AsyncHandlerInterceptor {
private static String OPERLOG_URL = "/operlog/addLogs";
private String rnd = null;
public static String ur="/";
@ -59,10 +60,9 @@ public class ParamSecureHandler implements AsyncHandlerInterceptor {
return true;
}
XssRequestWrapper requestWrapper = new XssRequestWrapper(request);
String requestUrl = requestWrapper.getRequestURI();
if("/operlog/addLogs".equals(requestUrl)){
if(OPERLOG_URL.equals(requestUrl)){
return true;
}
/**

View File

@ -36,7 +36,7 @@ public class TokenService
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
private final static long expireTime = CacheConstants.EXPIRATION;
private final static long EXPIRETIME = CacheConstants.EXPIRATION;
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
@ -57,17 +57,17 @@ public class TokenService
refreshToken(loginUser);
// Jwt存储信息
Map<String, Object> claimsMap = new HashMap<String, Object>();
Map<String, Object> claimsMap = new HashMap<String, Object>(16);
claimsMap.put(SecurityConstants.USER_KEY, token);
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
String accessToken= JwtUtils.createToken(claimsMap);
Map<String, Object> rspMap = new HashMap<String, Object>();
Map<String, Object> rspMap = new HashMap<String, Object>(16);
rspMap.put("access_token", accessToken);
rspMap.put("expires_in", expireTime);
rspMap.put("expires_in", EXPIRETIME);
//对token和 进行混粗糙你存储
redisService.setCacheObject(userName+":"+accessToken,userName, 120l, TimeUnit.MINUTES);
redisService.setCacheObject(userId+":"+accessToken,userId.toString(), 120l, TimeUnit.MINUTES);
redisService.setCacheObject(userName+":"+accessToken,userName, 120L, TimeUnit.MINUTES);
redisService.setCacheObject(userId+":"+accessToken,userId.toString(), 120L, TimeUnit.MINUTES);
return rspMap;
}
@ -163,10 +163,10 @@ public class TokenService
public void refreshToken(LoginUser loginUser)
{
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
loginUser.setExpireTime(loginUser.getLoginTime() + EXPIRETIME * MILLIS_MINUTE);
// 根据uuid将loginUser缓存
String userKey = getTokenKey(loginUser.getToken());
redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
redisService.setCacheObject(userKey, loginUser, EXPIRETIME, TimeUnit.MINUTES);
}
private String getTokenKey(String token)

View File

@ -15,6 +15,9 @@ import javax.servlet.http.HttpServletResponse;
import java.util.Collection;
import java.util.Map;
/**
* @author bonus
*/
public class LogsUtils {
/**
* 获取请求的参数放到log中
@ -25,8 +28,8 @@ public class LogsUtils {
public static void setRequestValue(ProceedingJoinPoint joinPoint, SysLogsVo operLog, String[] excludeParamNames) throws Exception {
String requestMethod = operLog.getMethod();
Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
if (StringUtils.isEmpty(paramsMap)
&& (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)))
boolean bResult = HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod);
if (StringUtils.isEmpty(paramsMap) && bResult)
{
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
operLog.setParams(StringUtils.substring(params, 0, 2000));

View File

@ -1,5 +1,6 @@
package com.bonus.common.sensitive.utils;
import com.bonus.common.core.constant.CacheConstants;
import com.bonus.common.core.utils.StringUtils;
/**
@ -9,6 +10,8 @@ import com.bonus.common.core.utils.StringUtils;
*/
public class DesensitizedUtil
{
private final static long OLD_CARLICENSE_LENGHT = 7;
private final static long NEW_CARLICENSE_LENGHT = 8;
/**
* 密码的全部字符都用*代替比如******
*
@ -37,11 +40,11 @@ public class DesensitizedUtil
return StringUtils.EMPTY;
}
// 普通车牌
if (carLicense.length() == 7)
if (carLicense.length() == OLD_CARLICENSE_LENGHT)
{
carLicense = StringUtils.hide(carLicense, 3, 6);
}
else if (carLicense.length() == 8)
else if (carLicense.length() == NEW_CARLICENSE_LENGHT)
{
// 新能源车牌
carLicense = StringUtils.hide(carLicense, 3, 7);

View File

@ -9,6 +9,9 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
import com.bonus.common.swagger.config.SwaggerAutoConfiguration;
/**
* @author bonus
*/
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented

View File

@ -24,6 +24,9 @@ import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @author bonus
*/
@Configuration
@EnableSwagger2
@EnableConfigurationProperties(SwaggerProperties.class)

View File

@ -4,6 +4,9 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author bonus
*/
@ConfigurationProperties("swagger")
public class SwaggerProperties
{

View File

@ -29,7 +29,9 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
/**
* 参数自动解密
* 拦截
* * @author bonus
*/
@Slf4j
@Component
public class AecDecryptParamFilter extends AbstractGatewayFilterFactory {

View File

@ -37,7 +37,9 @@ public class AuthFilter implements GlobalFilter, Ordered
public boolean jaData;
private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
// 排除过滤的 uri 地址nacos自行添加
/**
* 排除过滤的 uri 地址nacos自行添加
*/
@Autowired
private IgnoreWhiteProperties ignoreWhite;
@ -90,8 +92,8 @@ public class AuthFilter implements GlobalFilter, Ordered
if (StringUtils.isEmpty(id) || !id.equals(userId)) {
return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
}
redisService.setCacheObject(userName+":"+token,userName, 120l, TimeUnit.MINUTES);
redisService.setCacheObject(userId+":"+token,userId+"", 120l, TimeUnit.MINUTES);
redisService.setCacheObject(userName+":"+token,userName, 120L, TimeUnit.MINUTES);
redisService.setCacheObject(userId+":"+token,userId+"", 120L, TimeUnit.MINUTES);
}catch (Exception e){
return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
}

View File

@ -42,7 +42,9 @@ import java.util.Map;
*请求内容存储 处理请求内容 内容放在gatewayContext中
* 解决数据流被重复读取无数据的 问题
* 对formData 数据进行解密
* @author bonus
*/
@Component
@Slf4j
public class RequestCoverFilter implements GlobalFilter, Ordered {
@ -181,8 +183,8 @@ public class RequestCoverFilter implements GlobalFilter, Ordered {
/**
* ReadJsonBody
*
* @param exchange
* @param chain
* @param exchange 操作的http请求数据
* @param chain 网关过滤器链表
* @return
*/
private Mono<Void> readBody(ServerWebExchange exchange, GatewayFilterChain chain, GatewayContext gatewayContext) {

View File

@ -103,6 +103,7 @@ public class ResponseEncryptFilter implements GlobalFilter, Ordered {
public int getOrder() {
return -5;
}
@SuppressWarnings("deprecation")
private ServerHttpResponseDecorator buildResponse(ServerHttpResponse originalResponse, DataBufferFactory bufferFactory) {
return new ServerHttpResponseDecorator(originalResponse) {
@Override

View File

@ -34,7 +34,9 @@ import reactor.core.publisher.Mono;
@ConditionalOnProperty(value = "security.xss.enabled", havingValue = "true")
public class XssFilter implements GlobalFilter, Ordered
{
// 跨站脚本的 xss 配置nacos自行添加
/**
* 跨站脚本的 xss 配置nacos自行添加
*/
@Autowired
private XssProperties xss;

View File

@ -13,7 +13,10 @@ import springfox.documentation.swagger.web.SecurityConfigurationBuilder;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger.web.UiConfigurationBuilder;
/**
* SwaggerHandler
* @author bonus
*/
@RestController
@RequestMapping("/swagger-resources")
public class SwaggerHandler

View File

@ -13,11 +13,17 @@ public interface ValidateCodeService
{
/**
* 生成验证码
* @return AjaxResult
* @throws IOException 输入输出异常
* @throws CaptchaException 自定义captcha 异常
*/
public AjaxResult createCaptcha() throws IOException, CaptchaException;
/**
* 校验验证码
* @param key captcha的key
* @param value captcha的值
* @throws CaptchaException 自定义captcha 异常
*/
public void checkCaptcha(String key, String value) throws CaptchaException;
}

View File

@ -25,6 +25,7 @@ import com.bonus.gateway.service.ValidateCodeService;
*
* @author bonus
*/
@Service
public class ValidateCodeServiceImpl implements ValidateCodeService
{

View File

@ -57,7 +57,7 @@ public class SysFileController
try {
String fileUrl = Base64Utils.decodeUrl(url);
if (fileUrl != null) {
String fileName = Base64Utils.getFileNameFromURL(fileUrl);
String fileName = Base64Utils.getFileNameFromUrl(fileUrl);
sysFileService.downloadFile(fileUrl, destination + "/" + fileName);
return R.ok();
}

View File

@ -11,10 +11,14 @@ import org.apache.commons.net.ftp.FTPClient;
public class FileDownloadUtils {
private final static String HTTP_START_STR = "http://";
private final static String HTTPS_START_STR = "https://";
private final static String FTP_START_STR = "ftp:/";
public static boolean downloadFile(String urlStr, String destination) throws IOException {
if (urlStr.startsWith("http://") || urlStr.startsWith("https://")) {
if (urlStr.startsWith(HTTP_START_STR) || urlStr.startsWith(HTTPS_START_STR)) {
return downloadHttpFile(urlStr, destination);
} else if (urlStr.startsWith("ftp://")) {
} else if (urlStr.startsWith(FTP_START_STR)) {
return downloadFtpFile(urlStr, destination);
} else {
throw new IllegalArgumentException("Unsupported protocol: " + urlStr);

View File

@ -94,7 +94,7 @@ public class FileUploadUtils
public static final String extractFilename(MultipartFile file)
{
return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(),
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), FileTypeUtils.getExtension(file));
FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.UPLOADSEQTYPE), FileTypeUtils.getExtension(file));
}
private static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException

View File

@ -13,7 +13,7 @@ import com.bonus.common.core.web.domain.BaseEntity;
public class GenTableColumn extends BaseEntity
{
private static final long serialVersionUID = 1L;
private static final String BLANK_SPACR = " ";
/** 编号 */
private Long columnId;
@ -355,7 +355,7 @@ public class GenTableColumn extends BaseEntity
StringBuffer sb = new StringBuffer();
if (StringUtils.isNotEmpty(remarks))
{
for (String value : remarks.split(" "))
for (String value : remarks.split(BLANK_SPACR))
{
if (StringUtils.isNotEmpty(value))
{

View File

@ -121,11 +121,11 @@ public class SysOperLogServiceImpl implements ISysOperLogService
sb.append(vo.getMenuName4());
}
if(StringUtils.isNotEmpty(vo.getMenuName3())){
SbAppend(sb);
sbAppend(sb);
sb.append(vo.getMenuName3());
}
if(StringUtils.isNotEmpty(vo.getMenuName2())){
SbAppend(sb);
sbAppend(sb);
sb.append(vo.getMenuName2());
}
if("F".equals(type)){
@ -151,7 +151,7 @@ public class SysOperLogServiceImpl implements ISysOperLogService
maps.put("title",vo.getMenuName2());
}else{
maps.put("bussType",OperaType.QUERY);
SbAppend(sb);
sbAppend(sb);
sb.append(vo.getMenuName());
maps.put("title",vo.getMenuName());
}
@ -171,7 +171,7 @@ public class SysOperLogServiceImpl implements ISysOperLogService
return maps;
}
public void SbAppend(StringBuffer sb){
public void sbAppend(StringBuffer sb){
if(StringUtils.isNotEmpty(sb.toString())){
sb.append("->");
}