SOLR-12514: FIxed the test and another bug

This commit is contained in:
Noble Paul 2019-01-05 19:31:28 +11:00
parent 73797f60ad
commit 000d0c1364
6 changed files with 21 additions and 9 deletions

View File

@ -16,8 +16,10 @@
*/
package org.apache.solr.request;
import javax.servlet.http.HttpServletRequest;
import java.io.Closeable;
import java.lang.invoke.MethodHandles;
import java.security.Principal;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@ -40,6 +42,7 @@ public class SolrRequestInfo {
protected SolrQueryRequest req;
protected SolrQueryResponse rsp;
protected Date now;
protected HttpServletRequest httpRequest;
protected TimeZone tz;
protected ResponseBuilder rb;
protected List<Closeable> closeHooks;
@ -83,6 +86,17 @@ public class SolrRequestInfo {
this.req = req;
this.rsp = rsp;
}
public SolrRequestInfo(HttpServletRequest httpReq, SolrQueryResponse rsp) {
this.httpRequest = httpReq;
this.rsp = rsp;
}
public Principal getUserPrincipal() {
if (req != null) return req.getUserPrincipal();
if (httpRequest != null) return httpRequest.getUserPrincipal();
return null;
}
public Date getNOW() {
if (now != null) return now;

View File

@ -280,7 +280,7 @@ public class PKIAuthenticationPlugin extends AuthenticationPlugin implements Htt
SolrRequestInfo reqInfo = getRequestInfo();
String usr;
if (reqInfo != null) {
Principal principal = reqInfo.getReq().getUserPrincipal();
Principal principal = reqInfo.getUserPrincipal();
if (principal == null) {
log.debug("principal is null");
//this had a request but not authenticated

View File

@ -496,7 +496,7 @@ public class HttpSolrCall {
handleAdminRequest();
return RETURN;
case REMOTEQUERY:
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(solrReq, new SolrQueryResponse()));
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, new SolrQueryResponse()));
remoteQuery(coreUrl + path, resp);
return RETURN;
case PROCESS:

View File

@ -312,7 +312,6 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
}
@Test
@AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/SOLR-13098")
public void testForwarding() throws Exception {
String collectionName = "forwardingCollection";
miniCluster.uploadConfigSet(TEST_PATH().resolve("collection1/conf"), "conf1");

View File

@ -244,12 +244,11 @@ public class BasicAuthIntegrationTest extends SolrCloudAuthTestCase {
//Make a request to that jetty and it should fail
JettySolrRunner aNewJetty = cluster.startJettySolrRunner();
SolrClient aNewClient = aNewJetty.newClient();
UpdateRequest delQuery = null;
delQuery = new UpdateRequest().deleteByQuery("*:*");
delQuery.setBasicAuthCredentials("harry","HarryIsUberCool");
delQuery.process(aNewClient, COLLECTION);//this should succeed
try {
UpdateRequest delQuery = null;
delQuery = new UpdateRequest().deleteByQuery("*:*");
delQuery.setBasicAuthCredentials("harry","HarryIsUberCool");
delQuery.process(aNewClient, COLLECTION);//this should succeed
delQuery = new UpdateRequest().deleteByQuery("*:*");
delQuery.process(aNewClient, COLLECTION);
fail("This should not have succeeded without credentials");

View File

@ -127,7 +127,7 @@ public class HttpParamDelegationTokenPlugin extends KerberosPlugin {
SolrRequestInfo reqInfo = SolrRequestInfo.getRequestInfo();
String usr;
if (reqInfo != null) {
Principal principal = reqInfo.getReq().getUserPrincipal();
Principal principal = reqInfo.getUserPrincipal();
if (principal == null) {
//this had a request but not authenticated
//so we don't not need to set a principal