I am using Novell.Directory.Ldap in a Xamarin mobile application written in C #.
Using Novell, I can authenticate a user based on domain, username and password using
LdapConnection.bind(username, password);
Then I do a search using sAMAccountName , which is equivalent to the provided username.
After all this, which works successfully, I need to get the objectGuid user objectGuid that I can query external databases that use this guid as a key. The problem is that when I return the guid back to LdapSearchResults , it is somehow encoded. And I can't figure out how to get a readable string representation of this pointer.
Does anyone have more info on this? I would suggest that guid is encoded in some way, but I don’t know how it is encoded. I tried
System.Convert.FromBase64String
and it didn’t help. I appreciate the help guys let me know if I can post more information that would be helpful.
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(); } }