Search in sources :

Example 26 with ModifiableSolrParams

use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.

the class BasicAuthStandaloneTest method testBasicAuth.

@Test
@LogLevel("org.apache.solr=DEBUG")
public void testBasicAuth() throws Exception {
    String authcPrefix = "/admin/authentication";
    HttpClient cl = null;
    HttpSolrClient httpSolrClient = null;
    try {
        cl = HttpClientUtil.createClient(null);
        String baseUrl = buildUrl(jetty.getLocalPort(), "/solr");
        httpSolrClient = getHttpSolrClient(baseUrl);
        verifySecurityStatus(cl, baseUrl + authcPrefix, "/errorMessages", null, 20);
        // Write security.json locally. Should cause security to be initialized
        securityConfHandler.persistConf(new SecurityConfHandler.SecurityConfig().setData(Utils.fromJSONString(STD_CONF.replaceAll("'", "\""))));
        securityConfHandler.securityConfEdited();
        verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/class", "solr.BasicAuthPlugin", 20);
        String command = "{\n" + "'set-user': {'harry':'HarryIsCool'}\n" + "}";
        GenericSolrRequest genericReq = new GenericSolrRequest(SolrRequest.METHOD.POST, authcPrefix, new ModifiableSolrParams());
        genericReq.setContentStreams(Collections.singletonList(new ContentStreamBase.ByteArrayStream(command.getBytes(UTF_8), "")));
        HttpSolrClient finalHttpSolrClient = httpSolrClient;
        HttpSolrClient.RemoteSolrException exp = expectThrows(HttpSolrClient.RemoteSolrException.class, () -> {
            finalHttpSolrClient.request(genericReq);
        });
        assertEquals(401, exp.code());
        command = "{\n" + "'set-user': {'harry':'HarryIsUberCool'}\n" + "}";
        HttpPost httpPost = new HttpPost(baseUrl + authcPrefix);
        setBasicAuthHeader(httpPost, "solr", "SolrRocks");
        httpPost.setEntity(new ByteArrayEntity(command.getBytes(UTF_8)));
        httpPost.addHeader("Content-Type", "application/json; charset=UTF-8");
        verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication.enabled", "true", 20);
        HttpResponse r = cl.execute(httpPost);
        int statusCode = r.getStatusLine().getStatusCode();
        Utils.consumeFully(r.getEntity());
        assertEquals("proper_cred sent, but access denied", 200, statusCode);
        verifySecurityStatus(cl, baseUrl + authcPrefix, "authentication/credentials/harry", NOT_NULL_PREDICATE, 20);
        // Read file from SOLR_HOME and verify that it contains our new user
        assertTrue(new String(Utils.toJSON(securityConfHandler.getSecurityConfig(false).getData()), Charset.forName("UTF-8")).contains("harry"));
    } finally {
        if (cl != null) {
            HttpClientUtil.close(cl);
            httpSolrClient.close();
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) HttpPost(org.apache.http.client.methods.HttpPost) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test) LogLevel(org.apache.solr.util.LogLevel)

Example 27 with ModifiableSolrParams

use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.

the class TestDefaultStatsCache method dfQuery.

protected void dfQuery(Object... q) throws Exception {
    final ModifiableSolrParams params = new ModifiableSolrParams();
    for (int i = 0; i < q.length; i += 2) {
        params.add(q[i].toString(), q[i + 1].toString());
    }
    final QueryResponse controlRsp = controlClient.query(params);
    // query a random server
    params.set("shards", shards);
    int which = r.nextInt(clients.size());
    SolrClient client = clients.get(which);
    QueryResponse rsp = client.query(params);
    checkResponse(controlRsp, rsp);
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 28 with ModifiableSolrParams

use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.

the class FacetStream method open.

public void open() throws IOException {
    if (cache != null) {
        cloudSolrClient = cache.getCloudSolrClient(zkHost);
    } else {
        cloudSolrClient = new Builder().withZkHost(zkHost).build();
    }
    FieldComparator[] adjustedSorts = adjustSorts(buckets, bucketSorts);
    String json = getJsonFacetString(buckets, metrics, adjustedSorts, bucketSizeLimit);
    ModifiableSolrParams paramsLoc = new ModifiableSolrParams(params);
    paramsLoc.set("json.facet", json);
    paramsLoc.set("rows", "0");
    QueryRequest request = new QueryRequest(paramsLoc);
    try {
        NamedList response = cloudSolrClient.request(request, collection);
        getTuples(response, buckets, metrics);
        Collections.sort(tuples, getStreamSort());
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) NamedList(org.apache.solr.common.util.NamedList) Builder(org.apache.solr.client.solrj.impl.CloudSolrClient.Builder) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) IOException(java.io.IOException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IOException(java.io.IOException)

Example 29 with ModifiableSolrParams

use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.

the class FacetStream method toExplanation.

@Override
public Explanation toExplanation(StreamFactory factory) throws IOException {
    StreamExplanation explanation = new StreamExplanation(getStreamNodeId().toString());
    explanation.setFunctionName(factory.getFunctionName(this.getClass()));
    explanation.setImplementingClass(this.getClass().getName());
    explanation.setExpressionType(ExpressionType.STREAM_SOURCE);
    explanation.setExpression(toExpression(factory).toString());
    // child is a datastore so add it at this point
    StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-datastore");
    child.setFunctionName(String.format(Locale.ROOT, "solr (%s)", collection));
    // TODO: fix this so we know the # of workers - check with Joel about a Topic's ability to be in a
    // parallel stream.
    child.setImplementingClass("Solr/Lucene");
    child.setExpressionType(ExpressionType.DATASTORE);
    ModifiableSolrParams tmpParams = new ModifiableSolrParams(SolrParams.toMultiMap(params.toNamedList()));
    child.setExpression(tmpParams.getMap().entrySet().stream().map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue())).collect(Collectors.joining(",")));
    explanation.addChild(child);
    return explanation;
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 30 with ModifiableSolrParams

use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.

the class ShortestPathStream method toExplanation.

@Override
public Explanation toExplanation(StreamFactory factory) throws IOException {
    StreamExplanation explanation = new StreamExplanation(getStreamNodeId().toString());
    explanation.setFunctionName(factory.getFunctionName(this.getClass()));
    explanation.setImplementingClass(this.getClass().getName());
    explanation.setExpressionType(ExpressionType.GRAPH_SOURCE);
    explanation.setExpression(toExpression(factory).toString());
    // child is a datastore so add it at this point
    StreamExplanation child = new StreamExplanation(getStreamNodeId() + "-datastore");
    child.setFunctionName("solr (graph)");
    child.setImplementingClass("Solr/Lucene");
    child.setExpressionType(ExpressionType.DATASTORE);
    ModifiableSolrParams mParams = new ModifiableSolrParams(queryParams);
    child.setExpression(mParams.getMap().entrySet().stream().map(e -> String.format(Locale.ROOT, "%s=%s", e.getKey(), e.getValue())).collect(Collectors.joining(",")));
    explanation.addChild(child);
    return explanation;
}
Also used : StreamExplanation(org.apache.solr.client.solrj.io.stream.expr.StreamExplanation) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)521 Test (org.junit.Test)168 ArrayList (java.util.ArrayList)87 NamedList (org.apache.solr.common.util.NamedList)76 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)72 SolrException (org.apache.solr.common.SolrException)68 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)66 HashMap (java.util.HashMap)61 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)58 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)57 List (java.util.List)56 IOException (java.io.IOException)55 Map (java.util.Map)52 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)52 SolrInputDocument (org.apache.solr.common.SolrInputDocument)51 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)48 Tuple (org.apache.solr.client.solrj.io.Tuple)47 SolrParams (org.apache.solr.common.params.SolrParams)42 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)41 SolrRequest (org.apache.solr.client.solrj.SolrRequest)36