manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1520113 - /manifoldcf/integration/sharepoint-2007/branches/CONNECTORS-754/webservice/MCPermissions.cs
Date Wed, 04 Sep 2013 19:21:52 GMT
Author: kwright
Date: Wed Sep  4 19:21:52 2013
New Revision: 1520113

URL: http://svn.apache.org/r1520113
Log:
Remove requirement to call Permissions service.

Modified:
    manifoldcf/integration/sharepoint-2007/branches/CONNECTORS-754/webservice/MCPermissions.cs

Modified: manifoldcf/integration/sharepoint-2007/branches/CONNECTORS-754/webservice/MCPermissions.cs
URL: http://svn.apache.org/viewvc/manifoldcf/integration/sharepoint-2007/branches/CONNECTORS-754/webservice/MCPermissions.cs?rev=1520113&r1=1520112&r2=1520113&view=diff
==============================================================================
--- manifoldcf/integration/sharepoint-2007/branches/CONNECTORS-754/webservice/MCPermissions.cs
(original)
+++ manifoldcf/integration/sharepoint-2007/branches/CONNECTORS-754/webservice/MCPermissions.cs
Wed Sep  4 19:21:52 2013
@@ -41,6 +41,8 @@ namespace MetaCarta.SharePoint.SoapServe
         #region Private Fields
 
         private readonly string itemType = "Item";
+        private readonly string listType = "List";
+        private readonly string webType = "Web";
 
         #endregion
 
@@ -58,24 +60,19 @@ namespace MetaCarta.SharePoint.SoapServe
                 {
                     retVal = GetItemPermissions(objectName);
                 }
+                else if (objectType.Equals(listType))
+                {
+                    retVal = GetListPermissions(objectName);
+                }
+                else if (objectType.Equals(webType))
+                {
+                    retVal = GetWebPermissions(objectName);
+                }
                 else
                 {
-                    ServicePointManager.ServerCertificateValidationCallback +=
-                        new RemoteCertificateValidationCallback(ValidateCertificate);
-
-                    using (SPPermissionsService.Permissions service = new SPPermissionsService.Permissions())
-                    {
-                        service.Url = SPContext.Current.Web.Url + "/_vti_bin/Permissions.asmx";
-                        service.Credentials = System.Net.CredentialCache.DefaultCredentials;
-
-                        retVal = service.GetPermissionCollection(objectName, objectType);
-                    }
+                    throw new Exception("Unknown permission type: " + objectType);
                 }
             }
-            catch (SoapException soapEx)
-            {
-                throw soapEx;
-            }
             catch (Exception ex)
             {
                 EventLog.WriteEntry("MCPermissions.asmx", "Error: "+ex.Message+"; SPContext.Current.Web.Url='"+SPContext.Current.Web.Url+"'");
@@ -90,6 +87,42 @@ namespace MetaCarta.SharePoint.SoapServe
         #region Private Methods
 
         /// <summary>
+        /// Given the name of a list, return an XML fragment describing the set of permissions
+        /// for the specified list.
+        /// </summary>
+        /// <param name="itemName">A string containing the name of a list item</param>
+        /// <returns>An XML fragment</returns>
+        private XmlNode GetListPermissions(string listName)
+        {
+            if (string.IsNullOrEmpty(listName))
+                throw RaiseException("Parameter 'objectName' cannot be null or empty.", "2000",
"GetPermissionCollection");
+
+            using (SPWeb site = SPContext.Current.Web)
+            {
+                SPList item = site.GetList(listName);
+
+                return PopulateResponse(item);
+            }
+        }
+
+        /// <summary>
+        /// Given the current site, return an XML fragment describing the set of permissions
+        /// for the site.
+        /// </summary>
+        /// <param name="itemName">A string containing the name of a list item</param>
+        /// <returns>An XML fragment</returns>
+        private XmlNode GetWebPermissions(string siteName)
+        {
+            if (!siteName.Equals("/"))
+                throw RaiseException("Parameter 'objectName' must be /", "2000", "GetPermissionCollection");
+
+            using (SPWeb site = SPContext.Current.Web)
+            {
+                return PopulateResponse(site);
+            }
+        }
+        
+        /// <summary>
         /// Given the name of a list item, return an XML fragment describing the set of permissions
         /// for the specified list item.
         /// </summary>
@@ -97,8 +130,6 @@ namespace MetaCarta.SharePoint.SoapServe
         /// <returns>An XML fragment</returns>
         private XmlNode GetItemPermissions(string itemName)
         {
-            XmlNode retVal = null;
-
             if (string.IsNullOrEmpty(itemName))
                 throw RaiseException("Parameter 'objectName' cannot be null or empty.", "2000",
"GetPermissionCollection");
 
@@ -106,34 +137,39 @@ namespace MetaCarta.SharePoint.SoapServe
             {
                 SPListItem item = site.GetListItem(itemName);
 
-                if (item.RoleAssignments.Count > 0)
-                {
-                    XmlDocument doc = new XmlDocument();
-                    retVal = doc.CreateElement("GetPermissionCollection", 
-                        "http://schemas.microsoft.com/sharepoint/soap/directory/");
-                    XmlNode permissionsNode = doc.CreateElement("Permissions");
-
-                    // A list item can have one or more role assignments.  Each role assignment
-                    // represents a member (user or group) with one or more permissions.
 
-                    // The code below creates a Permission node for every member-permission
assignment.
-                    foreach (SPRoleAssignment assignment in item.RoleAssignments)
-                    {
-                        SPPrincipal member = assignment.Member;
+                return PopulateResponse(item);
+            }
+        }
 
-                        foreach (SPRoleDefinition roleDefinition in assignment.RoleDefinitionBindings)
-                        {
-                            XmlNode permissionNode = CreatePermissionNode(doc, member, roleDefinition);
-                            permissionsNode.AppendChild(permissionNode);
-                        }
+        private XmlNode PopulateResponse(SPSecurableObject item)
+        {
+            XmlNode retVal = null;
+            if (item.RoleAssignments.Count > 0)
+            {
+                XmlDocument doc = new XmlDocument();
+                retVal = doc.CreateElement("GetPermissionCollection", 
+                    "http://schemas.microsoft.com/sharepoint/soap/directory/");
+                XmlNode permissionsNode = doc.CreateElement("Permissions");
+
+                // A list item can have one or more role assignments.  Each role assignment
+                // represents a member (user or group) with one or more permissions.  
+                // The code below creates a Permission node for every member-permission assignment.
+                foreach (SPRoleAssignment assignment in item.RoleAssignments)
+                {
+                    SPPrincipal member = assignment.Member;
 
-                        retVal.AppendChild(permissionsNode);
+                    foreach (SPRoleDefinition roleDefinition in assignment.RoleDefinitionBindings)
+                    {
+                        XmlNode permissionNode = CreatePermissionNode(doc, member, roleDefinition);
+                        permissionsNode.AppendChild(permissionNode);
                     }
+
+                    retVal.AppendChild(permissionsNode);
                 }
             }
-
             return retVal;
         }
-
+        
         private XmlNode CreatePermissionNode(XmlDocument doc, SPPrincipal member, SPRoleDefinition
roleDefinition)
         {
             XmlNode retVal = doc.CreateElement("Permission");



Mime
View raw message