SharePoint【学习笔记】-- SecureStoreProvider扩展:验证Application中是否有当前用户的credentials
2013-02-21 15:17
531 查看
Code Snippet: Get User Credentials Using the Default Secure Store Provider 中演示了如何获取当前用户的凭证信息,其中提到当GetCredentials获取不到值会抛异常SecureStoreServiceException,这个异常相当强大,不仅出现在ULS中,在Windows日志中也会出现Event 7493事件;
using (SecureStoreCredentialCollection creds = provider.GetCredentials(appId)) { // Secure Store Service will not return null. It may throw a SecureStoreServiceException, // but this may not be true for other providers.
================================================================================
Microsoft Secure Store Service 应用程序 Secure Store Service 无法检索凭据。返回的错误为“在目标应用程序“eam_79”中找不到当前用户的凭据。请为当前用户设置凭据。”。有关详细信息,请参阅 Microsoft SharePoint 产品和技术软件开发工具包(SDK)。
===============================================================
因此避免无凭证用户去请求变的很重要,解决的思路是直接查询SSS的数据库表[SSSCredentials],将ApplicationID与[IdentityClaimValueHash]字段匹配,如果返回值大于0就说明该用户在SSS中是有该Application的凭证的;其中IdentityClaimValueHash字段是通过Hash256加密的;
下面是关键代码:
1.获取用户的IdentityClaimValueHash
2.获取SSS的数据库ConnecetionString
/// <summary> /// 获取单点登录数据库连接字符串 /// </summary> /// <returns></returns> public static string GetSSSDataBaseStr() { string dbconstr = ""; bool islocalservice = false; foreach (SPServiceApplicationProxy pro in SPContext.Current.Site.WebApplication.ServiceApplicationProxyGroup.DefaultProxies) { string s = pro.GetType().ToString(); if (s == "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplicationProxy") { SPIisWebServiceApplicationProxy iispro = (SPIisWebServiceApplicationProxy)pro; Uri endpoint = iispro.ServiceEndpointUri; SecureStoreService svc = SPFarm.Local.Services.GetValue<SecureStoreService>(); foreach (SecureStoreServiceApplication app in svc.Applications) { //SecureStoreServiceDatabase db=app.GetPrivateProperty<SecureStoreServiceDatabase>("Database"); string svid1 = app.Id.ToString(); if (!islocalservice) { //ServiceEndpointUri {urn:schemas-microsoft-com:sharepoint:service:510a8bf612714e58a3077f0a1f09ac1d#authority=urn:uuid:3ff1d34f9e994f939ebee8df59ff77b5&authority=https://irene2010rtm:32844/Topology/topology.svc} islocalservice = endpoint.AbsolutePath.ToLower().EndsWith(svid1.ToLower().Replace("-", "")); if (islocalservice) { Type objectType = app.GetType(); BindingFlags flag = BindingFlags.Instance | BindingFlags.NonPublic; PropertyInfo WS = objectType.GetProperty("Database", flag); SecureStoreServiceDatabase db3 = (SecureStoreServiceDatabase)WS.GetValue(app, null); //writer.WriteLine(db3.Name + ":" + db3.DatabaseConnectionString); dbconstr=db3.DatabaseConnectionString; break; } } } } } return dbconstr; }
3.查询语句()
select a.ApplicationName,b.IdentityClaimValueHash from SSSApplication a,SSSCredentials b where a.ApplicationId=b.ApplicationId and a.ApplicationName='" + appName.Trim()+ "' and b.IdentityClaimValueHash=@binaryValue
相关文章推荐
- SecureStoreProvider扩展:验证Application中是否有当前用户的credentials
- shell脚本判断当前用户是否为root(学习笔记一)
- sharepoint 2010 验证用户组是否存在当前用户 IsCurrentUserMemberOfGroup
- SharePoint 验证用户组是否存在当前用户方法
- servlet学习笔记4——用户登录网站(数据库验证)
- 黑马程序员之C#编程基础学习笔记:提示用户输入年龄,如果大于等于18,则告知用户可以查看,如果小于10岁,则告知不允许查看,如果大于等于10岁,则提示用户是否继续查看(yes,no),如果输入的是ye
- SpringMVC学习笔记(五)验证用户输入
- 微信用户提现不能到账,显示NO_AUTH | 产品权限验证失败,请查看您当前是否具有该产品的权限(企业付款到零钱)
- SharePoint【用户访问控制】-- sharepoint 判断当前用户在当前页面是否有某项权限
- 用installshield 12打包时,检查当前用户是否为administrator用户的方法验证
- SharePoint【学习笔记】-- SharePoint 2010 利用JavaScript根据用户使用的语言应用不同的样式
- 无法在当前的 Active Directory 域中创建服务连接点。验证 SharePoint 容器是否存在于当前域中并验证您是否具有向其写入的权限。 Microsoft.SharePoint.SPException: 目录中不存在对象 LDAP://CN=Microsoft SharePoint
- 微信用户提现不能到账,显示NO_AUTH | 产品权限验证失败,请查看您当前是否具有该产品的权限
- 【学习笔记】--Java过滤器,用户登陆验证过滤等
- servlet学习笔记3——用户登录网站(通过session验证登陆用户)
- Sharepoint学习笔记--- 快速确定VisualStudio2010当前Project的assembly name
- asp.net2.0系统用户验证学习笔记
- 在Sharepoint 2013中,使用JS判断当前用户是否在某个组里面
- Ajax学习笔记-验证用户名是否可用
- MVC2 扩展Models和自定义验证(学习笔记)