[sharepoint]根据用户名获取该用户的权限
生活随笔
收集整理的這篇文章主要介紹了
[sharepoint]根据用户名获取该用户的权限
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
寫在前面
這樣的一個場景,客戶端請求sharepoint的rest api,但不允許傳輸用戶的密碼,使用的是證書認證的方式,但這樣所有的用戶用的是同一個證書,這樣造成的結果就是無法識別該用戶是否有操作,及查詢的權限。這里是實際項目中遇到的一個問題。將解決方案,記錄一下。
解決方案
try{ClientContext spContext = new ClientContext("http://xxxx/xxx/xxx");spContext.ExecutingWebRequest += spContext_ExecutingWebRequest;var list = spContext.Web.Lists.GetByTitle("test");spContext.Load(list);spContext.ExecuteQuery();var permissions = list.GetUserEffectivePermissions(@"i:0#.w|domain\test15");spContext.ExecuteQuery();foreach (var permission in Enum.GetValues(typeof(PermissionKind)).Cast<PermissionKind>()){var permissionName = Enum.GetName(typeof(PermissionKind), permission);var hasPermission = permissions.Value.Has(permission);Debug.WriteLine("Permission: {0}, HasPermission: {1}", permissionName, hasPermission);}}catch (Exception){throw;}在回調方法中,帶上證書認證
void spContext_ExecutingWebRequest(object sender, WebRequestEventArgs e){HttpWebRequest webReq = e.WebRequestExecutor.WebRequest;var accessToken = TokenHelper.GetS2SAccessTokenWithWindowsIdentity(new Uri("http://xxx/xxx/xxxxx"), null);webReq.Method = "Post";webReq.Accept = "application/json;odata=verbose";webReq.Headers.Add("Authorization", "Bearer " + accessToken);}然后根據返回的權限,參考
SPBasePermissions 枚舉
根據該枚舉提供的值,判斷該用戶是否擁有權限。
轉載于:https://www.cnblogs.com/wolf-sun/p/4637126.html
總結
以上是生活随笔為你收集整理的[sharepoint]根据用户名获取该用户的权限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SDN,这一年都经历了什么
- 下一篇: iptables详细说明