Author: kwright
Date: Sun Oct 13 15:57:47 2013
New Revision: 1531700
URL: http://svn.apache.org/r1531700
Log:
Hook up health check function
Added:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SPSProxyHelper.java
(with props)
Modified:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SPSProxyHelper.java
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
Added:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SPSProxyHelper.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SPSProxyHelper.java?rev=1531700&view=auto
==============================================================================
---
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SPSProxyHelper.java
(added)
+++
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SPSProxyHelper.java
Sun Oct 13 15:57:47 2013
@@ -0,0 +1,506 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.manifoldcf.authorities.authorities.sharepoint;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.*;
+
+import java.io.InputStream;
+
+import javax.xml.soap.*;
+
+import org.apache.manifoldcf.core.common.XMLDoc;
+import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
+import org.apache.manifoldcf.agents.interfaces.ServiceInterruption;
+import org.apache.manifoldcf.authorities.system.Logging;
+
+import com.microsoft.schemas.sharepoint.dsp.*;
+import com.microsoft.schemas.sharepoint.soap.*;
+
+import org.apache.http.client.HttpClient;
+
+import org.apache.axis.EngineConfiguration;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.AxisEngine;
+import org.apache.axis.ConfigurationException;
+import org.apache.axis.Handler;
+import org.apache.axis.WSDDEngineConfiguration;
+import org.apache.axis.components.logger.LogFactory;
+import org.apache.axis.deployment.wsdd.WSDDDeployment;
+import org.apache.axis.deployment.wsdd.WSDDDocument;
+import org.apache.axis.deployment.wsdd.WSDDGlobalConfiguration;
+import org.apache.axis.encoding.TypeMappingRegistry;
+import org.apache.axis.handlers.soap.SOAPService;
+import org.apache.axis.utils.Admin;
+import org.apache.axis.utils.Messages;
+import org.apache.axis.utils.XMLUtils;
+import org.w3c.dom.Document;
+
+/**
+*
+* @author Michael Cummings
+*
+*/
+public class SPSProxyHelper {
+
+
+ public static final String HTTPCLIENT_PROPERTY =
org.apache.manifoldcf.sharepoint.CommonsHTTPSender.HTTPCLIENT_PROPERTY;
+
+ private String serverUrl;
+ private String serverLocation;
+ private String decodedServerLocation;
+ private String baseUrl;
+ private String userName;
+ private String password;
+ private EngineConfiguration configuration;
+ private HttpClient httpClient;
+
+ /**
+ *
+ * @param serverUrl
+ * @param userName
+ * @param password
+ */
+ public SPSProxyHelper( String serverUrl, String serverLocation, String
decodedServerLocation, String userName, String password,
+ Class resourceClass, String configFileName, HttpClient httpClient )
+ {
+ this.serverUrl = serverUrl;
+ this.serverLocation = serverLocation;
+ this.decodedServerLocation = decodedServerLocation;
+ if (serverLocation.equals("/"))
+ baseUrl = serverUrl;
+ else
+ baseUrl = serverUrl + serverLocation;
+ this.userName = userName;
+ this.password = password;
+ this.configuration = new ResourceProvider(resourceClass,configFileName);
+ this.httpClient = httpClient;
+ }
+
+ /**
+ * Get the access tokens for a user principal.
+ */
+ public String[] getAccessTokens(String site )
+ throws ManifoldCFException
+ {
+ try
+ {
+ if ( site.compareTo("/") == 0 )
+ site = ""; // root case
+
+ UserGroupWS userService = new UserGroupWS( baseUrl + site, userName,
password, configuration, httpClient );
+ com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall =
userService.getUserGroupSoapHandler( );
+
+ // Temporary, so that the exceptions still get thrown
+ String userLogin = "xxx";
+
com.microsoft.schemas.sharepoint.soap.directory.GetUserInfoResponseGetUserInfoResult
userResp = userCall.getUserInfo( userLogin );
+ org.apache.axis.message.MessageElement[] userList = userResp.get_any();
+
+ // MHL
+
+ return new String[0];
+ }
+ catch (java.net.MalformedURLException e)
+ {
+ throw new ManifoldCFException("Bad SharePoint url: "+e.getMessage(),e);
+ }
+ catch (javax.xml.rpc.ServiceException e)
+ {
+ if (Logging.authorityConnectors.isDebugEnabled())
+ Logging.authorityConnectors.debug("SharePoint: Got a service exception
getting the acls for site "+site,e);
+ throw new ManifoldCFException("Service exception: "+e.getMessage(), e);
+ }
+ catch (org.apache.axis.AxisFault e)
+ {
+ if (e.getFaultCode().equals(new
javax.xml.namespace.QName("http://xml.apache.org/axis/","HTTP")))
+ {
+ org.w3c.dom.Element elem = e.lookupFaultDetail(new
javax.xml.namespace.QName("http://xml.apache.org/axis/","HttpErrorCode"));
+ if (elem != null)
+ {
+ elem.normalize();
+ String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
+ if (httpErrorCode.equals("404"))
+ {
+ // Page did not exist
+ if (Logging.authorityConnectors.isDebugEnabled())
+ Logging.authorityConnectors.debug("SharePoint: The page at
"+baseUrl+site+" did not exist");
+ throw new ManifoldCFException("The page at "+baseUrl+site+" did
not exist");
+ }
+ else if (httpErrorCode.equals("401"))
+ {
+ // User did not have permissions for this library to get the acls
+ if (Logging.authorityConnectors.isDebugEnabled())
+ Logging.authorityConnectors.debug("SharePoint: The user did not
have access to the usergroups service for "+baseUrl+site);
+ throw new ManifoldCFException("The user did not have access to the
usergroups service at "+baseUrl+site);
+ }
+ else if (httpErrorCode.equals("403"))
+ throw new ManifoldCFException("Http error "+httpErrorCode+" while
reading from "+baseUrl+site+" - check IIS and SharePoint security settings!
"+e.getMessage(),e);
+ else
+ throw new ManifoldCFException("Unexpected http error code
"+httpErrorCode+" accessing SharePoint at "+baseUrl+site+": "+e.getMessage(),e);
+ }
+ throw new ManifoldCFException("Unknown http error occurred:
"+e.getMessage(),e);
+ }
+ else if (e.getFaultCode().equals(new
javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/","Server")))
+ {
+ org.w3c.dom.Element elem = e.lookupFaultDetail(new
javax.xml.namespace.QName("http://schemas.microsoft.com/sharepoint/soap/","errorcode"));
+ if (elem != null)
+ {
+ elem.normalize();
+ String sharepointErrorCode =
elem.getFirstChild().getNodeValue().trim();
+ if (Logging.authorityConnectors.isDebugEnabled())
+ {
+ org.w3c.dom.Element elem2 = e.lookupFaultDetail(new
javax.xml.namespace.QName("http://schemas.microsoft.com/sharepoint/soap/","errorstring"));
+ String errorString = "";
+ if (elem != null)
+ errorString = elem2.getFirstChild().getNodeValue().trim();
+
+ Logging.authorityConnectors.debug("SharePoint: Getting usergroups
in site "+site+" failed with unexpected SharePoint error code
"+sharepointErrorCode+": "+errorString,e);
+ }
+ throw new ManifoldCFException("SharePoint server error code:
"+sharepointErrorCode);
+ }
+ if (Logging.authorityConnectors.isDebugEnabled())
+ Logging.authorityConnectors.debug("SharePoint: Unknown SharePoint
server error getting the acls for site "+site+" - axis fault =
"+e.getFaultCode().getLocalPart()+", detail = "+e.getFaultString(),e);
+
+ throw new ManifoldCFException("Unknown SharePoint server error:
"+e.getMessage());
+ }
+
+ if (e.getFaultCode().equals(new
javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/","Server.userException")))
+ {
+ String exceptionName = e.getFaultString();
+ if (exceptionName.equals("java.lang.InterruptedException"))
+ throw new
ManifoldCFException("Interrupted",ManifoldCFException.INTERRUPTED);
+ }
+
+ if (Logging.authorityConnectors.isDebugEnabled())
+ Logging.authorityConnectors.debug("SharePoint: Got an unknown remote
exception getting usergroups for "+site+" - axis fault =
"+e.getFaultCode().getLocalPart()+", detail = "+e.getFaultString(),e);
+ throw new ManifoldCFException("Remote procedure exception:
"+e.getMessage(), e);
+ }
+ catch (java.rmi.RemoteException e)
+ {
+ // We expect the axis exception to be thrown, not this generic one!
+ // So, fail hard if we see it.
+ if (Logging.authorityConnectors.isDebugEnabled())
+ Logging.authorityConnectors.debug("SharePoint: Got an unexpected
remote exception usergroups for site "+site,e);
+ throw new ManifoldCFException("Unexpected remote procedure exception:
"+e.getMessage(), e);
+ }
+ }
+
+ /**
+ *
+ * @return true if connection OK
+ * @throws java.net.MalformedURLException
+ * @throws javax.xml.rpc.ServiceException
+ * @throws java.rmi.RemoteException
+ */
+ public boolean checkConnection( String site )
+ throws ManifoldCFException
+ {
+ try
+ {
+ if (site.equals("/"))
+ site = "";
+
+ UserGroupWS userService = new UserGroupWS( baseUrl + site, userName,
password, configuration, httpClient );
+ com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall =
userService.getUserGroupSoapHandler( );
+
+ // Get the info for the admin user
+
com.microsoft.schemas.sharepoint.soap.directory.GetUserInfoResponseGetUserInfoResult
userResp = userCall.getUserInfo( userName );
+ org.apache.axis.message.MessageElement[] userList = userResp.get_any();
+
+ // MHL
+
+ return true;
+ }
+ catch (java.net.MalformedURLException e)
+ {
+ throw new ManifoldCFException("Bad SharePoint url: "+e.getMessage(),e);
+ }
+ catch (javax.xml.rpc.ServiceException e)
+ {
+ if (Logging.authorityConnectors.isDebugEnabled())
+ Logging.authorityConnectors.debug("SharePoint: Got a service exception
checking connection",e);
+ throw new ManifoldCFException("Service exception: "+e.getMessage(), e);
+ }
+ catch (org.apache.axis.AxisFault e)
+ {
+ if (e.getFaultCode().equals(new
javax.xml.namespace.QName("http://xml.apache.org/axis/","HTTP")))
+ {
+ org.w3c.dom.Element elem = e.lookupFaultDetail(new
javax.xml.namespace.QName("http://xml.apache.org/axis/","HttpErrorCode"));
+ if (elem != null)
+ {
+ elem.normalize();
+ String httpErrorCode = elem.getFirstChild().getNodeValue().trim();
+ if (httpErrorCode.equals("404"))
+ {
+ // Page did not exist
+ throw new ManifoldCFException("The site at "+baseUrl+site+" did
not exist");
+ }
+ else if (httpErrorCode.equals("401"))
+ throw new ManifoldCFException("User did not authenticate properly,
or has insufficient permissions to access "+baseUrl+site+": "+e.getMessage(),e);
+ else if (httpErrorCode.equals("403"))
+ throw new ManifoldCFException("Http error "+httpErrorCode+" while
reading from "+baseUrl+site+" - check IIS and SharePoint security settings!
"+e.getMessage(),e);
+ else
+ throw new ManifoldCFException("Unexpected http error code
"+httpErrorCode+" accessing SharePoint at "+baseUrl+site+": "+e.getMessage(),e);
+ }
+ throw new ManifoldCFException("Unknown http error occurred:
"+e.getMessage(),e);
+ }
+ else if (e.getFaultCode().equals(new
javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/","Server")))
+ {
+ org.w3c.dom.Element elem = e.lookupFaultDetail(new
javax.xml.namespace.QName("http://schemas.microsoft.com/sharepoint/soap/","errorcode"));
+ if (elem != null)
+ {
+ elem.normalize();
+ String sharepointErrorCode =
elem.getFirstChild().getNodeValue().trim();
+ org.w3c.dom.Element elem2 = e.lookupFaultDetail(new
javax.xml.namespace.QName("http://schemas.microsoft.com/sharepoint/soap/","errorstring"));
+ String errorString = "";
+ if (elem != null)
+ errorString = elem2.getFirstChild().getNodeValue().trim();
+
+ throw new ManifoldCFException("Accessing site "+site+" failed with
unexpected SharePoint error code "+sharepointErrorCode+": "+errorString,e);
+ }
+ throw new ManifoldCFException("Unknown SharePoint server error
accessing site "+site+" - axis fault = "+e.getFaultCode().getLocalPart()+",
detail = "+e.getFaultString(),e);
+ }
+
+ if (e.getFaultCode().equals(new
javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/envelope/","Server.userException")))
+ {
+ String exceptionName = e.getFaultString();
+ if (exceptionName.equals("java.lang.InterruptedException"))
+ throw new
ManifoldCFException("Interrupted",ManifoldCFException.INTERRUPTED);
+ }
+
+ throw new ManifoldCFException("Got an unknown remote exception accessing
site "+site+" - axis fault = "+e.getFaultCode().getLocalPart()+", detail =
"+e.getFaultString(),e);
+ }
+ catch (java.rmi.RemoteException e)
+ {
+ // We expect the axis exception to be thrown, not this generic one!
+ // So, fail hard if we see it.
+ throw new ManifoldCFException("Got an unexpected remote exception
accessing site "+site+": "+e.getMessage(),e);
+ }
+ }
+
+ /**
+ * SharePoint UserGroup Service Wrapper Class
+ */
+ protected static class UserGroupWS extends
com.microsoft.schemas.sharepoint.soap.directory.UserGroupLocator
+ {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2052484076803624502L;
+ private java.net.URL endPoint;
+ private String userName;
+ private String password;
+ private HttpClient httpClient;
+
+ public UserGroupWS ( String siteUrl, String userName, String password,
EngineConfiguration configuration, HttpClient httpClient )
+ throws java.net.MalformedURLException
+ {
+ super(configuration);
+ endPoint = new java.net.URL(siteUrl + "/_vti_bin/usergroup.asmx");
+ this.userName = userName;
+ this.password = password;
+ this.httpClient = httpClient;
+ }
+
+ public com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap
getUserGroupSoapHandler( )
+ throws javax.xml.rpc.ServiceException, org.apache.axis.AxisFault
+ {
+ com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoapStub _stub
= new
com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoapStub(endPoint,
this);
+ _stub.setPortName(getUserGroupSoapWSDDServiceName());
+ _stub.setUsername( userName );
+ _stub.setPassword( password );
+ _stub._setProperty( HTTPCLIENT_PROPERTY, httpClient );
+ return _stub;
+ }
+ }
+
+ /** Implementation of EngineConfiguration that we'll use to get the wsdd
file from a
+ * local resource.
+ */
+ protected static class ResourceProvider implements WSDDEngineConfiguration
+ {
+ private WSDDDeployment deployment = null;
+
+ private Class resourceClass;
+ private String resourceName;
+
+ /**
+ * Constructor setting the resource name.
+ */
+ public ResourceProvider(Class resourceClass, String resourceName)
+ {
+ this.resourceClass = resourceClass;
+ this.resourceName = resourceName;
+ }
+
+ public WSDDDeployment getDeployment() {
+ return deployment;
+ }
+
+ public void configureEngine(AxisEngine engine)
+ throws ConfigurationException
+ {
+ try
+ {
+ InputStream resourceStream =
resourceClass.getResourceAsStream(resourceName);
+ if (resourceStream == null)
+ throw new ConfigurationException("Resource not found:
'"+resourceName+"'");
+ try
+ {
+ WSDDDocument doc = new
WSDDDocument(XMLUtils.newDocument(resourceStream));
+ deployment = doc.getDeployment();
+
+ deployment.configureEngine(engine);
+ engine.refreshGlobalOptions();
+ }
+ finally
+ {
+ resourceStream.close();
+ }
+ }
+ catch (ConfigurationException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(e);
+ }
+ }
+
+ public void writeEngineConfig(AxisEngine engine)
+ throws ConfigurationException
+ {
+ // Do nothing
+ }
+
+ /**
+ * retrieve an instance of the named handler
+ * @param qname XXX
+ * @return XXX
+ * @throws ConfigurationException XXX
+ */
+ public Handler getHandler(QName qname) throws ConfigurationException
+ {
+ return deployment.getHandler(qname);
+ }
+
+ /**
+ * retrieve an instance of the named service
+ * @param qname XXX
+ * @return XXX
+ * @throws ConfigurationException XXX
+ */
+ public SOAPService getService(QName qname) throws ConfigurationException
+ {
+ SOAPService service = deployment.getService(qname);
+ if (service == null)
+ {
+ throw new ConfigurationException(Messages.getMessage("noService10",
+ qname.toString()));
+ }
+ return service;
+ }
+
+ /**
+ * Get a service which has been mapped to a particular namespace
+ *
+ * @param namespace a namespace URI
+ * @return an instance of the appropriate Service, or null
+ */
+ public SOAPService getServiceByNamespaceURI(String namespace)
+ throws ConfigurationException
+ {
+ return deployment.getServiceByNamespaceURI(namespace);
+ }
+
+ /**
+ * retrieve an instance of the named transport
+ * @param qname XXX
+ * @return XXX
+ * @throws ConfigurationException XXX
+ */
+ public Handler getTransport(QName qname) throws ConfigurationException
+ {
+ return deployment.getTransport(qname);
+ }
+
+ public TypeMappingRegistry getTypeMappingRegistry()
+ throws ConfigurationException
+ {
+ return deployment.getTypeMappingRegistry();
+ }
+
+ /**
+ * Returns a global request handler.
+ */
+ public Handler getGlobalRequest() throws ConfigurationException
+ {
+ return deployment.getGlobalRequest();
+ }
+
+ /**
+ * Returns a global response handler.
+ */
+ public Handler getGlobalResponse() throws ConfigurationException
+ {
+ return deployment.getGlobalResponse();
+ }
+
+ /**
+ * Returns the global configuration options.
+ */
+ public Hashtable getGlobalOptions() throws ConfigurationException
+ {
+ WSDDGlobalConfiguration globalConfig =
deployment.getGlobalConfiguration();
+
+ if (globalConfig != null)
+ return globalConfig.getParametersTable();
+
+ return null;
+ }
+
+ /**
+ * Get an enumeration of the services deployed to this engine
+ */
+ public Iterator getDeployedServices() throws ConfigurationException
+ {
+ return deployment.getDeployedServices();
+ }
+
+ /**
+ * Get a list of roles that this engine plays globally. Services
+ * within the engine configuration may also add additional roles.
+ *
+ * @return a <code>List</code> of the roles for this engine
+ */
+ public List getRoles()
+ {
+ return deployment.getRoles();
+ }
+ }
+
+}
Propchange:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SPSProxyHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SPSProxyHelper.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java?rev=1531700&r1=1531699&r2=1531700&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
(original)
+++
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
Sun Oct 13 15:57:47 2013
@@ -26,10 +26,33 @@ import org.apache.manifoldcf.authorities
import java.io.*;
import java.util.*;
+import java.net.*;
+import java.util.concurrent.TimeUnit;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.naming.directory.*;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.NTCredentials;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.DefaultRedirectStrategy;
+import org.apache.http.util.EntityUtils;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.protocol.HttpContext;
+
/** This is the Active Directory implementation of the IAuthorityConnector
interface.
* Access tokens for this connector are simple SIDs, except for the "global
deny" token, which
@@ -59,10 +82,54 @@ public class SharePointAuthority extends
/** Cache manager. */
private ICacheManager cacheManager = null;
+ /** The length of time in milliseconds that an connection remains idle
before expiring. Currently 5 minutes. */
+ private static final long ADExpirationInterval = 300000L;
+
+ /** Length of time that a SharePoint session can remain idle */
+ private static final long SharePointExpirationInterval = 300000L;
- /** The length of time in milliseconds that the connection remains idle
before expiring. Currently 5 minutes. */
- private static final long expirationInterval = 300000L;
+ // SharePoint server parameters
+ private String serverProtocol = null;
+ private String serverUrl = null;
+ private String fileBaseUrl = null;
+ private String userName = null;
+ private String strippedUserName = null;
+ private String password = null;
+ private String ntlmDomain = null;
+ private String serverName = null;
+ private String serverLocation = null;
+ private String encodedServerLocation = null;
+ private int serverPort = -1;
+
+ private SPSProxyHelper proxy = null;
+
+ private long sharepointSessionTimeout;
+
+ // SSL support
+ private String keystoreData = null;
+ private IKeystoreManager keystoreManager = null;
+
+ private ClientConnectionManager connectionManager = null;
+ private HttpClient httpClient = null;
+
+ // Current host name
+ private static String currentHost = null;
+ static
+ {
+ // Find the current host name
+ try
+ {
+ java.net.InetAddress addr = java.net.InetAddress.getLocalHost();
+
+ // Get hostname
+ currentHost = addr.getHostName();
+ }
+ catch (UnknownHostException e)
+ {
+ }
+ }
+
/** Constructor.
*/
public SharePointAuthority()
@@ -151,7 +218,7 @@ public class SharePointAuthority extends
public String check()
throws ManifoldCFException
{
- // Set up the basic session...
+ // Set up the basic AD session...
getSessionParameters();
// Clear the DC session info, so we're forced to redo it
for (Map.Entry<String,DCSessionInfo> sessionEntry : sessionInfo.entrySet())
@@ -163,6 +230,27 @@ public class SharePointAuthority extends
{
createDCSession(domainController);
}
+
+ // SharePoint check
+ getSharePointSession();
+ try
+ {
+ URL urlServer = new URL( serverUrl );
+ }
+ catch ( MalformedURLException e )
+ {
+ return "Illegal SharePoint url: "+e.getMessage();
+ }
+
+ try
+ {
+ proxy.checkConnection( "/" );
+ }
+ catch (ManifoldCFException e)
+ {
+ return e.getMessage();
+ }
+
return super.check();
}
@@ -180,7 +268,7 @@ public class SharePointAuthority extends
session = new DCSessionInfo();
sessionInfo.put(domainController,session);
}
- return session.getSession(domainController,parms);
+ return session.getADSession(domainController,parms);
}
/** Poll. The connection should be closed if it has been idle for too long.
@@ -194,16 +282,26 @@ public class SharePointAuthority extends
{
sessionEntry.getValue().closeIfExpired(currentTime);
}
+ if (proxy != null && System.currentTimeMillis() >=
sharepointSessionTimeout)
+ expireSharePointSession();
+ if (connectionManager != null)
+ connectionManager.closeIdleConnections(60000L,TimeUnit.MILLISECONDS);
super.poll();
}
-
/** Close the connection. Call this before discarding the repository
connector.
*/
@Override
public void disconnect()
throws ManifoldCFException
{
+ // Clean up caching parameters
+
+ cacheLifetime = null;
+ cacheLRUsize = null;
+
+ // Clean up AD parameters
+
hasSessionParameters = false;
// Close all connections
@@ -213,8 +311,28 @@ public class SharePointAuthority extends
}
sessionInfo = null;
- cacheLifetime = null;
- cacheLRUsize = null;
+ // Clean up SharePoint parameters
+
+ serverUrl = null;
+ fileBaseUrl = null;
+ userName = null;
+ strippedUserName = null;
+ password = null;
+ ntlmDomain = null;
+ serverName = null;
+ serverLocation = null;
+ encodedServerLocation = null;
+ serverPort = -1;
+
+ keystoreData = null;
+ keystoreManager = null;
+
+ proxy = null;
+ httpClient = null;
+ if (connectionManager != null)
+ connectionManager.shutdown();
+ connectionManager = null;
+
super.disconnect();
}
@@ -829,7 +947,149 @@ public class SharePointAuthority extends
}
}
+ protected void getSharePointSession()
+ throws ManifoldCFException
+ {
+ if (proxy == null)
+ {
+ String serverVersion = params.getParameter(
SharePointConfig.PARAM_SERVERVERSION );
+ if (serverVersion == null)
+ serverVersion = "2.0";
+ // Authority needs to do nothing with SharePoint version right now.
+
+ serverProtocol = params.getParameter(
SharePointConfig.PARAM_SERVERPROTOCOL );
+ if (serverProtocol == null)
+ serverProtocol = "http";
+ try
+ {
+ String serverPort = params.getParameter(
SharePointConfig.PARAM_SERVERPORT );
+ if (serverPort == null || serverPort.length() == 0)
+ {
+ if (serverProtocol.equals("https"))
+ this.serverPort = 443;
+ else
+ this.serverPort = 80;
+ }
+ else
+ this.serverPort = Integer.parseInt(serverPort);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ManifoldCFException(e.getMessage(),e);
+ }
+ serverLocation =
params.getParameter(SharePointConfig.PARAM_SERVERLOCATION);
+ if (serverLocation == null)
+ serverLocation = "";
+ if (serverLocation.endsWith("/"))
+ serverLocation = serverLocation.substring(0,serverLocation.length()-1);
+ if (serverLocation.length() > 0 && !serverLocation.startsWith("/"))
+ serverLocation = "/" + serverLocation;
+ encodedServerLocation = serverLocation;
+ serverLocation = decodePath(serverLocation);
+
+ userName = params.getParameter(SharePointConfig.PARAM_SERVERUSERNAME);
+ password =
params.getObfuscatedParameter(SharePointConfig.PARAM_SERVERPASSWORD);
+ int index = userName.indexOf("\\");
+ if (index != -1)
+ {
+ strippedUserName = userName.substring(index+1);
+ ntlmDomain = userName.substring(0,index);
+ }
+ else
+ {
+ strippedUserName = null;
+ ntlmDomain = null;
+ }
+
+ serverUrl = serverProtocol + "://" + serverName;
+ if (serverProtocol.equals("https"))
+ {
+ if (serverPort != 443)
+ serverUrl += ":" + Integer.toString(serverPort);
+ }
+ else
+ {
+ if (serverPort != 80)
+ serverUrl += ":" + Integer.toString(serverPort);
+ }
+
+ // Set up ssl if indicated
+ keystoreData =
params.getParameter(SharePointConfig.PARAM_SERVERKEYSTORE);
+
+ PoolingClientConnectionManager localConnectionManager = new
PoolingClientConnectionManager();
+ localConnectionManager.setMaxTotal(1);
+ connectionManager = localConnectionManager;
+
+ if (keystoreData != null)
+ {
+ keystoreManager = KeystoreManagerFactory.make("",keystoreData);
+ SSLSocketFactory myFactory = new
SSLSocketFactory(keystoreManager.getSecureSocketFactory(), new
BrowserCompatHostnameVerifier());
+ Scheme myHttpsProtocol = new Scheme("https", 443, myFactory);
+ connectionManager.getSchemeRegistry().register(myHttpsProtocol);
+ }
+
+ fileBaseUrl = serverUrl + encodedServerLocation;
+
+ BasicHttpParams params = new BasicHttpParams();
+ params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true);
+
params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,false);
+ params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,60000);
+ params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,900000);
+ params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS,true);
+ DefaultHttpClient localHttpClient = new
DefaultHttpClient(connectionManager,params);
+ // No retries
+ localHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler()
+ {
+ public boolean retryRequest(
+ IOException exception,
+ int executionCount,
+ HttpContext context)
+ {
+ return false;
+ }
+
+ });
+ localHttpClient.setRedirectStrategy(new DefaultRedirectStrategy());
+ if (strippedUserName != null)
+ {
+ localHttpClient.getCredentialsProvider().setCredentials(
+ new AuthScope(serverName,serverPort),
+ new NTCredentials(strippedUserName, password, currentHost,
ntlmDomain));
+ }
+
+ httpClient = localHttpClient;
+
+ proxy = new SPSProxyHelper( serverUrl, encodedServerLocation,
serverLocation, userName, password,
+ org.apache.manifoldcf.sharepoint.CommonsHTTPSender.class,
"sharepoint-client-config.wsdd",
+ httpClient );
+
+ }
+ sharepointSessionTimeout = System.currentTimeMillis() +
SharePointExpirationInterval;
+ }
+ protected void expireSharePointSession()
+ throws ManifoldCFException
+ {
+ serverUrl = null;
+ fileBaseUrl = null;
+ userName = null;
+ strippedUserName = null;
+ password = null;
+ ntlmDomain = null;
+ serverLocation = null;
+ encodedServerLocation = null;
+ serverPort = -1;
+
+ keystoreData = null;
+ keystoreManager = null;
+
+ proxy = null;
+ httpClient = null;
+ if (connectionManager != null)
+ connectionManager.shutdown();
+ connectionManager = null;
+ }
+
/** Obtain the DistinguishedName for a given user logon name.
*@param ctx is the ldap context to use.
*@param userName (Domain Logon Name) is the user name or identifier.
@@ -935,7 +1195,7 @@ public class SharePointAuthority extends
}
/** Initialize the session. */
- public LdapContext getSession(String domainControllerName,
DCConnectionParameters params)
+ public LdapContext getADSession(String domainControllerName,
DCConnectionParameters params)
throws ManifoldCFException
{
String authentication = params.getAuthentication();
@@ -1015,7 +1275,7 @@ public class SharePointAuthority extends
}
// Set the expiration time anew
- expiration = System.currentTimeMillis() + expirationInterval;
+ expiration = System.currentTimeMillis() + ADExpirationInterval;
return ctx;
}
@@ -1046,6 +1306,79 @@ public class SharePointAuthority extends
}
+ /** Decode a path item.
+ */
+ public static String pathItemDecode(String pathItem)
+ {
+ try
+ {
+ return
java.net.URLDecoder.decode(pathItem.replaceAll("\\%20","+"),"utf-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // Bad news, utf-8 not available!
+ throw new RuntimeException("No utf-8 encoding available");
+ }
+ }
+
+ /** Encode a path item.
+ */
+ public static String pathItemEncode(String pathItem)
+ {
+ try
+ {
+ String output = java.net.URLEncoder.encode(pathItem,"utf-8");
+ return output.replaceAll("\\+","%20");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // Bad news, utf-8 not available!
+ throw new RuntimeException("No utf-8 encoding available");
+ }
+ }
+
+ /** Given a path that is /-separated, and otherwise encoded, decode properly
to convert to
+ * unencoded form.
+ */
+ public static String decodePath(String relPath)
+ {
+ StringBuilder sb = new StringBuilder();
+ String[] pathEntries = relPath.split("/");
+ int k = 0;
+
+ boolean isFirst = true;
+ while (k < pathEntries.length)
+ {
+ if (isFirst)
+ isFirst = false;
+ else
+ sb.append("/");
+ sb.append(pathItemDecode(pathEntries[k++]));
+ }
+ return sb.toString();
+ }
+
+ /** Given a path that is /-separated, and otherwise unencoded, encode
properly for an actual
+ * URI
+ */
+ public static String encodePath(String relPath)
+ {
+ StringBuilder sb = new StringBuilder();
+ String[] pathEntries = relPath.split("/");
+ int k = 0;
+
+ boolean isFirst = true;
+ while (k < pathEntries.length)
+ {
+ if (isFirst)
+ isFirst = false;
+ else
+ sb.append("/");
+ sb.append(pathItemEncode(pathEntries[k++]));
+ }
+ return sb.toString();
+ }
+
/** Class describing a domain suffix and corresponding domain controller
name rule.
*/
protected static class DCRule
Modified:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SPSProxyHelper.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SPSProxyHelper.java?rev=1531700&r1=1531699&r2=1531700&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SPSProxyHelper.java
(original)
+++
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SPSProxyHelper.java
Sun Oct 13 15:57:47 2013
@@ -107,7 +107,7 @@ public class SPSProxyHelper {
* @return array of sids
* @throws Exception
*/
- public String[] getACLs(String site, String guid )
+ public String[] getACLs(String site, String guid, boolean
activeDirectoryAuthority )
throws ManifoldCFException, ServiceInterruption
{
long currentTime;
@@ -161,7 +161,7 @@ public class SPSProxyHelper {
{
// Use AD user or group
String userLogin = doc.getValue( node, "UserLogin" );
- String userSid = getSidForUser( userCall, userLogin );
+ String userSid = getSidForUser( userCall, userLogin,
activeDirectoryAuthority );
sids.add( userSid );
}
else
@@ -172,11 +172,11 @@ public class SPSProxyHelper {
if ( roleName.length() == 0)
{
roleName = doc.getValue(node,"GroupName");
- roleSids = getSidsForGroup(userCall, roleName);
+ roleSids = getSidsForGroup(userCall, roleName,
activeDirectoryAuthority);
}
else
{
- roleSids = getSidsForRole(userCall, roleName);
+ roleSids = getSidsForRole(userCall, roleName,
activeDirectoryAuthority);
}
int j = 0;
@@ -299,7 +299,7 @@ public class SPSProxyHelper {
* @throws ManifoldCFException
* @throws ServiceInterruption
*/
- public String[] getDocumentACLs(String site, String file)
+ public String[] getDocumentACLs(String site, String file, boolean
activeDirectoryAuthority)
throws ManifoldCFException, ServiceInterruption
{
long currentTime;
@@ -372,7 +372,7 @@ public class SPSProxyHelper {
{
// Use AD user or group
String userLogin = doc.getValue( node, "UserLogin" );
- String userSid = getSidForUser( userCall, userLogin );
+ String userSid = getSidForUser( userCall, userLogin,
activeDirectoryAuthority );
sids.add( userSid );
}
else
@@ -383,11 +383,11 @@ public class SPSProxyHelper {
if ( roleName.length() == 0)
{
roleName = doc.getValue(node,"GroupName");
- roleSids = getSidsForGroup(userCall, roleName);
+ roleSids = getSidsForGroup(userCall, roleName,
activeDirectoryAuthority);
}
else
{
- roleSids = getSidsForRole(userCall, roleName);
+ roleSids = getSidsForRole(userCall, roleName,
activeDirectoryAuthority);
}
int j = 0;
@@ -1295,10 +1295,14 @@ public class SPSProxyHelper {
* @return
* @throws Exception
*/
- private String
getSidForUser(com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap
userCall, String userLogin )
+ private String
getSidForUser(com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap
userCall, String userLogin,
+ boolean activeDirectoryAuthority)
throws ManifoldCFException, java.net.MalformedURLException,
javax.xml.rpc.ServiceException,
java.rmi.RemoteException
{
+ if (!activeDirectoryAuthority)
+ return "U"+userLogin;
+
com.microsoft.schemas.sharepoint.soap.directory.GetUserInfoResponseGetUserInfoResult
userResp = userCall.getUserInfo( userLogin );
org.apache.axis.message.MessageElement[] userList = userResp.get_any();
@@ -1334,9 +1338,13 @@ public class SPSProxyHelper {
* @return
* @throws Exception
*/
- private String[]
getSidsForGroup(com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap
userCall, String groupName)
+ private String[]
getSidsForGroup(com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap
userCall, String groupName,
+ boolean activeDirectoryAuthority)
throws ManifoldCFException, java.net.MalformedURLException,
javax.xml.rpc.ServiceException, java.rmi.RemoteException
{
+ if (!activeDirectoryAuthority)
+ return new String[]{"G"+groupName};
+
com.microsoft.schemas.sharepoint.soap.directory.GetUserCollectionFromGroupResponseGetUserCollectionFromGroupResult
roleResp = userCall.getUserCollectionFromGroup(groupName);
org.apache.axis.message.MessageElement[] roleList = roleResp.get_any();
@@ -1383,10 +1391,13 @@ public class SPSProxyHelper {
* @return
* @throws Exception
*/
- private String[] getSidsForRole(
com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall, String
roleName )
+ private String[] getSidsForRole(
com.microsoft.schemas.sharepoint.soap.directory.UserGroupSoap userCall, String
roleName,
+ boolean activeDirectoryAuthority)
throws ManifoldCFException, java.net.MalformedURLException,
javax.xml.rpc.ServiceException,
java.rmi.RemoteException
{
+ if (!activeDirectoryAuthority)
+ return new String[]{"R"+roleName};
com.microsoft.schemas.sharepoint.soap.directory.GetUserCollectionFromRoleResponseGetUserCollectionFromRoleResult
roleResp = userCall.getUserCollectionFromRole( roleName );
org.apache.axis.message.MessageElement[] roleList = roleResp.get_any();
Modified:
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java?rev=1531700&r1=1531699&r2=1531700&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
(original)
+++
manifoldcf/branches/CONNECTORS-754/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
Sun Oct 13 15:57:47 2013
@@ -88,6 +88,7 @@ public class SharePointRepository extend
private boolean supportsItemSecurity = false;
private boolean dspStsWorks = true;
private boolean attachmentsSupported = false;
+ private boolean activeDirectoryAuthority = true;
private String serverProtocol = null;
private String serverUrl = null;
@@ -150,6 +151,12 @@ public class SharePointRepository extend
supportsItemSecurity = !serverVersion.equals("2.0");
dspStsWorks = !serverVersion.equals("4.0");
attachmentsSupported = !serverVersion.equals("2.0");
+
+ String authorityType = params.getParameter(
SharePointConfig.PARAM_AUTHORITYTYPE );
+ if (authorityType == null)
+ authorityType = "ActiveDirectory";
+
+ activeDirectoryAuthority = authorityType.equals("ActiveDirectory");
serverProtocol = params.getParameter(
SharePointConfig.PARAM_SERVERPROTOCOL );
if (serverProtocol == null)
@@ -1034,7 +1041,7 @@ public class SharePointRepository extend
else
{
// Security on, is native
- accessTokens = proxy.getDocumentACLs( encodedSitePath,
encodePath(decodedDocumentPath) );
+ accessTokens = proxy.getDocumentACLs( encodedSitePath,
encodePath(decodedDocumentPath), activeDirectoryAuthority );
denyTokens = new String[]{defaultAuthorityDenyToken};
}
}
@@ -1266,7 +1273,7 @@ public class SharePointRepository extend
else
{
// Security enabled, native security
- accessTokens = proxy.getACLs( encodedSitePath, listID );
+ accessTokens = proxy.getACLs( encodedSitePath, listID,
activeDirectoryAuthority );
denyTokens = new String[]{defaultAuthorityDenyToken};
}
@@ -1601,7 +1608,7 @@ public class SharePointRepository extend
else
{
// Security enabled, native security
- accessTokens = proxy.getACLs( encodedSitePath, libID );
+ accessTokens = proxy.getACLs( encodedSitePath, libID,
activeDirectoryAuthority );
denyTokens = new String[]{defaultAuthorityDenyToken};
}