mirror of
https://github.com/dataease/dataease.git
synced 2026-05-15 05:22:13 +08:00
fix(X-Pack): OAuth2 对接用户支持多集属性映射 #15523
This commit is contained in:
committed by
xuwei-fit2cloud
parent
05235f883e
commit
0d03f5c7f6
41
sdk/common/src/main/java/io/dataease/utils/MappingUtils.java
Normal file
41
sdk/common/src/main/java/io/dataease/utils/MappingUtils.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package io.dataease.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MappingUtils {
|
||||
|
||||
public static Map<String, String> mapNestedUserData(Map<String, Object> userMap, Map<String, String> mappingMap) {
|
||||
|
||||
Map<String, String> resultMap = new HashMap<>();
|
||||
mappingMap.forEach((targetKey, sourcePath) -> {
|
||||
Object value = getNestedValue(userMap, sourcePath);
|
||||
if (value != null) {
|
||||
resultMap.put(targetKey, value.toString());
|
||||
}
|
||||
});
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private static Object getNestedValue(Map<String, Object> sourceMap, String path) {
|
||||
String[] keys = path.split("\\.");
|
||||
Object current = sourceMap;
|
||||
|
||||
for (String key : keys) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user