Search in sources :

Example 1 with AbstractEntity

use of org.keycloak.models.map.common.AbstractEntity 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;
}
Also used : DefaultModelCriteria(org.keycloak.models.map.storage.criteria.DefaultModelCriteria) Collection(java.util.Collection) Logger(org.jboss.logging.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) KeycloakSession(org.keycloak.models.KeycloakSession) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Matcher(java.util.regex.Matcher) AbstractEntity(org.keycloak.models.map.common.AbstractEntity) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) EntityField(org.keycloak.models.map.common.EntityField) Pattern(java.util.regex.Pattern) ModelEntityUtil(org.keycloak.models.map.storage.ModelEntityUtil) Pattern(java.util.regex.Pattern)

Aggregations

Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Supplier (java.util.function.Supplier)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Logger (org.jboss.logging.Logger)1 KeycloakSession (org.keycloak.models.KeycloakSession)1 AbstractEntity (org.keycloak.models.map.common.AbstractEntity)1 EntityField (org.keycloak.models.map.common.EntityField)1 ModelEntityUtil (org.keycloak.models.map.storage.ModelEntityUtil)1 DefaultModelCriteria (org.keycloak.models.map.storage.criteria.DefaultModelCriteria)1