mirror of
https://github.com/LamGC/Oracle-Sentry.git
synced 2025-04-29 22:27:34 +00:00
fix: 修复因 Oracle 身份配置内容缺失导致加载失败的问题.
准确来讲该问题并不是很严重, 但还是为此添加了验证步骤以更优雅的告知用户该配置有问题.
This commit is contained in:
parent
541115b9c7
commit
9905f6ce01
@ -1,5 +1,6 @@
|
|||||||
package net.lamgc.oracle.sentry;
|
package net.lamgc.oracle.sentry;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@ -69,6 +70,9 @@ public final class OracleIdentityManager {
|
|||||||
for (File configFile : configFiles) {
|
for (File configFile : configFiles) {
|
||||||
try {
|
try {
|
||||||
AuthenticationDetailsProvider provider = loadFromConfigFile(configFile);
|
AuthenticationDetailsProvider provider = loadFromConfigFile(configFile);
|
||||||
|
if (provider == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
loadedCount ++;
|
loadedCount ++;
|
||||||
log.info("已成功加载身份配置文件.\n\tUserId: {}\n\tUsername: {}\n\tPath: {}",
|
log.info("已成功加载身份配置文件.\n\tUserId: {}\n\tUsername: {}\n\tPath: {}",
|
||||||
provider.getUserId(),
|
provider.getUserId(),
|
||||||
@ -93,6 +97,11 @@ public final class OracleIdentityManager {
|
|||||||
|
|
||||||
ConfigFileReader.ConfigFile config
|
ConfigFileReader.ConfigFile config
|
||||||
= ConfigFileReader.parse(identityConfig.getAbsolutePath());
|
= ConfigFileReader.parse(identityConfig.getAbsolutePath());
|
||||||
|
if (!checkIdentityProfileConfig(config)) {
|
||||||
|
log.warn("该配置文件缺少必要信息, 跳过加载.(Path: {})", identityConfig.getCanonicalPath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
String keyFilePath = config.get("key_file");
|
String keyFilePath = config.get("key_file");
|
||||||
if (keyFilePath.startsWith(".")) {
|
if (keyFilePath.startsWith(".")) {
|
||||||
@ -117,6 +126,23 @@ public final class OracleIdentityManager {
|
|||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkIdentityProfileConfig(ConfigFileReader.ConfigFile config) {
|
||||||
|
String[] fields = new String[] {
|
||||||
|
"key_file",
|
||||||
|
"region",
|
||||||
|
"tenancy",
|
||||||
|
"user",
|
||||||
|
"fingerprint"
|
||||||
|
};
|
||||||
|
for (String field : fields) {
|
||||||
|
if (Strings.isNullOrEmpty(config.get(field))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取身份所属用户的名称.
|
* 获取身份所属用户的名称.
|
||||||
* @param provider 身份提供器.
|
* @param provider 身份提供器.
|
||||||
|
Loading…
Reference in New Issue
Block a user