博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SecureStoreProvider扩展:验证Application中是否有当前用户的credentials
阅读量:5122 次
发布时间:2019-06-13

本文共 4441 字,大约阅读时间需要 14 分钟。

中演示了如何获取当前用户的凭证信息,其中提到当
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

///         /// 获取单点登录数据库连接字符串         ///         /// 
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
(); foreach (SecureStoreServiceApplication app in svc.Applications) { //SecureStoreServiceDatabase db=app.GetPrivateProperty
("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; }

以下代码作废

1: SPFarm farm = SPFarm.Local;
2:                    if (null == farm)
3:                    {
4:                        throw new InvalidProgramException("SP Farm Local Not Found");
5:                    }
6:                    SecureStoreService service = farm.Services.GetValue
();
7:                    if (null == service)
8:                    {
9:                        throw new InvalidProgramException("Proxy Creattion Failed Error");
10:                    }
11:                    SPServiceApplication application = service.Applications.ToList().SingleOrDefault();
12:                    if (application is SecureStoreServiceApplication)
13:                    {
14:                        SecureStoreServiceApplication secureStoreServiceApplication = application as SecureStoreServiceApplication;
15:                        string strconn=((Microsoft.SharePoint.Administration.SPDatabase)(secureStoreServiceApplication.Database)).ConnectionString;
16: 
17:                        Console.WriteLine(strconn);
18:                    }
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

转载于:https://www.cnblogs.com/ruijian/archive/2012/02/16/2355038.html

你可能感兴趣的文章
使用pygal_maps_world.i18n中数据画各大洲地图
查看>>
sql server必知多种日期函数时间格式转换
查看>>
jQuery EasyUI 的下拉选择combobox后台动态赋值
查看>>
timeline时间轴进度“群英荟萃”
查看>>
python if else elif statement
查看>>
网络编程
查看>>
文本隐藏(图片代替文字)
查看>>
java面试题
查看>>
提高码力专题(未完待续)
查看>>
pair的例子
查看>>
前端框架性能对比
查看>>
@property中 retain 详解
查看>>
uva 387 A Puzzling Problem (回溯)
查看>>
12.2日常
查看>>
同步代码时忽略maven项目 target目录
查看>>
MVC.NET:提供对字体文件.woff的访问
查看>>
Oracle中包的创建
查看>>
团队开发之个人博客八(4月27)
查看>>
发布功能完成
查看>>
【原】小程序常见问题整理
查看>>