作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在用C#编写的Xamarin移动应用程序中使用Novell.Directory.Ldap
。
使用Novell,我能够使用域,用户名和密码对用户进行身份验证
LdapConnection.bind(username, password);
sAMAccountName
进行搜索,它等于提供的用户名。
objectGuid
,以便可以查询使用该guid作为键的外部数据库。问题是,当我从
LdapSearchResults
中获得向导时,它以某种方式进行了编码。而且我无法弄清楚如何获得该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/
我是一名优秀的程序员,十分优秀!