使用.NET解析MYSAPSSO2登录令牌

时间:2012-08-13 20:21:48

标签: .net sap

通过SAP社区网络上的旧blog post读取,我找到了解析MYSAPSSO2登录令牌的用户名和系统ID的一些说明。

我很好奇是否有人偶然发现了一个.NET库来获取这些信息而无需编写我自己的信息。

2 个答案:

答案 0 :(得分:1)

注意:此方法会失败一些,具体取决于故障单字符串的格式。

void SetUserNameFromTicket1(string Ticket)         {             this.UserName = string.Empty;

        try
        {
            // Decoded Ticket "1100 \0portal:USERNAME1(char65533)\0basicauthentication\0\nUSERNAME2\0000\..."

            string TicketData = this.base64Decode(ticket);
            MessageBox.Show(strTicketData);
        }
        catch (Exception ex)
        {
            mobjLog.Debug("Exception in GetUserNameFromTicket: " + ex.Message);
        }
    }

    private string base64Decode(string data)
    {
        string result = string.Empty;
        try
        {
            data = System.Web.HttpUtility.UrlDecode(data); 
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();

            // if base64 were to be embedded in a URL, the use of the forward slash would be interpreted as a URL divider rather than
            // part of the base64. As a result, other characters such as dash (-), underscore (_), period
            // (.), colon (:) and exclamation point (!) are used in some implementations.
            // http://www.sans.org/reading_room/whitepapers/auditing/base64-pwned_33759
            // base64-pwned_33759.pdf
            data = data.Replace('-', '/');
            data = data.Replace('_', '/');
            data = data.Replace('.', '/');
            data = data.Replace(':', '/');
            data = data.Replace('!', '/');

            byte[] todecode_byte = Convert.FromBase64String(data);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            result = new String(decoded_char);
        }
        catch (Exception ex)
        {
            mobjLog.Debug("Error in base64Decode" + ex.Message);
        }

        return result;
    }

答案 1 :(得分:1)

您应该考虑使用SAP SSO EXT Lib(SAPSSOEXT - (SAP note 1040335))来解析登录故障单详细信息。它是SAP的官方标准库,用于解析SAP / Portal登录票证。它可以在C,Java和.NET应用程序中使用。

更多信息
SAP SSO Authentication with verify.pse using SAPSSOEXT

相关问题