manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1807497 - in /manifoldcf/integration/elasticsearch-5.5/trunk/src/main: java/org/apache/manifoldcf/elasticsearch/ resources/
Date Wed, 06 Sep 2017 16:18:26 GMT
Author: kwright
Date: Wed Sep  6 16:18:26 2017
New Revision: 1807497

URL: http://svn.apache.org/viewvc?rev=1807497&view=rev
Log:
Add Steph van Schalkwyk's patch -- work in progress.

Modified:
    manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java
    manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerException.java
    manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerPlugin.java
    manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerRestSearchAction.java
    manifoldcf/integration/elasticsearch-5.5/trunk/src/main/resources/plugin-descriptor.properties

Modified: manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java
URL: http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java?rev=1807497&r1=1807496&r2=1807497&view=diff
==============================================================================
--- manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java
(original)
+++ manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java
Wed Sep  6 16:18:26 2017
@@ -26,8 +26,9 @@ import org.elasticsearch.index.query.Que
 import org.elasticsearch.index.query.BoolQueryBuilder;
 import org.elasticsearch.index.query.TermQueryBuilder;
 
-import org.elasticsearch.common.logging.Loggers;
-import org.elasticsearch.common.logging.ESLogger;
+import org.apache.logging.log4j.Logger;
+import org.elasticsearch.common.logging.ESLoggerFactory;
+
 
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
@@ -51,7 +52,7 @@ public class MCFAuthorizer
   static final public String NOSECURITY_TOKEN = "__nosecurity__";
 
   /** A logger we can use */
-  private static final ESLogger LOG = Loggers.getLogger(MCFAuthorizer.class);
+  private static final Logger LOG = ESLoggerFactory.getLogger(MCFAuthorizer.class);
 
   // Member variables
 

Modified: manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerException.java
URL: http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerException.java?rev=1807497&r1=1807496&r2=1807497&view=diff
==============================================================================
--- manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerException.java
(original)
+++ manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerException.java
Wed Sep  6 16:18:26 2017
@@ -26,6 +26,9 @@ import org.elasticsearch.ElasticsearchEx
 */
 public class MCFAuthorizerException extends ElasticsearchException
 {
+  // default serialVersionID
+	private static final long serialVersionUID = 1L;
+
   /** Constructor */
   public MCFAuthorizerException(String message)
   {

Modified: manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerPlugin.java
URL: http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerPlugin.java?rev=1807497&r1=1807496&r2=1807497&view=diff
==============================================================================
--- manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerPlugin.java
(original)
+++ manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerPlugin.java
Wed Sep  6 16:18:26 2017
@@ -18,27 +18,30 @@
 */
 package org.apache.manifoldcf.elasticsearch;
 
-import org.elasticsearch.common.logging.ESLogger;
-import org.elasticsearch.common.logging.Loggers;
+import org.apache.logging.log4j.Logger;
+import org.elasticsearch.common.logging.ESLoggerFactory;
 
 import org.elasticsearch.plugins.Plugin;
-import org.elasticsearch.rest.RestModule;
+//import org.elasticsearch.rest.RestModule;
+import org.elasticsearch.rest.BytesRestResponse;
+import org.elasticsearch.rest.RestController;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.action.cat.AbstractCatAction;
+import org.elasticsearch.rest.action.cat.RestTable;
 
 public class MCFAuthorizerPlugin extends Plugin
 {
 
-  private final ESLogger log = Loggers.getLogger(this.getClass());
+  private final Logger log = ESLoggerFactory.getLogger(this.getClass());
 
   public MCFAuthorizerPlugin() {
     log.info("Starting ManifoldCF Authorizer Plugin");
   }
 
-  @Override
   public String name() {
     return "elasticsearch-plugin-mcf";
   }
 
-  @Override
   public String description() {
     return "Plugin to connect elasticsearch with ManifoldCF";
   }

Modified: manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerRestSearchAction.java
URL: http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerRestSearchAction.java?rev=1807497&r1=1807496&r2=1807497&view=diff
==============================================================================
--- manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerRestSearchAction.java
(original)
+++ manifoldcf/integration/elasticsearch-5.5/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizerRestSearchAction.java
Wed Sep  6 16:18:26 2017
@@ -24,25 +24,26 @@ import org.elasticsearch.common.inject.I
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.rest.*;
 import org.elasticsearch.rest.action.search.RestSearchAction;
-import org.elasticsearch.rest.action.support.RestStatusToXContentListener;
+import org.elasticsearch.rest.action.RestStatusToXContentListener;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.elasticsearch.action.support.IndicesOptions;
-import org.elasticsearch.common.ParseFieldMatcher;
+/**import org.elasticsearch.common.ParseFieldMatcher;*/
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.index.query.*;
 import org.elasticsearch.rest.RestRequest;
-import org.elasticsearch.rest.action.support.RestActions;
+import org.elasticsearch.rest.action.RestActions;
 import org.elasticsearch.search.Scroll;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
-import org.elasticsearch.search.fetch.source.FetchSourceContext;
+import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
 import org.elasticsearch.search.sort.SortOrder;
 import org.elasticsearch.search.suggest.SuggestBuilders;
 import org.elasticsearch.search.suggest.term.TermSuggestionBuilder;
 import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.XContentParser;
 
 import java.io.*;
 
@@ -51,22 +52,22 @@ public class MCFAuthorizerRestSearchActi
   protected final MCFAuthorizer authorizer;
   
   @Inject
-  public MCFAuthorizerRestSearchAction(Settings settings, final RestController restController,
Client client) {
-    super(settings,restController,client);
+  public MCFAuthorizerRestSearchAction(Settings settings, final RestController restController)
{
+    super(settings,restController);
     final MCFConfigurationParameters conf = new MCFConfigurationParameters(settings);
     authorizer = new MCFAuthorizer(conf);
   }
 
-  @Override
   public void handleRequest(RestRequest request, RestChannel channel, Client client) {
     SearchRequest searchRequest;
-    searchRequest = parseSearchRequestMCF(request, parseFieldMatcher);
+    searchRequest = parseSearchRequestMCF(request); //, parseFieldMatcher);
     client.search(searchRequest, new RestStatusToXContentListener(channel));
   }
   
   protected SearchRequest parseSearchRequestMCF(
-    final RestRequest request,
-    final ParseFieldMatcher parseFieldMatcher) throws MCFAuthorizerException {
+    final RestRequest request //,
+//    final ParseFieldMatcher parseFieldMatcher
+    ) throws MCFAuthorizerException {
     final SearchRequest searchRequest;
     if(request.param("u")!=null) {
       searchRequest = new SearchRequest();
@@ -77,24 +78,31 @@ public class MCFAuthorizerRestSearchActi
 
       if(request.hasContent() || request.hasParam("source")) {
         QueryBuilder authorizationFilter = authorizer.buildAuthorizationFilter(authenticatedUserNamesAndDomains);
-        FilteredQueryBuilder filteredQueryBuilder;
+        QueryBuilder filteredQueryBuilder;
 
         ObjectMapper objectMapper = new ObjectMapper();
         ObjectNode modifiedJSON, innerJSON;
         JsonNode requestJSON;
 
         try {
-          requestJSON = objectMapper.readTree(RestActions.getRestContent(request).toBytes());
+          requestJSON = objectMapper.readTree(RestActions.getQueryContent((XContentParser)
request).toString());
           if (isTemplateRequest) {
             modifiedJSON = (ObjectNode) requestJSON;
             innerJSON = (ObjectNode)requestJSON.findValue("template");
-            filteredQueryBuilder = QueryBuilders.filteredQuery(QueryBuilders.wrapperQuery(innerJSON.findValue("query").toString()),
authorizationFilter);
-            modifiedJSON.replace("template",innerJSON.set("query", objectMapper.readTree(filteredQueryBuilder.buildAsBytes().toBytes())));
+            filteredQueryBuilder = QueryBuilders.boolQuery()
+            		.must (QueryBuilders.wrapperQuery(innerJSON.findValue("query").toString()))
+            		.must(authorizationFilter);      		
+            		
+            modifiedJSON.replace("template",innerJSON.set("query", objectMapper.readTree(filteredQueryBuilder.toString())));
             searchRequest.templateSource(modifiedJSON.toString());
+            searchRequest.set
           } else {
-            filteredQueryBuilder = QueryBuilders.filteredQuery(QueryBuilders.wrapperQuery(requestJSON.findValue("query").toString()),
authorizationFilter);
+            filteredQueryBuilder = QueryBuilders.boolQuery()
+            		.must(QueryBuilders.wrapperQuery(requestJSON.findValue("query").toString()))
+            		.must(authorizationFilter);
+            				
             modifiedJSON = (ObjectNode) requestJSON;
-            modifiedJSON.set("query", objectMapper.readTree(filteredQueryBuilder.buildAsBytes().toBytes()));
+            modifiedJSON.set("query", objectMapper.readTree(filteredQueryBuilder.toString()));
             searchRequest.source(modifiedJSON.toString());
           }
         } catch (IOException e) {
@@ -103,7 +111,7 @@ public class MCFAuthorizerRestSearchActi
       }
 
       //parseSearchSource(searchRequest.source(), request);
-      searchRequest.extraSource(parseSearchSourceMCF(request));
+      searchRequest.source(parseSearchSourceMCF(request));
       searchRequest.searchType(request.param("search_type"));
       
       // Should this be done?
@@ -120,7 +128,7 @@ public class MCFAuthorizerRestSearchActi
       searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
     }
     else {
-      searchRequest = parseSearchRequest(request, parseFieldMatcher);
+      searchRequest = parseSearchRequest(request);//, parseFieldMatcher);
     }
     return searchRequest;
   }
@@ -135,18 +143,18 @@ public class MCFAuthorizerRestSearchActi
       from.defaultField(request.param("df"));
       from.analyzer(request.param("analyzer"));
       from.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
-      from.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
+//      from.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
       from.lenient(request.paramAsBoolean("lenient", (Boolean)null));
       String size = request.param("default_operator");
       if(size != null) {
         if("OR".equals(size)) {
-          from.defaultOperator(QueryStringQueryBuilder.Operator.OR);
+          from.defaultOperator(Operator.OR);
         } else {
           if(!"AND".equals(size)) {
             throw new IllegalArgumentException("Unsupported defaultOperator [" + size + "],
can either be [OR] or [AND]");
           }
 
-          from.defaultOperator(QueryStringQueryBuilder.Operator.AND);
+          from.defaultOperator(Operator.AND);
         }
       }
 
@@ -154,7 +162,9 @@ public class MCFAuthorizerRestSearchActi
         searchSourceBuilder = new SearchSourceBuilder();
       }
 
-      searchSourceBuilder.query(QueryBuilders.filteredQuery(from, authorizationFilter));
+      searchSourceBuilder.query(QueryBuilders.boolQuery()
+    		  .must(from)
+    		  .must(authorizationFilter));
     }
     else {
         if(!(request.hasContent() || request.hasParam("source"))){
@@ -162,7 +172,8 @@ public class MCFAuthorizerRestSearchActi
             searchSourceBuilder = new SearchSourceBuilder();
           }
           QueryBuilder authorizationFilter = authorizer.buildAuthorizationFilter(request.param("u"));
-          searchSourceBuilder.query(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),authorizationFilter));
+          searchSourceBuilder.query(QueryBuilders.boolQuery()
+        		  .must(authorizationFilter));
         }
     }
 

Modified: manifoldcf/integration/elasticsearch-5.5/trunk/src/main/resources/plugin-descriptor.properties
URL: http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch-5.5/trunk/src/main/resources/plugin-descriptor.properties?rev=1807497&r1=1807496&r2=1807497&view=diff
==============================================================================
--- manifoldcf/integration/elasticsearch-5.5/trunk/src/main/resources/plugin-descriptor.properties
(original)
+++ manifoldcf/integration/elasticsearch-5.5/trunk/src/main/resources/plugin-descriptor.properties
Wed Sep  6 16:18:26 2017
@@ -19,7 +19,7 @@
 description=ApacheManifoldCF Auth Plugin
 #
 # 'version': plugin's version
-version=2.1
+version=5.5
 #
 # 'name': the plugin name
 name=ApacheManifoldCFAuthPlugin
@@ -40,14 +40,14 @@ classname=org.apache.manifoldcf.elastics
 # use the system property java.specification.version
 # version string must be a sequence of nonnegative decimal integers
 # separated by "."'s and may have leading zeros
-java.version=1.7
+java.version=1.8
 #
 # 'elasticsearch.version' version of elasticsearch compiled against
 # You will have to release a new version of the plugin for each new
 # elasticsearch release. This version is checked when the plugin
 # is loaded so Elasticsearch will refuse to start in the presence of
 # plugins with the incorrect elasticsearch.version.
-elasticsearch.version=2.0.2
+elasticsearch.version=5.5.2
 #
 ### deprecated elements for jvm plugins :
 #



Mime
View raw message