use of org.apache.solr.common.params.CommonParams.NAME in project lucene-solr by apache.
the class Permission method load.
static Permission load(Map m) {
Permission p = new Permission();
p.originalConfig = new LinkedHashMap<>(m);
String name = (String) m.get(NAME);
if (!m.containsKey("role"))
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "role not specified");
p.role = readValueAsSet(m, "role");
if (PermissionNameProvider.Name.get(name) != null) {
p.wellknownName = PermissionNameProvider.Name.get(name);
HashSet<String> disAllowed = new HashSet<>(knownKeys);
//these are the only
disAllowed.remove("role");
//allowed keys for well-known permissions
disAllowed.remove(NAME);
//allowed keys for well-known permissions
disAllowed.remove("collection");
disAllowed.remove("index");
for (String s : disAllowed) {
if (m.containsKey(s))
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, s + " is not a valid key for the permission : " + name);
}
}
p.name = name;
p.path = readSetSmart(name, m, "path");
p.collections = readSetSmart(name, m, "collection");
p.method = readSetSmart(name, m, "method");
Map<String, Object> paramRules = (Map<String, Object>) m.get("params");
if (paramRules != null) {
p.params = new LinkedHashMap<>();
for (Map.Entry<String, Object> e : paramRules.entrySet()) {
if (e.getValue() == null) {
p.params.put(e.getKey(), (String[] val) -> val == null);
} else {
List<String> patternStrs = e.getValue() instanceof List ? (List) e.getValue() : singletonList(e.getValue().toString());
List patterns = patternStrs.stream().map(it -> it.startsWith("REGEX:") ? Pattern.compile(String.valueOf(it.substring("REGEX:".length()))) : it).collect(Collectors.toList());
p.params.put(e.getKey(), val -> {
if (val == null)
return false;
for (Object pattern : patterns) {
for (String s : val) {
if (pattern instanceof String) {
if (pattern.equals(s))
return true;
} else if (pattern instanceof Pattern) {
if (((Pattern) pattern).matcher(s).find())
return true;
}
}
}
return false;
});
}
}
}
return p;
}
Aggregations