gpt4 book ai didi

mobile - 如何将Active Directory objectGuid转换为可读的字符串?

转载 作者:行者123 更新时间:2023-12-04 05:07:31 44 4
gpt4 key购买 nike

我在用C#编写的Xamarin移动应用程序中使用Novell.Directory.Ldap

使用Novell,我能够使用域,用户名和密码对用户进行身份验证

LdapConnection.bind(username, password);

然后,我使用 sAMAccountName进行搜索,它等于提供的用户名。

完成所有这些工作(成功运行)之后,我需要获取用户的 objectGuid,以便可以查询使用该guid作为键的外部数据库。问题是,当我从 LdapSearchResults中获得向导时,它以某种方式进行了编码。而且我无法弄清楚如何获得该guid的可读字符串表示形式。

有人对此有更多信息吗?我会想象guid是以某种方式编码的,但是我不知道它是如何编码的。我试过了
System.Convert.FromBase64String 

那没有帮助。感谢您的帮助,如果可以再发布一些对您有所帮助的信息,请告诉我。
private void Login()
{
if (LOG.isInfoEnabled())
{
LOG.info("Attempting LDAP logon . . .");

if (LOG.isDebugEnabled())
{
LOG.debug("Host: " + this.ldapHost);
LOG.debug("Port: " + this.ldapPort);
LOG.debug("SearchBase: " + this.ldapSearchBase);
}
}

LdapConnection conn = new LdapConnection();

try
{
conn.Connect(this.ldapHost, this.ldapPort);

if (LOG.isDebugEnabled())
{
LOG.debug("connected?: " + conn.Connected.ToString());
}
}
catch (Exception e)
{
LOG.error("An exception occurred while attempting to connect to AD server!", e);

// INFORM USER ABOUT ERROR
authError(Resource.String.error_unknown);
}

if (!string.IsNullOrEmpty(this.editTextUserName.Text) && !string.IsNullOrEmpty(this.editTextPassword.Text))
{
// HIDE KEYBOARD
var imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(editTextPassword.WindowToken, HideSoftInputFlags.NotAlways);

// HIDE 'LOGON' BUTTON WHILE LOGGING ON
this.buttonLogin.Visibility = ViewStates.Invisible;

try
{
// PERFORM AUTHENTICATION
conn.Bind(this.userName, this.userPassword);

if (LOG.isDebugEnabled())
{
LOG.debug("conn.Bound?: " + conn.Bound);
}

if (conn.Bound)
{
if (LOG.isDebugEnabled())
{
LOG.debug("authentication successful");
}

string[] name = this.userName.Split('\\');
LOG.debug("name[0]: " + name[0]);
LOG.debug("name[1]: " + name[1]);

string filter = "(sAMAccountName=" + name[1] + ")";
string guid = "";

LdapSearchResults searchResults = conn.Search(
this.ldapSearchBase, // search base
LdapConnection.SCOPE_SUB, // search scope
filter, // filter
null, // attributes
false); // attributes only

while (searchResults.hasMore())
{
LdapEntry nextEntry = null;

try
{
nextEntry = searchResults.next();
guid = nextEntry.getAttribute("objectGUID").StringValue;
}
catch (LdapException e)
{
LOG.error("An exception occurred while attempting to get next search result!", e);
continue;
}
}

Intent intent = new Intent(this, typeof(DashboardActivity));
intent.PutExtra("guid", guid);

StartActivity(intent);
}
else
{
// INFORM USER ABOUT ERROR
authError(Resource.String.error_auth);
}
}
catch (LdapException ldape)
{
LOG.error("An exception occurred while attempting to authenticate user credentials!", ldape);

// INFORM USER ABOUT ERROR
authError(Resource.String.error_auth);
}
finally
{
conn.Disconnect();
}
}
else
{
conn.Disconnect();
}
}

最佳答案

我不确定Novell库是否以其他方式对其进行编码,但是System.DirectoryServices将GUID提供为字节数组。您可以使用System.Guid结构将其获取为可读的字符串:

new Guid((System.Byte[])this.GUID).ToString()

关于mobile - 如何将Active Directory objectGuid转换为可读的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18383843/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com