Cached.checkName
This commit is contained in:
@@ -17,6 +17,7 @@ import org.redkale.convert.json.JsonConvert;
|
|||||||
import org.redkale.inject.ResourceFactory;
|
import org.redkale.inject.ResourceFactory;
|
||||||
import org.redkale.util.Environment;
|
import org.redkale.util.Environment;
|
||||||
import org.redkale.util.MultiHashKey;
|
import org.redkale.util.MultiHashKey;
|
||||||
|
import org.redkale.util.RedkaleException;
|
||||||
import org.redkale.util.ThrowSupplier;
|
import org.redkale.util.ThrowSupplier;
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ public class CachedAction {
|
|||||||
|
|
||||||
String init(ResourceFactory resourceFactory, Object service) {
|
String init(ResourceFactory resourceFactory, Object service) {
|
||||||
this.manager = resourceFactory.load(environment.getPropertyValue(cached.getManager()), CachedManager.class);
|
this.manager = resourceFactory.load(environment.getPropertyValue(cached.getManager()), CachedManager.class);
|
||||||
this.name = environment.getPropertyValue(cached.getName());
|
this.name = checkName(environment.getPropertyValue(cached.getName()));
|
||||||
this.key = environment.getPropertyValue(cached.getKey());
|
this.key = environment.getPropertyValue(cached.getKey());
|
||||||
if (key.startsWith("@")) { // 动态加载缓存key生成器
|
if (key.startsWith("@")) { // 动态加载缓存key生成器
|
||||||
String generatorName = key.substring(1);
|
String generatorName = key.substring(1);
|
||||||
@@ -116,6 +117,28 @@ public class CachedAction {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查name是否含特殊字符
|
||||||
|
*
|
||||||
|
* @param value 参数
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
protected String checkName(String value) {
|
||||||
|
if (value != null && !value.isEmpty()) {
|
||||||
|
for (char ch : value.toCharArray()) {
|
||||||
|
if (!((ch >= '0' && ch <= '9')
|
||||||
|
|| (ch >= 'a' && ch <= 'z')
|
||||||
|
|| (ch >= 'A' && ch <= 'Z')
|
||||||
|
|| ch == '-'
|
||||||
|
|| ch == '_'
|
||||||
|
|| ch == '.')) { // 不能含特殊字符: # @
|
||||||
|
throw new RedkaleException("name only contains 0-9 a-z A-Z . - _");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
@ClassDepends
|
@ClassDepends
|
||||||
public <T> T get(ThrowSupplier<T> supplier, Object... args) {
|
public <T> T get(ThrowSupplier<T> supplier, Object... args) {
|
||||||
if (async) {
|
if (async) {
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查name是否含特殊字符
|
* 检查schema是否含特殊字符
|
||||||
*
|
*
|
||||||
* @param value 参数
|
* @param value 参数
|
||||||
* @return value
|
* @return value
|
||||||
@@ -145,8 +145,13 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
|
|||||||
protected String checkSchema(String value) {
|
protected String checkSchema(String value) {
|
||||||
if (value != null && !value.isEmpty()) {
|
if (value != null && !value.isEmpty()) {
|
||||||
for (char ch : value.toCharArray()) {
|
for (char ch : value.toCharArray()) {
|
||||||
if (ch == ':' || ch == '#' || ch == '@') { // 不能含特殊字符
|
if (!((ch >= '0' && ch <= '9')
|
||||||
throw new RedkaleException("schema cannot contains : # @");
|
|| (ch >= 'a' && ch <= 'z')
|
||||||
|
|| (ch >= 'A' && ch <= 'Z')
|
||||||
|
|| ch == '-'
|
||||||
|
|| ch == '_'
|
||||||
|
|| ch == '.')) { // 不能含特殊字符: # @
|
||||||
|
throw new RedkaleException("schema only contains 0-9 a-z A-Z . - _");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user