פבאַ און סקל סערווירער: א ליבע סטאָרי

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 (ווי קעגן צו עמבעדדינג אַ באַניצער שייַן אין אַ סקל אָנפֿרעג אָדער עטלעכע אנדערע צוגאַנג).

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.

אפילו כאָטש פבאַ איז אַ ASP.NET שטריך, מיר שאַרעפּאָינט נאַציאָן מענטשן האָבן געלערנט די פארשידענע זוכן ענדזשאַנז אַז אויב איר ניטאָ קוועריינג פֿאַר פבאַ, 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 ימפּערסאָנאַטיאָן

מער פאָרשונג געפירט אונדז צו דעם קאָדפּראָדזשעקט אַרטיקל: 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.

דאָ ס דער קאָד וואָס געארבעט פֿאַר אונדז:

פּראָטעקטעד פּאָסל בטנסעאַרטשקאַרריער_קליקק(כייפעץ סענדער, עווענטאַרגס E)
 {
 פּרובירן
 {
 ו = ימפּערסאָנאַטעוסער נייַ ימפּערסאָנאַטעוסער();
 // אַלע: Replace credentials
 iU.Impersonate("DomainName", "UserName", "Password");

//
 CODE
//

 iU.Undo();
 }
 כאַפּן (ויסנעם עקס)
 {

 }
 }

// Using Impersonation class as mentioned below.

עפנטלעך קלאַס ימפּערסאָנאַטעוסער
 {
 [DllImport("advapi32.dll", SetLastError = ריכטיק)]
 עפנטלעך סטאַטיק extern bool LogonUser(
 String lpszUsername,
 String lpszDomain,
 String lpszPassword,
 int dwLogonType,
 int dwLogonProvider,
 ref IntPtr phToken);

 [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
 פּריוואַט extern סטאַטיק bool CloseHandle(IntPtr handle);

 פּריוואַט סטאַטיק IntPtr tokenHandle = נייַ IntPtr(0);
 פּריוואַט סטאַטיק WindowsImpersonationContext impersonatedUser;

 // If you incorporate this code into a DLL, be sure to demand that it
 // runs with FullTrust.
 [PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
 עפנטלעך void Impersonate(string domainName, string userName, string password)
 {
 פּרובירן
 {

 // Use the unmanaged LogonUser function to get the user token for
 // the specified user, domain, and password.
 const int LOGON32_PROVIDER_DEFAULT = 0;

 // Passing this parameter causes LogonUser to create a primary token.
 const int LOGON32_LOGON_INTERACTIVE = 2;
 tokenHandle = IntPtr.Zero;

 // טרעטן -1 Call LogonUser to obtain a handle to an access token.
 bool returnValue = LogonUser(
 userName,
 domainName,
 password,
 LOGON32_LOGON_INTERACTIVE,
 LOGON32_PROVIDER_DEFAULT,
 ref tokenHandle); // tokenHandle - new security token

 צי (false == returnValue)
 {
 int ret = Marshal.GetLastWin32Error();
 קאָנסאָלע.ווריטעלינע("LogonUser call failed with error code : " +
 ret);
 וואַרפן new System.ComponentModel.Win32Exception(ret);
 }

 // טרעטן - 2
 WindowsIdentity newId = נייַ WindowsIdentity(tokenHandle);
 // טרעטן -3
 impersonatedUser = newId.Impersonate();

 }
 כאַפּן (ויסנעם עקס)
 {
 קאָנסאָלע.ווריטעלינע("Exception occurred. " + ex.Message);
 }
 }


 /// <קיצער>
 /// Stops impersonation
 /// </קיצער>
 עפנטלעך void Undo()
 {
 impersonatedUser.Undo();
 // Free the tokens.
 צי (tokenHandle != IntPtr.Zero)
 CloseHandle(tokenHandle);
 }
 }

</עק>

אַבאָנירן צו מיין בלאָג.

טעטשנאָראַטי טאַגס:

איינער געדאַנק אויף "פבאַ און סקל סערווירער: א ליבע סטאָרי

  1. דוד פרי
    Sorry for posting this unrelated question but I could not figure out how to send you an email from this blog.
    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.

לאָזן אַ ענטפֿערן

אייער בליצפּאָסט אַדרעס וועט ניט זיין ארויס. Required fields are marked *