我在用Novell.Directory.Ldap
C# 编写的 Xamarin 移动应用程序中使用。
使用 Novell,我可以使用基于域、用户名和密码的用户身份验证
LdapConnection.bind(username, password);
然后,我使用sAMAccountName
等同于提供的用户名的 执行搜索。
毕竟这一切都成功了,我需要获取用户的objectGuid
,以便我可以查询使用该 guid 作为键的外部数据库。问题是,当我从 guid 中取回 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();
}
}