FBA અને SQL સર્વર: એ લવ સ્ટોરી

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 (તરીકે SQL ક્વેરી વપરાશકર્તા ID અથવા અમુક અન્ય અભિગમ એમ્બેડ વિરોધ).

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, એક સારી શબ્દ અભાવ માટે, manually impersonating an AD user so that we could connect to SQL such that SQL data level security works.

FBA એક ASP.NET લક્ષણ છે, તેમ છતાં, અમે શેરપોઈન્ટ નેશન લોકો વિવિધ શોધ એન્જિન શીખવવામાં છે કે તમે FBA માટે પ્રશ્ન પૂછવાના રહ્યાં છો, તો, 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.

આ સંશોધન દરમિયાન, અમે ફરી વાંચી આ લેખ: ASP.NET ઢોંગ

વધુ સંશોધન આ codproject લેખમાં અમને દોરી: http://www.codeproject.com/KB/cs/cpimpersonation1.aspx

કે અમને અમારી કોડ લખવા મદદ કરી, which I’ve included below. It’s not the most elegant stuff, પરંતુ તે કામ કર્યું. I hope you find it helpful.

અહીં અમારા માટે કામ કર્યું હતું કે કોડ છે:

રક્ષિત રદબાતલ btnSearchCarrier_Click(ઑબ્જેક્ટ પ્રેષક, EventArgs ઈ)
 {
 પ્રયત્ન કરવો
 {
 ImpersonateUser iu = નવું ImpersonateUser();
 // TODO: ઓળખાણપત્ર બદલો
 ("DomainName", "UserName", "Password");

//
 CODE
//

 iU.Undo();
 }
 ઝાલવું (અપવાદ ભૂતપૂર્વ)
 {

 }
 }

// ઢોંગ વર્ગ મદદથી નીચે ઉલ્લેખ કર્યો છે.

જાહેર વર્ગ ImpersonateUser
 {
 [DllImport("advapi32.dll", SetLastError = સાચું)]
 જાહેર સ્થિર extern bool LogonUser(
 શબ્દમાળા lpszUsername,
 શબ્દમાળા lpszDomain,
 શબ્દમાળા lpszPassword,
 ઈન્ dwLogonType,
 ઈન્ dwLogonProvider,
 પંચ IntPtr phToken);

 [DllImport("kernel32.dll", કેરસેટ = CharSet.Auto)]
 ખાનગી extern સ્થિર bool CloseHandle(IntPtr હેન્ડલ);

 ખાનગી સ્થિર IntPtr tokenHandle = નવું IntPtr(0);
 ખાનગી સ્થિર WindowsImpersonationContext impersonatedUser;

 // જો તમે DLL આ કોડને સમાવેશ નહિં, તે માગ ખાતરી કરો
 // FullTrust સાથે નહીં.
 [PermissionSetAttribute(SecurityAction.Demand, = Name "FullTrust")]
 જાહેર નકલ ગેરમાન્ય(સ્ટ્રિંગ DOMAINNAME, સ્ટ્રિંગ userName, સ્ટ્રિંગ પાસવર્ડ)
 {
 પ્રયત્ન કરવો
 {

 // માટે વપરાશકર્તા ટોકન મેળવવા માટે સંચાલન રહીત LogonUser કાર્ય ઉપયોગ કરો
 // ચોક્કસ વપરાશકર્તા, અધિકારક્ષેત્ર, અને પાસવર્ડ.
 const ઈન્ LOGON32_PROVIDER_DEFAULT = 0;

 // આ પરિમાણ પસાર LogonUser પ્રાથમિક ટોકન બનાવવા માટે માટેનું કારણ બને છે.
 const ઈન્ LOGON32_LOGON_INTERACTIVE = 2;
 tokenHandle = IntPtr.Zero;

 // પગલું -1 ઍક્સેસ ટોકન માટે હેન્ડલ મેળવવા માટે LogonUser કૉલ કરો.
 bool returnValue = LogonUser(
 userName,
 DOMAINNAME,
 પાસવર્ડ,
 LOGON32_LOGON_INTERACTIVE,
 LOGON32_PROVIDER_DEFAULT,
 સંદર્ભ tokenHandle); // tokenHandle - નવી સુરક્ષા ટોકન

 જો (ખોટા == returnValue)
 {
 ઈન્ Ret = Marshal.GetLastWin32Error();
 Console.WriteLine("LogonUser call failed with error code : " +
 Ret);
 ફેંકવું નવી System.ComponentModel.Win32Exception(Ret);
 }

 // પગલું - 2
 WindowsIdentity = newId નવું WindowsIdentity(tokenHandle);
 // પગલું -3
 impersonatedUser = newId.Impersonate();

 }
 ઝાલવું (અપવાદ ભૂતપૂર્વ)
 {
 Console.WriteLine("Exception occurred. " + ex.Message);
 }
 }


 /// <સારાંશ>
 /// ઢોંગ અટકાવે છે
 /// </સારાંશ>
 જાહેર પૂર્વવત્ કરો ગેરમાન્ય()
 {
 impersonatedUser.Undo();
 // ટોકનો મફત.
 જો (tokenHandle != IntPtr.Zero)
 CloseHandle(tokenHandle);
 }
 }

</અંત>

મારા બ્લોગ પર સબ્સ્ક્રાઇબ કરો.

Technorati ટૅગ્સ:

વન પર વિચાર્યું "FBA અને SQL સર્વર: એ લવ સ્ટોરી

  1. ડેવિડ પ્રારંભિક
    આ બિનસંબંધિત પ્રશ્ન પોસ્ટ માટે માફ કરશો, પરંતુ હું તમને આ બ્લોગ માંથી એક ઇમેઇલ મોકલવા માટે કેવી રીતે બહાર આકૃતિ શક્યા નથી.
    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.

જવાબ છોડો

તમારું ઇમેઇલ સરનામું પ્રકાશિત કરવામાં આવશે નહીં. જરૂરી ક્ષેત્રો ચિહ્નિત થયેલ છે *