我正在通过BO SDK(.NET)实现BusinessObjects的Web GUI,并需要一种方法来在多个用户之间持续存储和共享身份验证令牌。一个特定的业务需求是只有一次登录(在这种情况下是来自ActiveDirectory的服务帐户)。我最初登录后没有麻烦,然后通过首次登录生成的默认令牌执行后续登录。麻烦的是,当第二次尝试使用令牌登录时,令牌被覆盖。如何检查BusinessObjects SDK中是否存在EnterpriseSession标记
我需要一种方法来检查令牌是否有效,而不必完成一个完整的登录,覆盖原始的令牌值。我的计划是将令牌保存在缓存中,并在每个报告请求生成时通过WCF提供,只有在令牌值不再有效时才会重新生成令牌值。通过在OpenDocument url中将令牌作为查询字符串参数提供验证来完成每个报告的最终请求。
我可以使用以下代码通过令牌完成完整登录: //原始登录名 SessionMgr ses = new SessionMgr(); EnterpriseSession es = ses.Logon(user,pass,server,type);
//Get the token
LogonTokenMgr myToken = es.LogonTokenMgr;
string BOToken = myToken.DefaultToken;
//Login with the generated token
EnterpriseSession esToken = ses.LogonWithToken(BOToken);
我无法找到将原始标记作为参数并确定它是否与有效的BusinessObjects会话关联的方法。在每次登录时覆盖令牌(使用LogonWithToken方法时发生)不是一种选择,因为它是一个多用户环境,并且覆盖会使前一个令牌/会话无效,如果用户依赖无效令牌。
有没有人知道BO SDK库中的方法将检查令牌的有效性而不覆盖它?我可以访问所有以堆栈附带的DLL文件...
UPDATE:
由于SDK似乎缺少了用于验证令牌的专用方法,我创建了一个工作HACK。创建一个有效的令牌后,我将其存入缓存中,并在随后的调用中通过尝试从缓存的令牌初始化EnterpriseSession来“验证”它。如果会话创建失败,则认为令牌无效,并生成一个新的令牌并将其返回给缓存服务进行存储(对不起,如果格式设置关闭 - 我是新来的降价):
希望有人创建这个问题的“真正的”解决方案,但以下代码运行良好:
public static class BusinessObjectsAuth
{
public static string GetBOToken (string currentToken = null)
{
if (!ValidateToken(currentToken))
{
//This is aprt a custom encryption piece - needed unless you are comfortable storing pw in plain text in config file
Crypt decrypter = new Crypt();
//Generate a new token
SessionMgr ses = new SessionMgr();
EnterpriseSession es = ses.Logon(AppSettings.BusinessObjectsUser, decrypter.DecryptString(AppSettings.BusinessObjectsPass), AppSettings.BusinessObjectsUrl, "secWinAD");
LogonTokenMgr myToken = es.LogonTokenMgr;
//The token generated below is good on any client for an unlimited number of logins for 24 hours
//This may or may not be a good idea based on the security of your network
return myToken.CreateLogonTokenEx("", 1440, -1);
}
else
{
//If the token is still valild return it
return currentToken;
}
}
public static bool ValidateToken(string currentToken = null)
{
SessionMgr ses = new SessionMgr();
try
{
//Check to see if the token can be used for logon - close the session afterwards
EnterpriseSession es = ses.LogonWithToken(currentToken);
es.Logoff();
return true;
}
catch (Exception ex)
{
//This is a workaround for the fact that the BO SDK does not include a built in method for verifying
//that a token is valid - we can only assume it's a bad token if the logon attempt in the try block fails
string message = ex.Message;
return false;
}
}
}
为什么你需要在用户之间共享认证? – craig
这是商业伙伴的直接要求。他们希望为用户删除对BO的访问权限,以便他们被迫使用我们的集中式报告门户(我们从BO,SSRS,Sharepoint等整合报告),使其更易于捕获使用情况并执行准确的资源规划。 – Tuck
我的一个客户有类似的要求,但他们想保留用户ID(用户ID需要支持行级安全)。 – craig