Author: kwright
Date: Tue Oct 29 05:24:38 2013
New Revision: 1536589

URL: http://svn.apache.org/r1536589
Log:
Update component for MCF 1.5.

Modified:
    manifoldcf/integration/elasticsearch/trunk/CHANGES.txt
    manifoldcf/integration/elasticsearch/trunk/README.txt
    
manifoldcf/integration/elasticsearch/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java

Modified: manifoldcf/integration/elasticsearch/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch/trunk/CHANGES.txt?rev=1536589&r1=1536588&r2=1536589&view=diff
==============================================================================
--- manifoldcf/integration/elasticsearch/trunk/CHANGES.txt (original)
+++ manifoldcf/integration/elasticsearch/trunk/CHANGES.txt Tue Oct 29 05:24:38 
2013
@@ -3,6 +3,11 @@ $Id$
 
 ======================= 0.2-SNAPSHOT =====================
 
+Add functionality making the plugin compatible with multi-domain
+features of ManifoldCF.  Specifically, create method signatures that
+allow multiple domain/username pairs to be passed in.
+(Karl Wright)
+
 ======================= Release 0.1 =====================
 
 Added the path.data parameter in the ElasticSearch server: now the data folder 
is created under the target folder

Modified: manifoldcf/integration/elasticsearch/trunk/README.txt
URL: 
http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch/trunk/README.txt?rev=1536589&r1=1536588&r2=1536589&view=diff
==============================================================================
--- manifoldcf/integration/elasticsearch/trunk/README.txt (original)
+++ manifoldcf/integration/elasticsearch/trunk/README.txt Tue Oct 29 05:24:38 
2013
@@ -13,6 +13,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+Compatibility
+------------
+
+This version of this component is only compatible with ManifoldCF 1.5 and 
above, and cannot be used with earlier releases of ManifoldCF.
 
 Instructions for Building Apache ManifoldCF Plugin for Elastic Search from 
Source
 -----------------------------------------------------------------------------

Modified: 
manifoldcf/integration/elasticsearch/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/integration/elasticsearch/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java?rev=1536589&r1=1536588&r2=1536589&view=diff
==============================================================================
--- 
manifoldcf/integration/elasticsearch/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java
 (original)
+++ 
manifoldcf/integration/elasticsearch/trunk/src/main/java/org/apache/manifoldcf/elasticsearch/MCFAuthorizer.java
 Tue Oct 29 05:24:38 2013
@@ -116,21 +116,56 @@ public class MCFAuthorizer
   }
   
   /** Main method for building a filter representing appropriate security.
-  *@param authenticatedUserName is a user name in the form "user@domain".
+  *@param domainMap is a map from MCF authorization domain name to user name,
+  * and describes a complete user identity.
   *@return the filter builder.
   */
-  public FilterBuilder buildAuthorizationFilter(String authenticatedUserName)
+  public FilterBuilder buildAuthorizationFilter(Map<String,String> domainMap)
     throws AuthorizerException
   {
     if (authorityBaseURL == null)
       throw new IllegalStateException("Authority base URL required for finding 
access tokens for a user");
     
-    if (authenticatedUserName == null)
+    if (domainMap == null || domainMap.size() == 0)
       throw new IllegalArgumentException("Cannot find user tokens for null 
user");
 
-    LOG.info("Trying to match docs for user '"+authenticatedUserName+"'");
+    StringBuilder sb = new StringBuilder("[");
+    boolean first = true;
+    for (String domain : domainMap.keySet())
+    {
+      if (!first)
+        sb.append(",");
+      else
+        first = false;
+      sb.append(domain).append(":").append(domainMap.get(domain));
+    }
+    sb.append("]");
+    LOG.info("Trying to match docs for user '"+sb.toString()+"'");
 
-    return buildAuthorizationFilter(getAccessTokens(authenticatedUserName));
+    return buildAuthorizationFilter(getAccessTokens(domainMap));
+  }
+  
+  /** Main method for building a filter representing appropriate security.
+  *@param authenticatedUserName is a user name in the form "user@domain".
+  *@return the filter builder.
+  */
+  public FilterBuilder buildAuthorizationFilter(String authenticatedUserName)
+    throws AuthorizerException
+  {
+    return buildAuthorizationFilter(authenticatedUserName, "");
+  }
+  
+  /** Main method for building a filter representing appropriate security.
+  *@param authenticatedUserName is a user name in the form "user@domain".
+  *@param authenticatedUserDomain is the corresponding MCF authorization 
domain.
+  *@return the filter builder.
+  */
+  public FilterBuilder buildAuthorizationFilter(String authenticatedUserName, 
String authenticatedUserDomain)
+    throws AuthorizerException
+  {
+    Map<String,String> domainMap = new HashMap<String,String>();
+    domainMap.put(authenticatedUserDomain, authenticatedUserName);
+    return buildAuthorizationFilter(domainMap);
   }
 
   /** Main method for building a filter representing appropriate security.
@@ -193,12 +228,26 @@ public class MCFAuthorizer
   }
 
   /** Get access tokens given a username */
-  protected List<String> getAccessTokens(String authenticatedUserName)
+  protected List<String> getAccessTokens(Map<String,String> domainMap)
     throws AuthorizerException
   {
     try
     {
-      String theURL = authorityBaseURL + 
"/UserACLs?username="+URLEncoder.encode(authenticatedUserName,"utf-8");
+      StringBuilder urlBuffer = new StringBuilder(authorityBaseURL);
+      urlBuffer.append("/UserACLs");
+      int i = 0;
+      for (String domain : domainMap.keySet())
+      {
+        if (i == 0)
+          urlBuffer.append("?");
+        else
+          urlBuffer.append("&");
+        
urlBuffer.append("username_").append(Integer.toString(i)).append("=").append(URLEncoder.encode(domainMap.get(domain),"utf-8")).append("&")
+          
.append("domain_").append(Integer.toString(i)).append("=").append(URLEncoder.encode(domain,"utf-8"));
+        i++;
+      }
+      String theURL = urlBuffer.toString();
+
       HttpGet method = new HttpGet(theURL);
       try
       {
@@ -235,7 +284,7 @@ public class MCFAuthorizer
                 else
                 {
                   // It probably says something about the state of the 
authority(s) involved, so log it
-                  LOG.info("For user '"+authenticatedUserName+"', saw 
authority response "+line);
+                  LOG.info("Saw authority response "+line);
                 }
               }
               return tokenList;


Reply via email to