2017-05-08 11 views
0

誰かが私のコードで私を助けることができますか?私は人のすべてのグループを照会するカスタム属性ストアが必要です。人のすべてのグループを照会するカスタム属性ストア

私は信用している当事者にアクセスしているユーザーのユーザー名を取得する方法がわかりません。

私のコードは次のようになります:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.DirectoryServices; 
using System.Threading.Tasks; 
using Microsoft.IdentityServer.ClaimsPolicy.Engine.AttributeStore; 
using System.IdentityModel; 


namespace GroupClaimAttributeStore 
{ 
    public class GroupClaimStore : IAttributeStore 
    { 
     public IAsyncResult BeginExecuteQuery(string query, string[] parameters, AsyncCallback callback, object state) 
     { 
      DirectorySearcher search = new DirectorySearcher(new DirectoryEntry("uk.svc.com") { AuthenticationType = AuthenticationTypes.Secure, Path = "LDAP://OU=staffusers,DC=leeds-art,DC=ac,DC=uk" }); 
      // get username 
      string username = string.Empty; 
      // set filter 
      search.Filter = "(cn=" + username + ")"; 

      SearchResult result = search.FindOne(); 
      search.PropertiesToLoad.Add("memberOf"); 

      List<string> outputValue = new List<string>(); 

      if (result != null) 
      { 
       ResultPropertyCollection fields = result.Properties; 
       var groups = fields["memberOf"]; 
       foreach (var group in groups) 
       { 
        outputValue.Add(group.ToString()); 
       } 
      } 

      TypedAsyncResult<string[]> asyncResult = new TypedAsyncResult<string[]>(callback, state); 
      asyncResult.Complete(outputValue.ToArray(), false); 
      return asyncResult; 
     } 

     public string[][] EndExecuteQuery(IAsyncResult result) 
     { 
      return TypedAsyncResult<string[][]>.End(result); 
     } 

     public void Initialize(Dictionary<string, string> config) 
     { 

     } 
    } 
} 

はありがとうございました!

答えて

0

これは、「トークングループ - 非修飾名」から「役割」にマッピングされたLDAPルールで実行できます。

それ以外の場合は、「username」というAD属性はありません。おそらく "sAMAccountName"が必要です。

関連する問題