use of org.apache.solr.common.util.CommandOperation in project lucene-solr by apache.
the class Sha256AuthenticationProvider method edit.
@Override
public Map<String, Object> edit(Map<String, Object> latestConf, List<CommandOperation> commands) {
for (CommandOperation cmd : commands) {
if (!supported_ops.contains(cmd.name)) {
cmd.unknownOperation();
return null;
}
if (cmd.hasError())
return null;
if ("delete-user".equals(cmd.name)) {
List<String> names = cmd.getStrs("");
Map map = (Map) latestConf.get("credentials");
if (map == null || !map.keySet().containsAll(names)) {
cmd.addError("No such user(s) " + names);
return null;
}
for (String name : names) map.remove(name);
return latestConf;
}
if ("set-user".equals(cmd.name)) {
Map map = getMapValue(latestConf, "credentials");
Map kv = cmd.getDataMap();
for (Object o : kv.entrySet()) {
Map.Entry e = (Map.Entry) o;
if (e.getKey() == null || e.getValue() == null) {
cmd.addError("name and password must be non-null");
return null;
}
putUser(String.valueOf(e.getKey()), String.valueOf(e.getValue()), map);
}
}
}
return latestConf;
}
use of org.apache.solr.common.util.CommandOperation in project lucene-solr by apache.
the class TestSchemaManager method testParsing.
@Test
public void testParsing() throws IOException {
String x = "{\n" + " 'add-field' : {\n" + " 'name':'a',\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'indexed':false\n" + " },\n" + " 'add-field' : {\n" + " 'name':'b',\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'indexed':false\n" + " }\n" + "\n" + "}";
List<CommandOperation> ops = CommandOperation.parse(new StringReader(json(x)));
assertEquals(2, ops.size());
assertTrue(CommandOperation.captureErrors(ops).isEmpty());
x = " {'add-field' : [{\n" + " 'name':'a1',\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'indexed':false\n" + " },\n" + " {\n" + " 'name':'a2',\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }]\n" + " }";
ops = CommandOperation.parse(new StringReader(json(x)));
assertEquals(2, ops.size());
assertTrue(CommandOperation.captureErrors(ops).isEmpty());
}
use of org.apache.solr.common.util.CommandOperation in project lucene-solr by apache.
the class TestSha256AuthenticationProvider method testBasicAuthCommands.
public void testBasicAuthCommands() {
BasicAuthPlugin basicAuthPlugin = new BasicAuthPlugin();
basicAuthPlugin.init(Collections.emptyMap());
Map latestConf = new LinkedHashMap<>();
CommandOperation blockUnknown = new CommandOperation("set-property", singletonMap("blockUnknown", true));
basicAuthPlugin.edit(latestConf, Collections.singletonList(blockUnknown));
assertEquals(Boolean.TRUE, latestConf.get("blockUnknown"));
basicAuthPlugin.init(latestConf);
assertTrue(basicAuthPlugin.getBlockUnknown());
blockUnknown = new CommandOperation("set-property", singletonMap("blockUnknown", false));
basicAuthPlugin.edit(latestConf, Collections.singletonList(blockUnknown));
assertEquals(Boolean.FALSE, latestConf.get("blockUnknown"));
basicAuthPlugin.init(latestConf);
assertFalse(basicAuthPlugin.getBlockUnknown());
}
use of org.apache.solr.common.util.CommandOperation in project lucene-solr by apache.
the class TestApiFramework method invoke.
private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, String path, String fullPath, SolrRequest.METHOD method, CoreContainer mockCC) {
HashMap<String, String> parts = new HashMap<>();
boolean containerHandlerLookup = mockCC.getRequestHandlers() == reqHandlers;
path = path == null ? fullPath : path;
Api api = null;
if (containerHandlerLookup) {
api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
} else {
api = V2HttpCall.getApiInfo(mockCC.getRequestHandlers(), fullPath, "GET", fullPath, parts);
if (api == null)
api = new CompositeApi(null);
if (api instanceof CompositeApi) {
CompositeApi compositeApi = (CompositeApi) api;
api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
compositeApi.add(api);
api = compositeApi;
}
}
SolrQueryResponse rsp = new SolrQueryResponse();
LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>())) {
@Override
public List<CommandOperation> getCommands(boolean validateInput) {
return Collections.emptyList();
}
};
api.call(req, rsp);
return rsp;
}
use of org.apache.solr.common.util.CommandOperation in project lucene-solr by apache.
the class TestSha256AuthenticationProvider method testAuthenticate.
public void testAuthenticate() {
Sha256AuthenticationProvider zkAuthenticationProvider = new Sha256AuthenticationProvider();
zkAuthenticationProvider.init(Collections.emptyMap());
String pwd = "My#$Password";
String user = "noble";
Map latestConf = new LinkedHashMap<>();
Map<String, Object> params = singletonMap(user, pwd);
Map<String, Object> result = zkAuthenticationProvider.edit(latestConf, Collections.singletonList(new CommandOperation("set-user", params)));
zkAuthenticationProvider = new Sha256AuthenticationProvider();
zkAuthenticationProvider.init(result);
assertTrue(zkAuthenticationProvider.authenticate(user, pwd));
assertFalse(zkAuthenticationProvider.authenticate(user, "WrongPassword"));
assertFalse(zkAuthenticationProvider.authenticate("unknownuser", "WrongPassword"));
}
Aggregations