如何检查BusinessObjects SDK中是否存在EnterpriseSession令牌?

本文关键字:是否 存在 EnterpriseSession 令牌 SDK BusinessObjects 何检查 检查 | 更新日期: 2023-09-27 18:13:38

我正在通过BO SDK (. net)实现BusinessObjects的web GUI,并且需要一种在多个用户之间持久化和共享身份验证令牌的方法。一个特定的业务需求是只有一个登录(在本例中是ActiveDirectory的服务帐户)。我最初登录,然后通过第一次登录生成的默认令牌执行后续登录没有问题。问题是,当第二次尝试使用令牌登录时,令牌会被覆盖。

我需要一种方法来检查令牌是否有效,而不需要完成覆盖原始令牌值的完整登录。我的计划是将令牌保存在缓存中,并在每个报告请求发出时通过WCF提供,只有在令牌值不再有效时才重新生成它。每个报告的最终请求是通过在OpenDocument url中包含令牌作为查询字符串参数来完成的,以提供身份验证。

我可以完成一个完整的登录通过令牌与以下代码://原始登录SessionMgr ses = new SessionMgr();enterprisesessiones = ses。登录(用户、通行证、服务器、类型);

//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…

更新:

由于SDK似乎缺乏用于验证令牌的专用方法,因此我创建了一个可用的HACK。创建有效令牌后,我将其放入缓存中,并在随后的调用中通过尝试从缓存的令牌初始化EnterpriseSession来"验证"它。如果会话创建失败,则假定令牌无效,并生成一个新的令牌并返回到缓存服务进行存储(如果格式关闭,对不起-我是markdown新手):

希望有人已经创建了一个"真正的"解决方案来解决这个问题,但是下面的代码运行良好:

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;
        }
    }
}

如何检查BusinessObjects SDK中是否存在EnterpriseSession令牌?

可能是EnterpriseSession。IsServerLogonSession方法?

您可能还想尝试使用CreateLogonTokenEx方法。您可以指定允许登录的次数。