From 000d0c1364b4c39d53095b37f263f75880d432db Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Sat, 5 Jan 2019 19:31:28 +1100 Subject: [PATCH] SOLR-12514: FIxed the test and another bug --- .../org/apache/solr/request/SolrRequestInfo.java | 14 ++++++++++++++ .../solr/security/PKIAuthenticationPlugin.java | 2 +- .../java/org/apache/solr/servlet/HttpSolrCall.java | 2 +- .../TestSolrCloudWithSecureImpersonation.java | 1 - .../solr/security/BasicAuthIntegrationTest.java | 9 ++++----- .../security/HttpParamDelegationTokenPlugin.java | 2 +- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java b/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java index 424f1a6b55a..5995f2b0e1c 100644 --- a/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java +++ b/solr/core/src/java/org/apache/solr/request/SolrRequestInfo.java @@ -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 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; diff --git a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java index a60e7008724..b14068c9317 100644 --- a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java +++ b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java @@ -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 diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java index b8332448e60..f10481daf87 100644 --- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java +++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java @@ -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: diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java index 1f737993112..a149b33ab4a 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java @@ -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"); diff --git a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java index c643d297538..39389b6d194 100644 --- a/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java @@ -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"); diff --git a/solr/core/src/test/org/apache/solr/security/HttpParamDelegationTokenPlugin.java b/solr/core/src/test/org/apache/solr/security/HttpParamDelegationTokenPlugin.java index a8f03550b55..bd1818e0e95 100644 --- a/solr/core/src/test/org/apache/solr/security/HttpParamDelegationTokenPlugin.java +++ b/solr/core/src/test/org/apache/solr/security/HttpParamDelegationTokenPlugin.java @@ -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