optimize jackson's threats

This commit is contained in:
huoyo 2022-05-30 12:54:01 +08:00
parent e20812f17a
commit b4957441a8
12 changed files with 75 additions and 44 deletions

View File

@ -26,7 +26,7 @@
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.16.0</version>
<version>4.0.0-beta.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>

View File

@ -28,7 +28,7 @@ import java.util.logging.Logger;
@ComponentScan("cn.langpy.kotime")
@Configuration
public class LoadConfig {
public static Logger log = Logger.getLogger(LoadConfig.class.toString());
private static Logger log = Logger.getLogger(LoadConfig.class.toString());
@Value("${koTime.enable:true}")
private Boolean kotimeEnable;

View File

@ -34,7 +34,7 @@ public class KoTimeController {
@Value("${ko-time.password:}")
private String password;
public static Logger log = Logger.getLogger(KoTimeController.class.toString());
private static Logger log = Logger.getLogger(KoTimeController.class.toString());
@PostMapping("/login")
@ResponseBody
@ -65,41 +65,48 @@ public class KoTimeController {
@GetMapping
public void index(String test, HttpServletResponse response, HttpServletRequest request) throws Exception {
public void index(String test, HttpServletResponse response, HttpServletRequest request) {
if (null != test) {
return;
}
response.setContentType("text/html;charset=utf-8");
ClassPathResource classPathResource = new ClassPathResource(KoConstant.kotimeViewer);
BufferedReader reader = new BufferedReader(new InputStreamReader(classPathResource.getInputStream(), "utf-8"));
PrintWriter out = response.getWriter();
String context = request.getContextPath();
if (StringUtils.hasText(Context.getConfig().getContextPath())) {
context = Context.getConfig().getContextPath();
}
StringBuilder stringBuilder = new StringBuilder();
String line = "";
int n = 0;
while ((line = reader.readLine()) != null) {
if (n > 14) {
if (line.indexOf(KoConstant.globalThreshold) > -1) {
line = line.replace(KoConstant.globalThreshold, Context.getConfig().getThreshold() + "");
} else if (line.indexOf(KoConstant.globalNeedLogin) > -1) {
line = line.replace(KoConstant.globalNeedLogin, Context.getConfig().getAuthEnable() + "");
} else if (line.indexOf(KoConstant.contextPath) > -1) {
line = line.replace(KoConstant.contextPath, context);
} else if (line.indexOf(KoConstant.exceptionTitleStyle) > -1) {
line = line.replace(KoConstant.exceptionTitleStyle, Context.getConfig().getExceptionEnable() == true ? "" : "display:none;");
}
stringBuilder.append(line + "\n");
} else {
stringBuilder.append(line + "\n");
try (
InputStream inputStream = classPathResource.getInputStream();
InputStreamReader streamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader reader = new BufferedReader(streamReader);
PrintWriter out = response.getWriter()) {
String context = request.getContextPath();
if (StringUtils.hasText(Context.getConfig().getContextPath())) {
context = Context.getConfig().getContextPath();
}
n++;
StringBuilder stringBuilder = new StringBuilder();
String line = "";
int n = 0;
while ((line = reader.readLine()) != null) {
if (n > 14) {
if (line.indexOf(KoConstant.globalThreshold) > -1) {
line = line.replace(KoConstant.globalThreshold, Context.getConfig().getThreshold() + "");
} else if (line.indexOf(KoConstant.globalNeedLogin) > -1) {
line = line.replace(KoConstant.globalNeedLogin, Context.getConfig().getAuthEnable() + "");
} else if (line.indexOf(KoConstant.contextPath) > -1) {
line = line.replace(KoConstant.contextPath, context);
} else if (line.indexOf(KoConstant.exceptionTitleStyle) > -1) {
line = line.replace(KoConstant.exceptionTitleStyle, Context.getConfig().getExceptionEnable() == true ? "" : "display:none;");
}
stringBuilder.append(line + "\n");
} else {
stringBuilder.append(line + "\n");
}
n++;
}
line = stringBuilder.toString();
out.write(line);
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
line = stringBuilder.toString();
out.write(line);
out.close();
}

View File

@ -15,7 +15,6 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList;
@ -25,7 +24,7 @@ import static java.util.stream.Collectors.toList;
@Component("database")
@Lazy
public class DataBase implements GraphService {
public static Logger log = Logger.getLogger(DataBase.class.toString());
private static Logger log = Logger.getLogger(DataBase.class.toString());
private Connection readConnection;
private Connection writeConnection;

View File

@ -25,7 +25,7 @@ import java.util.logging.Logger;
@Aspect
@Component
public class AuthHandler {
public static Logger log = Logger.getLogger(AuthHandler.class.toString());
private static Logger log = Logger.getLogger(AuthHandler.class.toString());
@Pointcut(KoConstant.authRange)
public void preProcess() {

View File

@ -16,7 +16,7 @@ import java.util.logging.Logger;
@Aspect
@Component
public class ComputeTimeHandler {
public static Logger log = Logger.getLogger(ComputeTimeHandler.class.toString());
private static Logger log = Logger.getLogger(ComputeTimeHandler.class.toString());
@Pointcut(KoConstant.comMethodRange)
public void preProcess() {

View File

@ -8,7 +8,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Logger;
public class InvokedQueue {
public static Logger log = Logger.getLogger(InvokedQueue.class.toString());
private static Logger log = Logger.getLogger(InvokedQueue.class.toString());
private volatile static ConcurrentLinkedQueue<InvokedInfo> queue = new ConcurrentLinkedQueue();

View File

@ -12,7 +12,7 @@ import java.util.logging.Logger;
@KoListener
public final class KoInvokedHandler implements InvokedHandler {
public static Logger log = Logger.getLogger(KoInvokedHandler.class.toString());
private static Logger log = Logger.getLogger(KoInvokedHandler.class.toString());
@Override

View File

@ -14,7 +14,7 @@ import java.util.logging.Logger;
* zhangchang
*/
public class MethodNodeService {
public static Logger log = Logger.getLogger(MethodNodeService.class.toString());
private static Logger log = Logger.getLogger(MethodNodeService.class.toString());
public static MethodNode getParentMethodNode() {
Stack<String> stack = MethodStack.get();

View File

@ -24,7 +24,7 @@ import java.util.logging.Logger;
* zhangchang
*/
public class Common {
public static Logger log = Logger.getLogger(Common.class.toString());
private static Logger log = Logger.getLogger(Common.class.toString());
final static List<Class<?>> baseTypes = Arrays.asList(Integer.class, Double.class, Float.class, String.class, Boolean.class, MultipartFile.class);

View File

@ -7,7 +7,6 @@ import cn.langpy.kotime.service.GraphService;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
/**
* zhangchang

View File

@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
public class DataBaseUtil {
public static Logger log = Logger.getLogger(DataBaseUtil.class.toString());
private static Logger log = Logger.getLogger(DataBaseUtil.class.toString());
static Map<String, ColumnInfo> tableInfoMap = new ConcurrentHashMap<>();
@ -82,13 +82,14 @@ public class DataBaseUtil {
public static List<Map<String, Object>> query(Connection connection, String sql, Object[] values) {
List<Map<String, Object>> list = new ArrayList<>();
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
statement = connection.prepareStatement(sql);
if (null != values) {
statement = setParams(statement, values);
}
final ResultSetMetaData metaData = statement.getMetaData();
ResultSet resultSet = statement.executeQuery();
resultSet = statement.executeQuery();
List<ColumnInfo> columns = getColumns(metaData);
while (resultSet.next()) {
Map<String, Object> map = new HashMap<>();
@ -107,16 +108,24 @@ public class DataBaseUtil {
throwables.printStackTrace();
}
}
if (null != resultSet) {
try {
resultSet.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
return list;
}
public static boolean existsById(Connection connection, String sql, Object id) {
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
statement = connection.prepareStatement(sql);
statement = setParams(statement, id);
ResultSet resultSet = statement.executeQuery();
resultSet = statement.executeQuery();
if (resultSet.next()) {
return true;
}
@ -130,6 +139,13 @@ public class DataBaseUtil {
throwables.printStackTrace();
}
}
if (null != resultSet) {
try {
resultSet.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
return false;
}
@ -137,13 +153,14 @@ public class DataBaseUtil {
public static <T> List<T> query(Connection connection, String sql, Object[] values, Class<T> c) {
List<T> list = new ArrayList<>();
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
statement = connection.prepareStatement(sql);
if (null != values) {
statement = setParams(statement, values);
}
final ResultSetMetaData metaData = statement.getMetaData();
ResultSet resultSet = statement.executeQuery();
resultSet = statement.executeQuery();
List<ColumnInfo> columns = getColumns(metaData);
Field[] fields = null;
while (resultSet.next()) {
@ -173,6 +190,7 @@ public class DataBaseUtil {
} else {
field.set(object, columnValue);
}
field.setAccessible(false);
}
list.add(object);
}
@ -190,6 +208,14 @@ public class DataBaseUtil {
throwables.printStackTrace();
}
}
if (null != resultSet) {
try {
resultSet.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
return list;
}