通过阅读 SAP 社区网络上的一篇旧博文,我发现了一些关于解析 MYSAPSSO2 登录令牌的用户名和系统 ID 的说明。
我很好奇是否有人偶然发现了一个 .NET 库来获取这些信息而无需自己编写。
注意:此方法有时会失败,具体取决于票证字符串的格式。
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;
}
您应该考虑使用 SAP SSO EXT Lib (SAPSSOEXT - (SAP note 1040335)) 来解析登录票据详细信息。它是 SAP 的官方标准库,用于解析 SAP/Portal 登录票据。它可用于 C、Java 和 .NET 应用程序。