Impersonating the “All Authenticated User” User in WSS/MOSS

Within WSS, items can be unsecured (available to the anonymous user), secured to specific users or groups, or generically secured to All Authenticated Users. If an item (or list) is accessible to All Authenticated Users, in most intranet cases it is a near equivalent to unsecured.

To impersonate a user, you must create a new SPSite object on behalf of the user and access items from within it’s security context. You cannot use the SPContext.Current scoped references of the SPSite or SPWeb. This is true whether you are impersonating an arbitrary user or are using SPSecurity.RunWithElevatedPRiveleges. To open an impersonated site, you would use the SPSite contructor that takes a site ID (GUID) and user token. Note that the user token is an opaque object that you get from WSS, and is implemented distinctly on Windows authenticated servers where the token represents AD group information, and on Forms authenticated servers where it simply stores the user ID.

// Summary (from the Microsoft.SharePoint.dll metadata):
//     Initializes a new instance of the Microsoft.SharePoint.SPSite class based
//     on the specified site collection GUID and user token.
// Parameters:
//   userToken:
//     A Microsoft.SharePoint.SPUserToken object that represents the user token.
//   id:
//     A GUID that specifies the site collection.
public SPSite(Guid id, SPUserToken userToken);

To get a token to impersonate, use the "AllUsers" property of the SPWeb. This group includes all users that WSS knows about in this site context. To get the All Authenticated Users user, use the following:

// Gets the All Authenticated Users SPUSer
SPUser spUser = SPContext.Current.Web.AllUsers[@"NT AUTHORITY\authenticated users"];

With this SPUser reference, you can now use its token to open an impersonated SPSite. Be sure to dispose of these objects as they were not created as part of the WSS Http pipeline.  

SPUserToken token = spUser.UserTooken;
using (SPSite impSite = new SPSite(SPContext.Current.Site.ID, token))
{/* …use the impersonated site context. */}

 *Note that I have not verified user impersonation with MOSS, as I’ve been focusing on cross-environment (WSS and MOSS) platform APIs lately. I’ve been getting a few comments that MOSS impersonation seems to work differently, so I will have to check into that! If you have code examples of impersonation using the MOSS framework additions please leave a comment and I’ll add a link.  

Read more: Page 372 of Inside Windows SharePoint Services

Technorati Tags: , , ,
This entry was posted in SharePoint. Bookmark the permalink.

31 Responses to Impersonating the “All Authenticated User” User in WSS/MOSS

  1. Unknown says:

    power leveling 老人ホーム 不動産担保ローン 人材派遣会社 転職 賃貸 オフィス 賃貸 事務所 貸事務所 語学留学 自己破産 リフォーム 出会い 出会い系 チャットレディー ETC インプラント レーシック 現金化 パワーストーン 葬儀 wow power leveling wow gold runescape power leveling runescape money rs gold runescape gold rolex watch wow gold wow power leveling

  2. Unknown says:

    ضحك,ليبيا,شباب ليبيا,احاديث نبوية,السيرة النبوية,برامج اسلامية,صوتيات اسلامية,خواطر,الشعر الشعبى,قصص,اللغات الاجنبية,تعلم الفرنسية,تعلم الانجليزية,الطب,تقنية الاسنان,كتب طبية,طب الاعشاب,اناقة وجمال,اناقة الرجال,الاسرة والمجتمع,الطبخات,اثاث وديكور,مقاطع كورة,الدوري الليبي,المصارعة,الكرة العربية,الكرة العالمية,الدوري الاسباني,الدوري الانجليزي,الدوري الايطالي,اخبار المشاهير,افلام اجنبية,مسلسلات اجنبية,تحميل افلام,افلام عربية,تحميل مسلسلات عربية,افلام كرتون,برامج,برامج الفيديو,اخبار التكنولوجيا,شبكات الحاسوب,تطوير المواقع,تطوير المنتديات,محادثة,صور,الفوتوشوب,برامج الفوتوشوب,التصميم,برامج الجوال,كليبات جوال,نغمات جوال,نغمات عربية,نغمات اسلامية,العاب الجوال,مسجات,الفضائيات,شفرات,كروت الساتلايت,الرسيفرات,خلفيات للجوال,نغمات اجنبية,برامج الجوال الجيل الثالث,ترحيب,games,مسجات ليبية مسجات رومانسية مسجات روعة مسجات حب مسجات عتاب مسجات جديدة مسجات ليبية رسائل رومانسية C.Ronaldo باب الحارة سنوات الضياع نكت youtubeمسلسل نور prison break 2 تحميل messi Kaka منتدى الكساد توم وجيري عدنان ولينا Youtube Download

Leave a comment