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 15:07:55 UTC

svn commit: r1093985 - in /incubator/lcf/branches/CONNECTORS-32: ./ connectors/activedirectory/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/activedirectory/ connectors/documentum/connector/src/main/java/org/apache/manifoldcf/cr...

Author: kwright
Date: Sat Apr 16 13:07:54 2011
New Revision: 1093985

URL: http://svn.apache.org/viewvc?rev=1093985&view=rev
Log:
Add LiveLink authority caching, and set lifetime of tokens to 1 minute rather than 5.

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

Modified: incubator/lcf/branches/CONNECTORS-32/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/CHANGES.txt?rev=1093985&r1=1093984&r2=1093985&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/CHANGES.txt (original)
+++ incubator/lcf/branches/CONNECTORS-32/CHANGES.txt Sat Apr 16 13:07:54 2011
@@ -3,7 +3,8 @@ $Id$
 
 ======================= 0.3-dev =========================
 CONNECTORS-32: Add access token caching to the Active Directory
-authority connector, and Documentum authority connector.
+authority connector, LiveLink 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/activedirectory/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/activedirectory/ActiveDirectoryAuthority.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/connectors/activedirectory/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/activedirectory/ActiveDirectoryAuthority.java?rev=1093985&r1=1093984&r2=1093985&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/connectors/activedirectory/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/activedirectory/ActiveDirectoryAuthority.java (original)
+++ incubator/lcf/branches/CONNECTORS-32/connectors/activedirectory/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/activedirectory/ActiveDirectoryAuthority.java Sat Apr 16 13:07:54 2011
@@ -590,7 +590,7 @@ public class ActiveDirectoryAuthority ex
     return strSID.toString();
   }
 
-  protected static long responseLifetime = 300000L;
+  protected static long responseLifetime = 60000L;
   protected static int LRUsize = 1000;
   protected static StringSet emptyStringSet = new StringSet();
   

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=1093985&r1=1093984&r2=1093985&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 13:07:54 2011
@@ -1246,7 +1246,7 @@ public class AuthorityConnector extends 
     );
   }
 
-  protected static long responseLifetime = 300000L;
+  protected static long responseLifetime = 60000L;
   protected static int LRUsize = 1000;
   protected static StringSet emptyStringSet = new StringSet();
 

Modified: incubator/lcf/branches/CONNECTORS-32/connectors/livelink/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/livelink/LivelinkAuthority.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-32/connectors/livelink/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/livelink/LivelinkAuthority.java?rev=1093985&r1=1093984&r2=1093985&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-32/connectors/livelink/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/livelink/LivelinkAuthority.java (original)
+++ incubator/lcf/branches/CONNECTORS-32/connectors/livelink/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/livelink/LivelinkAuthority.java Sat Apr 16 13:07:54 2011
@@ -68,6 +68,9 @@ public class LivelinkAuthority extends o
   // So, for some kinds of errors, we just retry for a while hoping it will go away.
   private static final int FAILURE_RETRY_COUNT = 5;
 
+  /** Cache manager. */
+  protected ICacheManager cacheManager = null;
+  
   // Livelink does not have "deny" permissions, and there is no such thing as a document with no tokens, so it is safe to not have a local "deny" token.
   // However, people feel that a suspenders-and-belt approach is called for, so this restriction has been added.
   // Livelink tokens are numbers, "SYSTEM", or "GUEST", so they can't collide with the standard form.
@@ -83,16 +86,21 @@ public class LivelinkAuthority extends o
   {
   }
 
-  /** Return the path for the UI interface JSP elements.
-  * These JSP's must be provided to allow the connector to be configured, and to
-  * permit it to present document filtering specification information in the UI.
-  * This method should return the name of the folder, under the <webapp>/connectors/
-  * area, where the appropriate JSP's can be found.  The name should NOT have a slash in it.
-  *@return the folder part
+  /** Set thread context.
+  */
+  public void setThreadContext(IThreadContext tc)
+    throws ManifoldCFException
+  {
+    super.setThreadContext(tc);
+    cacheManager = CacheManagerFactory.make(tc);
+  }
+  
+  /** Clear thread context.
   */
-  public String getJSPFolder()
+  public void clearThreadContext()
   {
-    return "livelink";
+    super.clearThreadContext();
+    cacheManager = null;
   }
 
   /** Connect.  The configuration parameters are included.
@@ -237,6 +245,43 @@ public class LivelinkAuthority extends o
   public AuthorizationResponse getAuthorizationResponse(String userName)
     throws ManifoldCFException
   {
+    // Construct a cache description object
+    ICacheDescription objectDescription = new AuthorizationResponseDescription(userName,serverName,serverPort,
+      serverUsername,serverPassword);
+    
+    // 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(userName);
+        // Save it in the cache
+        cacheManager.saveObject(createHandle,objectDescription,response);
+        // And return it...
+        return response;
+      }
+      finally
+      {
+        cacheManager.leaveCreateSection(createHandle);
+      }
+    }
+    finally
+    {
+      cacheManager.leaveCache(ch);
+    }
+  }
+  
+  /** Uncached method to get access tokens for a user name. */
+  public AuthorizationResponse getAuthorizationResponseUncached(String userName)
+    throws ManifoldCFException
+  {
     // First, do what's necessary to map the user name that comes in to a reasonable
     // Livelink domain\\user combination.
 
@@ -741,6 +786,77 @@ public class LivelinkAuthority extends o
 
   }
 
+  protected static long responseLifetime = 60000L;
+  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 user name associated with the access tokens */
+    protected String userName;
+    
+    // The server connection parameters
+    protected String serverName;
+    protected int serverPort;
+    protected String serverUsername;
+    protected String serverPassword;
+
+    /** The expiration time */
+    protected long expirationTime = -1;
+    
+    /** Constructor. */
+    public AuthorizationResponseDescription(String userName, String serverName, int serverPort,
+      String serverUsername, String serverPassword)
+    {
+      super("LiveLinkAuthority",LRUsize);
+      this.userName = userName;
+      this.serverName = serverName;
+      this.serverPort = serverPort;
+      this.serverUsername = serverUsername;
+      this.serverPassword = serverPassword;
+    }
+
+    /** 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 + "-" + serverName +
+        "-" + Integer.toString(serverPort) + "-" + serverUsername + "-" + serverPassword;
+    }
+
+    /** Return the object expiration interval */
+    public long getObjectExpirationTime(long currentTime)
+    {
+      if (expirationTime == -1)
+        expirationTime = currentTime + responseLifetime;
+      return expirationTime;
+    }
+
+    public int hashCode()
+    {
+      return userName.hashCode() + serverName.hashCode() + new Integer(serverPort).hashCode() +
+        serverUsername.hashCode() + serverPassword.hashCode();
+    }
+    
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof AuthorizationResponseDescription))
+        return false;
+      AuthorizationResponseDescription ard = (AuthorizationResponseDescription)o;
+      return ard.userName.equals(userName) && ard.serverName.equals(serverName) && arc.serverPort == serverPort &&
+        ard.serverUsername.equals(serverUsername) && ard.serverPassword.equals(serverPassword);
+    }
+    
+  }
+
 }