use of org.keycloak.models.map.storage.ModelEntityUtil in project keycloak by keycloak.
the class TreeStorageNodePrescription method restrictConfigMap.
/**
* Restricts configuration map to options that are either applicable everywhere (have no '[' in their name)
* or apply to a selected entity class (e.g. ends in "[clients]" for {@code MapClientEntity}).
* @return A new configuration map crafted for this particular entity class
*/
private static <V extends AbstractEntity> Map<String, Object> restrictConfigMap(Class<V> targetEntityClass, Map<String, Object> np) {
final Class<Object> modelType = ModelEntityUtil.getModelType(targetEntityClass, null);
String name = Optional.ofNullable(modelType).map(ModelEntityUtil::getModelName).orElse(null);
if (name == null) {
return null;
}
// Start with all properties not specific for any domain
Map<String, Object> res = np.entrySet().stream().filter(me -> me.getKey().indexOf('[') == -1).filter(me -> me.getValue() != null).collect(Collectors.toMap(Entry::getKey, Entry::getValue, (s, a) -> s, HashMap::new));
// Now add and/or replace properties specific for the target domain
Pattern specificPropertyPattern = Pattern.compile("(.*?)\\[.*\\b" + Pattern.quote(name) + "\\b.*\\]");
np.keySet().stream().map(specificPropertyPattern::matcher).filter(Matcher::matches).forEach(m -> res.put(m.group(1), np.get(m.group(0))));
return res;
}
Aggregations