我在用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 –