Search in sources :

Example 6 with CommandOperation

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;
}
Also used : CommandOperation(org.apache.solr.common.util.CommandOperation) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap)

Example 7 with CommandOperation

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());
}
Also used : CommandOperation(org.apache.solr.common.util.CommandOperation) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 8 with CommandOperation

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());
}
Also used : CommandOperation(org.apache.solr.common.util.CommandOperation) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with CommandOperation

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;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) HashMap(java.util.HashMap) CommandOperation(org.apache.solr.common.util.CommandOperation) CompositeApi(org.apache.solr.api.V2HttpCall.CompositeApi) CompositeApi(org.apache.solr.api.V2HttpCall.CompositeApi) Api(org.apache.solr.api.Api)

Example 10 with CommandOperation

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"));
}
Also used : CommandOperation(org.apache.solr.common.util.CommandOperation) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

CommandOperation (org.apache.solr.common.util.CommandOperation)13 Map (java.util.Map)5 SolrException (org.apache.solr.common.SolrException)5 LinkedHashMap (java.util.LinkedHashMap)4 HashMap (java.util.HashMap)3 Api (org.apache.solr.api.Api)3 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 Collections.singletonList (java.util.Collections.singletonList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 List (java.util.List)2 SolrParams (org.apache.solr.common.params.SolrParams)2 ValidatingJsonMap (org.apache.solr.common.util.ValidatingJsonMap)2 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)2 File (java.io.File)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ApiBag (org.apache.solr.api.ApiBag)1