mirror of
https://github.com/dataease/dataease.git
synced 2026-05-14 04:12:11 +08:00
perf(X-Pack): 对接 Oauth2 用户属性映射支持使用数组
This commit is contained in:
committed by
fit2cloud-chenyw
parent
cbd53e2d4a
commit
102e33de36
@@ -1,6 +1,7 @@
|
||||
package io.dataease.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MappingUtils {
|
||||
@@ -23,12 +24,48 @@ public class MappingUtils {
|
||||
Object current = sourceMap;
|
||||
|
||||
for (String key : keys) {
|
||||
if (!(current instanceof Map)) {
|
||||
if (current == null) {
|
||||
return null;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> currentMap = (Map<String, Object>) current;
|
||||
current = currentMap.get(key);
|
||||
|
||||
if (key.matches(".+\\[\\d+]")) {
|
||||
String propertyName = key.replaceAll("\\[\\d+]", "");
|
||||
String indexStr = key.replaceAll(".*\\[(\\d+)]", "$1");
|
||||
|
||||
if (!(current instanceof Map)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> currentMap = (Map<String, Object>) current;
|
||||
Object arrayOrList = currentMap.get(propertyName);
|
||||
|
||||
if (!(arrayOrList instanceof List)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> list = (List<Object>) arrayOrList;
|
||||
|
||||
try {
|
||||
int index = Integer.parseInt(indexStr);
|
||||
if (index < 0 || index >= list.size()) {
|
||||
return null;
|
||||
}
|
||||
current = list.get(index);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// 普通对象属性
|
||||
if (!(current instanceof Map)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> currentMap = (Map<String, Object>) current;
|
||||
current = currentMap.get(key);
|
||||
}
|
||||
|
||||
if (current == null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user