2017-05-08 5 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 규칙을 사용하여이를 수행 할 수 있습니다.

그렇지 않으면 "사용자 이름"이라는 AD 속성이 없습니다. "sAMAccountName"이 필요할 수도 있습니다.