2012-03-30 139 views
4

我的任務是處理涉及以下情形的一些SharePoint工作。從Active Directory中獲取用戶權限在SharePoint組中

在某些情況下,用戶處於活動目錄組,並且在某些情況下將AD組分配給SharePoint組。

我的問題是如何檢查SPUser的權限,如果用戶沒有直接分配到組/權限但實際上在Active Directory組中?我需要檢查用戶的權限級別。

例如:

用戶:用戶X 屬於AD組「SHAREPOINT_POWER_USERS」,這組具有「投稿」權限和屬於一個SharePoint組「IT支持組」。

有沒有辦法以編程方式檢索此用戶不存在於advaned權限或sharepoint組?我可以通過如下方式訪問:

//Pseudocode to access groups 
SPUser user = SPContext.Current.Web.CurrentUser; 
SPGroupCollection collection = user.Groups; 

請讓我知道這是如何工作的。

謝謝。

回答

0

你可以去對廣告本身,直接,得到會員的團體,如果他們是有權限的對象的成員的羣體之一,您授權(即顯示對象,等等。)。

嘗試:http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#39

public ArrayList Groups(string userDn, bool recursive) 
{ 
    ArrayList groupMemberships = new ArrayList(); 
    return AttributeValuesMultiString("memberOf", userDn, 
     groupMemberships, recursive); 
} 

public string AttributeValuesSingleString 
    (string attributeName, string objectDn) 
{ 
    string strValue; 
    DirectoryEntry ent = new DirectoryEntry(objectDn); 
    strValue = ent.Properties[attributeName].Value.ToString(); 
    ent.Close(); 
    ent.Dispose(); 
    return strValue; 
} 

public string GetObjectDistinguishedName(objectClass objectCls, 
    returnType returnValue, string objectName, string LdapDomain) 
{ 
    string distinguishedName = string.Empty; 
    string connectionPrefix = "LDAP://" + LdapDomain; 
    DirectoryEntry entry = new DirectoryEntry(connectionPrefix); 
    DirectorySearcher mySearcher = new DirectorySearcher(entry); 

    switch (objectCls) 
    { 
     case objectClass.user: 
      mySearcher.Filter = "(&(objectClass=user) 
     (|(cn=" + objectName + ")(sAMAccountName=" + objectName + ")))"; 
      break; 
     case objectClass.group: 
      mySearcher.Filter = "(&(objectClass=group) 
     (|(cn=" + objectName + ")(dn=" + objectName + ")))"; 
      break; 
     case objectClass.computer: 
      mySearcher.Filter = "(&(objectClass=computer) 
      (|(cn=" + objectName + ")(dn=" + objectName + ")))"; 
      break; 
    } 
    SearchResult result = mySearcher.FindOne(); 

    if (result == null) 
    { 
     throw new NullReferenceException 
     ("unable to locate the distinguishedName for the object " + 
     objectName + " in the " + LdapDomain + " domain"); 
    } 
    DirectoryEntry directoryObject = result.GetDirectoryEntry(); 
    if (returnValue.Equals(returnType.distinguishedName)) 
    { 
     distinguishedName = "LDAP://" + directoryObject.Properties 
      ["distinguishedName"].Value; 
    } 
    if (returnValue.Equals(returnType.ObjectGUID)) 
    { 
     distinguishedName = directoryObject.Guid.ToString(); 
    } 
    entry.Close(); 
    entry.Dispose(); 
    mySearcher.Dispose(); 
    return distinguishedName; 
} 
相關問題