You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/04/16 12:18:05 UTC

svn commit: r1093956 - in /incubator/lcf/branches/CONNECTORS-32: CHANGES.txt connectors/documentum/connector/src/main/java/org/apache/manifoldcf/crawler/authorities/DCTM/AuthorityConnector.java

Author: kwright
Date: Sat Apr 16 10:18:05 2011
New Revision: 1093956

URL: http://svn.apache.org/viewvc?rev=1093956&view=rev
Log:
Add caching to documentum authority connector

Modified:
    incubator/lcf/branches/CONNECTORS-32/CHANGES.txt
    incubator/lcf/branches/CONNECTORS-32/connectors/documentum/connector/src/main/java/org/apache/manifoldcf/crawler/authorities/DCTM/AuthorityConnector.java

Modified: incubator/lcf/branches/CONNECTORS-32/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/CHANGES.txt?rev=1093956&r1=1093955&r2=1093956&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/CHANGES.txt (original)
+++ incubator/lcf/branches/CONNECTORS-32/CHANGES.txt Sat Apr 16 10:18:05 2011
@@ -3,7 +3,7 @@ $Id$
 
 ======================= 0.3-dev =========================
 CONNECTORS-32: Add access token caching to the Active Directory
-authority connector.
+authority connector, and Documentum authority connector.
 (Shinichiro Abe, Karl Wright)
 
 CONNECTORS-181: Fix the way timed expiration works to agree with

Modified: incubator/lcf/branches/CONNECTORS-32/connectors/documentum/connector/src/main/java/org/apache/manifoldcf/crawler/authorities/DCTM/AuthorityConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/connectors/documentum/connector/src/main/java/org/apache/manifoldcf/crawler/authorities/DCTM/AuthorityConnector.java?rev=1093956&r1=1093955&r2=1093956&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/connectors/documentum/connector/src/main/java/org/apache/manifoldcf/crawler/authorities/DCTM/AuthorityConnector.java (original)
+++ incubator/lcf/branches/CONNECTORS-32/connectors/documentum/connector/src/main/java/org/apache/manifoldcf/crawler/authorities/DCTM/AuthorityConnector.java Sat Apr 16 10:18:05 2011
@@ -57,6 +57,9 @@ public class AuthorityConnector extends 
   protected static final AuthorizationResponse userNotFoundResponse = new AuthorizationResponse(new String[]{denyToken},AuthorizationResponse.RESPONSE_USERNOTFOUND);
   protected static final AuthorizationResponse userUnauthorizedResponse = new AuthorizationResponse(new String[]{denyToken},AuthorizationResponse.RESPONSE_USERUNAUTHORIZED);
 
+    /** Cache manager. */
+  protected ICacheManager cacheManager = null;
+
   // This is the DFC session; it may be null, or it may be set.
   protected IDocumentum session = null;
   protected long lastSessionFetch = -1L;
@@ -68,6 +71,23 @@ public class AuthorityConnector extends 
     super();
   }
 
+  /** Set thread context.
+  */
+  public void setThreadContext(IThreadContext tc)
+    throws ManifoldCFException
+  {
+    super.setThreadContext(tc);
+    cacheManager = CacheManagerFactory.make(tc);
+  }
+  
+  /** Clear thread context.
+  */
+  public void clearThreadContext()
+  {
+    super.clearThreadContext();
+    cacheManager = null;
+  }
+
   protected class GetSessionThread extends Thread
   {
     protected Throwable exception = null;
@@ -583,6 +603,46 @@ public class AuthorityConnector extends 
     if (Logging.authorityConnectors.isDebugEnabled())
       Logging.authorityConnectors.debug("DCTM: Inside AuthorityConnector.getAuthorizationResponse for user '"+strUserNamePassedIn+"'");
 
+    // Construct a cache description object
+    ICacheDescription objectDescription = new AuthorizationResponseDescription(strUserNamePassedIn,docbaseName,userName,password,
+      domain,caseInsensitive,useSystemAcls);
+    
+    // Enter the cache
+    ICacheHandle ch = cacheManager.enterCache(new ICacheDescription[]{objectDescription},null,null);
+    try
+    {
+      ICacheCreateHandle createHandle = cacheManager.enterCreateSection(ch);
+      try
+      {
+        // Lookup the object
+        AuthorizationResponse response = (AuthorizationResponse)cacheManager.lookupObject(createHandle,objectDescription);
+        if (response != null)
+          return response;
+        // Create the object.
+        response = getAuthorizationResponseUncached(strUserNamePassedIn);
+        // Save it in the cache
+        cacheManager.saveObject(createHandle,objectDescription,response);
+        // And return it...
+        return response;
+      }
+      finally
+      {
+        cacheManager.leaveCreateSection(createHandle);
+      }
+    }
+    finally
+    {
+      cacheManager.leaveCache(ch);
+    }
+  }
+  
+  /** Uncached get response method. */
+  protected AuthorizationResponse getAuthorizationResponseUncached(String strUserNamePassedIn)
+    throws ManifoldCFException
+  {
+    if (Logging.authorityConnectors.isDebugEnabled())
+      Logging.authorityConnectors.debug("DCTM: Inside AuthorityConnector.getAuthorizationResponseUncached for user '"+strUserNamePassedIn+"'");
+
     try
     {
       String strUserName;
@@ -1186,4 +1246,80 @@ public class AuthorityConnector extends 
     );
   }
 
+  protected static long responseLifetime = 300000L;
+  protected static int LRUsize = 1000;
+  protected static StringSet emptyStringSet = new StringSet();
+
+  /** This is the cache object descriptor for cached access tokens from
+  * this connector.
+  */
+  protected static class AuthorizationResponseDescription extends org.apache.manifoldcf.core.cachemanager.BaseDescription
+  {
+    // The parameters upon which the cached results are based.
+    protected String userName;
+    protected String docbaseName;
+    protected String adminUserName;
+    protected String adminPassword;
+    protected String domain;
+    protected boolean caseInsensitive;
+    protected boolean useSystemACLs;
+    /** The expiration time */
+    protected long expirationTime = -1;
+    
+    /** Constructor. */
+    public AuthorizationResponseDescription(String userName, String docbaseName,
+      String adminUserName, String adminPassword, String domain, boolean caseInsensitive, boolean useSystemACLs)
+    {
+      super("DocumentumDirectoryAuthority",LRUsize);
+      this.userName = userName;
+      this.docbaseName = docbaseName;
+      this.adminUserName = adminUserName;
+      this.adminPassword = adminPassword;
+      this.domain = domain;
+      this.caseInsensitive = caseInsensitive;
+      this.useSystemACLs = useSystemACLs;
+    }
+
+    /** Return the invalidation keys for this object. */
+    public StringSet getObjectKeys()
+    {
+      return emptyStringSet;
+    }
+
+    /** Get the critical section name, used for synchronizing the creation of the object */
+    public String getCriticalSectionName()
+    {
+      return getClass().getName() + "-" + userName + "-" + docbaseName +
+        "-" + adminUserName + "-" + adminPassword + "-" + ((domain==null)?"NULL":domain) + "-" +
+        (caseInsensitive?"true":"false") + "-" + (useSystemACLs?"true":"false");
+    }
+
+    /** Return the object expiration interval */
+    public long getObjectExpirationTime(long currentTime)
+    {
+      if (expirationTime == -1)
+        expirationTime = currentTime + responseLifetime;
+      return expirationTime;
+    }
+
+    public int hashCode()
+    {
+      return userName.hashCode() + docbaseName.hashCode() + adminUserName.hashCode() +
+        adminPassword.hashCode() + ((domain==null)?0:domain.hashCode()) +
+        (caseInsensitive?1:0) + (useSystemACLs?1:0);
+    }
+    
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof AuthorizationResponseDescription))
+        return false;
+      AuthorizationResponseDescription ard = (AuthorizationResponseDescription)o;
+      return ard.userName.equals(userName) && ard.docbaseName.equals(docbaseName) &&
+        ard.adminUserName.equals(adminUserName) && ard.adminPassword.equals(adminPassword) &&
+        ((ard.domain==null||domain==null)?(ard.domain == domain):(ard.domain.equals(domain))) &&
+        ard.caseInsensitive == caseInsensitive && ard.useSystemACLs == useSystemACLs;
+    }
+    
+  }
+
 }