From 4470052c3b6bdeb18e45987f8aa293d1e93d0552 Mon Sep 17 00:00:00 2001
From: Ludc <2870569285@qq.com>
Date: 星期二, 18 十一月 2025 11:59:12 +0800
Subject: [PATCH] 所有文件上传接口增加文件安全校验逻辑。
---
Source/BladeX-Tool/blade-core-launch/src/main/java/org/springblade/core/launch/props/BladeProperties.java | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 226 insertions(+), 0 deletions(-)
diff --git a/Source/BladeX-Tool/blade-core-launch/src/main/java/org/springblade/core/launch/props/BladeProperties.java b/Source/BladeX-Tool/blade-core-launch/src/main/java/org/springblade/core/launch/props/BladeProperties.java
new file mode 100644
index 0000000..e86860a
--- /dev/null
+++ b/Source/BladeX-Tool/blade-core-launch/src/main/java/org/springblade/core/launch/props/BladeProperties.java
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the dreamlu.net developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: Chill 搴勯獮 (smallchill@163.com)
+ */
+package org.springblade.core.launch.props;
+
+import lombok.Getter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.EnvironmentCapable;
+import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * 閰嶇疆鏂囦欢
+ *
+ * @author Chill
+ */
+@ConfigurationProperties("blade")
+public class BladeProperties implements EnvironmentAware, EnvironmentCapable {
+ @Nullable
+ private Environment environment;
+
+ /**
+ * 瑁呰浇鑷畾涔夐厤缃産lade.prop.xxx
+ */
+ @Getter
+ private final Map<String, String> prop = new HashMap<>();
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @return value
+ */
+ @Nullable
+ public String get(String key) {
+ return get(key, null);
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @param defaultValue 榛樿鍊�
+ * @return value
+ */
+ @Nullable
+ public String get(String key, @Nullable String defaultValue) {
+ String value = prop.get(key);
+ if (value == null) {
+ return defaultValue;
+ }
+ return value;
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @return int value
+ */
+ @Nullable
+ public Integer getInt(String key) {
+ return getInt(key, null);
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @param defaultValue 榛樿鍊�
+ * @return int value
+ */
+ @Nullable
+ public Integer getInt(String key, @Nullable Integer defaultValue) {
+ String value = prop.get(key);
+ if (value != null) {
+ return Integer.valueOf(value.trim());
+ }
+ return defaultValue;
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @return long value
+ */
+ @Nullable
+ public Long getLong(String key) {
+ return getLong(key, null);
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @param defaultValue 榛樿鍊�
+ * @return long value
+ */
+ @Nullable
+ public Long getLong(String key, @Nullable Long defaultValue) {
+ String value = prop.get(key);
+ if (value != null) {
+ return Long.valueOf(value.trim());
+ }
+ return defaultValue;
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @return Boolean value
+ */
+ @Nullable
+ public Boolean getBoolean(String key) {
+ return getBoolean(key, null);
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @param defaultValue 榛樿鍊�
+ * @return Boolean value
+ */
+ @Nullable
+ public Boolean getBoolean(String key, @Nullable Boolean defaultValue) {
+ String value = prop.get(key);
+ if (value != null) {
+ value = value.toLowerCase().trim();
+ return Boolean.parseBoolean(value);
+ }
+ return defaultValue;
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @return double value
+ */
+ @Nullable
+ public Double getDouble(String key) {
+ return getDouble(key, null);
+ }
+
+ /**
+ * 鑾峰彇閰嶇疆
+ *
+ * @param key key
+ * @param defaultValue 榛樿鍊�
+ * @return double value
+ */
+ @Nullable
+ public Double getDouble(String key, @Nullable Double defaultValue) {
+ String value = prop.get(key);
+ if (value != null) {
+ return Double.parseDouble(value.trim());
+ }
+ return defaultValue;
+ }
+
+ /**
+ * 鍒ゆ柇鏄惁瀛樺湪key
+ *
+ * @param key prop key
+ * @return boolean
+ */
+ public boolean containsKey(String key) {
+ return prop.containsKey(key);
+ }
+
+
+ /**
+ * 鐜锛屾柟渚垮湪浠g爜涓幏鍙�
+ *
+ * @return 鐜 env
+ */
+ public String getEnv() {
+ Objects.requireNonNull(environment, "Spring boot 鐜涓� Environment 涓嶅彲鑳戒负null");
+ String env = environment.getProperty("blade.env");
+ Assert.notNull(env, "璇蜂娇鐢� BladeApplication 鍚姩...");
+ return env;
+ }
+
+ /**
+ * 搴旂敤鍚嶇О${spring.application.name}
+ *
+ * @return 搴旂敤鍚�
+ */
+ public String getName() {
+ Objects.requireNonNull(environment, "Spring boot 鐜涓� Environment 涓嶅彲鑳戒负null");
+ return environment.getProperty("spring.application.name", environment.getProperty("blade.name", ""));
+ }
+
+ @Override
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
+ @Override
+ public Environment getEnvironment() {
+ Objects.requireNonNull(environment, "Spring boot 鐜涓� Environment 涓嶅彲鑳戒负null");
+ return this.environment;
+ }
+}
--
Gitblit v1.10.0