我在用C#编写的Xamarin移动应用程序中使用Novell.Directory.Ldap
。如何将Active Directory objectGuid转换为可读的字符串?
使用Novell,我可以基于域名,用户名和密码的用户进行身份验证使用
LdapConnection.bind(username, password);
然后,我执行搜索,使用sAMAccountName
,这相当于提供的用户名。
毕竟,这成功的工作,我需要得到用户的objectGuid
,以便我可以查询外部数据库,使用该guid作为关键。问题是,当我从LdapSearchResults
得到guid时,它以某种方式编码。我无法弄清楚如何获得这个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();
}
}
你说你可以使用域和用户名绑定。你究竟如何格式化?我遇到了麻烦。在这里看到我的问题:http://stackoverflow.com/q/30773555/3799847 –