FBA və SQL Server: A Love Story

My colleague has been working on a web part in an FBA environment. Among other things, the web part pulls some data from SQL server. The grand plan for this project dictates that a DBA configures data level security in SQL (kimi bir SQL sorğu bir istifadəçi ID və ya başqa bir yanaşma daxilolma qarşı).

The problem is that SQL server doesn’t know anything about our FBA environment so it can’t trust us. We solved this problem by, daha yaxşı bir söz olmaması üçün, manually impersonating an AD user so that we could connect to SQL such that SQL data level security works.

FBA bir ASP.NET xüsusiyyət olsa da, biz SharePoint Nation nəfər müxtəlif axtarış motorları tədris ki, siz FBA üçün querying yapıyorsanız, you must mean you want know how to configure FBA in SharePoint. I failed to find find any information on how to enable an FBA oriented ASP.NET application to communicate with SQL in the way we needed.

Bu araşdırma zamanı, biz yenidən oxumaq bu maddənin: ASP.NET impersonation

Daha çox araşdırma bu codproject maddə bizi gətirib: http://www.codeproject.com/KB/cs/cpimpersonation1.aspx

Yəni bizim kodu yazmaq kömək, which I’ve included below. It’s not the most elegant stuff, lakin o, işləyib. I hope you find it helpful.

Burada bizim üçün çalışıb ki, kod:

müdafiə void btnSearchCarrier_Click(obyekt göndərən, EventArgs e)
 {
 cəhd
 {
 ImpersonateUser IU = yeni ImpersonateUser();
 // TODO: Etimadnaməsini dəyişdirin
 ("DomainName", "UserName", "Password");

//
 CODE
//

 iU.Undo();
 }
 tutmaq (Istisna ex)
 {

 }
 }

// Impersonation sinif istifadə edərək aşağıda qeyd.

ictimai sinfi ImpersonateUser
 {
 [DllImport("advapi32.dll", SetLastError = doğru)]
 ictimai statik extern bool LogonUser(
 String lpszUsername,
 String lpszDomain,
 String lpszPassword,
 int dwLogonType,
 int dwLogonProvider,
 ref IntPtr phToken);

 [DllImport("kernel32.dll", Charset = CharSet.Auto)]
 xüsusi extern statik bool CloseHandle(IntPtr qolu);

 xüsusi statik IntPtr tokenHandle = yeni IntPtr(0);
 xüsusi statik WindowsImpersonationContext impersonatedUser;

 // Bir DLL bu kodu daxil edin, ki, tələb əmin olun
 // FullTrust ilə çalışır.
 [PermissionSetAttribute(SecurityAction.Demand, = Adlandırın "FullTrust")]
 ictimai taklit ləğv(string domainName, string İstifadəçi adı, string unutdunuz)
 {
 cəhd
 {

 // Istifadəçi mö'cüzə almaq üçün yönetilmeyen LogonUser funksiyasından istifadə
 // Göstərilən istifadəçi, domain, və parol.
 İns int = LOGON32_PROVIDER_DEFAULT 0;

 // Bu parametr keçən LogonUser əsas mö'cüzə yaratmaq səbəb olur.
 İns int = LOGON32_LOGON_INTERACTIVE 2;
 tokenHandle = IntPtr.Zero;

 // Addım -1 Giriş mö'cüzə bir qolu almaq LogonUser zəng.
 bool returnValue = LogonUser(
 İstifadəçi adı,
 domainName,
 parol,
 LOGON32_LOGON_INTERACTIVE,
 LOGON32_PROVIDER_DEFAULT,
 ref tokenHandle); // tokenHandle - yeni təhlükəsizlik mö'cüzə

 əgər (yalan == returnValue)
 {
 int ret = Marshal.GetLastWin32Error();
 Console.WriteLine("LogonUser call failed with error code : " +
 islağa qoymaq);
 atmaq yeni System.ComponentModel.Win32Exception(islağa qoymaq);
 }

 // Addım - 2
 WindowsIdentity = newid yeni WindowsIdentity(tokenHandle);
 // Addım -3
 impersonatedUser = newId.Impersonate();

 }
 tutmaq (Istisna ex)
 {
 Console.WriteLine("Exception occurred. " + ex.Message);
 }
 }


 /// <xülasə>
 /// Impersonation dayandırır
 /// </xülasə>
 ictimai Al ləğv()
 {
 impersonatedUser.Undo();
 // Ayələrindən azad.
 əgər (tokenHandle != IntPtr.Zero)
 CloseHandle(tokenHandle);
 }
 }

</son>

Blog abunə.

Technorati Tags:

Bir fikir “FBA və SQL Server: A Love Story

  1. David Erkən
    Bu olmayan sual göndərmək üçün Bağışlayın, ancaq mən bu blog bir e-poçt göndərmək üçün necə anlamaq bilməz.
    You had a previous post where you offered a great way to filter a library to view untagged data. Do you have any thoughts as to how you might view a list of untagged documents in an entire document library? Using an empty field in advanced search does not return any results.
    Cavab

Şəkil Yükləmə

E-poçt ünvanından dərc olunmayacaq. Lazım alanlar qeyd olunur *