3

ASP.Net の MembershipProvider を使用して、特定のユーザーのみにアクセス権を付与しようとしています。これは、ADAM インスタンスによってバックアップされます。

私はうまく動作するいくつかのテストコードを使用します:

public static DataTable getADValuesByParameter(string strFilter, string strLDAPUser, string strLDAPPath, string strLDAPPWD, string strLDAPProperties)
        {
            DataTable functionReturnValue = default(DataTable);
            string[] arrLDAP = null;
            DirectoryEntry rootEntry = new DirectoryEntry();
            DirectorySearcher searcher = new DirectorySearcher();
            SearchResultCollection results = default(SearchResultCollection);
            DataTable dtExchangeUserData = new DataTable();
            arrLDAP = strLDAPProperties.Split(new char[] { ',' });
            rootEntry.Path = strLDAPPath;
            rootEntry.Username = strLDAPUser;
            rootEntry.Password = strLDAPPWD;
            rootEntry.AuthenticationType = AuthenticationTypes.Secure;

            searcher.SearchRoot = rootEntry;
            searcher.SearchScope = SearchScope.Subtree;
            searcher.Filter = strFilter;
            searcher.PropertiesToLoad.AddRange(arrLDAP);

            //var value = rootEntry.NativeObject;

            results = searcher.FindAll();
            Int16 si = default(Int16);
            foreach (SearchResult result in results)
            {
                si = 0;
                object[] arrKeyValue = new object[result.Properties.Count - 1];
                // -2 weil property "adspath" nicht dazu gehört, und .count -1 weil 0 basierendes array
                if ((result != null))
                {
                    System.Collections.IEnumerator myEnumerator = arrLDAP.GetEnumerator();
                    while (myEnumerator.MoveNext())
                    {
                        foreach (string Key in result.Properties.PropertyNames)
                        {
                            if (Key != "adspath")
                            {
                                if (Key.Equals(((string)myEnumerator.Current).ToLower()))
                                {
                                    if (dtExchangeUserData.Columns[Key] == null)
                                        dtExchangeUserData.Columns.Add(Key);
                                    if (Key.Equals("objectguid"))
                                    {
                                        arrKeyValue[si] = new Guid(((byte[])result.Properties[Key][0]));
                                    }
                                    else
                                    {
                                        arrKeyValue[si] = result.Properties[Key][0].ToString();
                                    }
                                    si++;
                                }
                            }
                        }
                    }
                    if (arrKeyValue.Length > 0)
                        dtExchangeUserData.Rows.Add(arrKeyValue);
                }
            }

            functionReturnValue = dtExchangeUserData;
            dtExchangeUserData.Dispose();
            rootEntry.Close();
            rootEntry.Dispose();
            return functionReturnValue;
        }

ここでは、ADAM に手動でクエリを実行します。コードの書き方は悪いですが、動作します。「AuthenticationTypes.Secure」の使い方に注意してください。

ここで、ActiveDirectoryMembershipProvider を使用して同じこと (同じ connectionPath、ユーザー名、パスワードなど) を実行しようとすると、次のようになります (ドイツ語から大まかに翻訳されています)。

ConfigurationErrorsException: SSL 経由で安全な接続を確立できません。

これは私が呼び出すときに起こります

Membership.ValidateUser()

Web.config ファイルの関連部分は次のとおりです。

<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://server.com/OU=users,DC=test,DC=adam"/>
</connectionStrings>
<authentication mode="Forms" >
      <forms loginUrl="~/Login.aspx/Test/" timeout="2880" />
    </authentication>
    <authorization>
      <deny users ="?" />
    </authorization>

    <!--<identity impersonate="true" />-->

    <trust level="Full" />

    <membership defaultProvider="MyMembershipProvider">
      <providers>
        <add name="MyMembershipProvider"
              type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
              connectionStringName="ADConnectionString"
              connectionUsername="[domain]\[user]"
              connectionPassword="[password]"
              connectionProtection="Secure"
              enableSearchMethods="true"
          />
        </providers>
    </membership>

偽装を使用するかどうかは問題ではありません (正直なところ、偽装が何をするものかはよくわかりません)。信頼レベルも何も変わりません。

代わりに connectionProtection="None" を使用すると、(再び翻訳された)「間違ったユーザー名またはパスワード」が表示されます。マニュアルの例で「AuthenticationTypes.None」を使用すると、同じエラーが発生します。

私は何を間違っていますか?

御時間ありがとうございます...

4

0 に答える 0