public virtual ActionResult addUser(AddUserModel user) { Authentication auth = new Authentication(); if (auth.isAdmin(this) || Authentication.DEBUG_bypassAuth) { if (ModelState.IsValid) { LDAPConnection newConnection = new LDAPConnection(); List <string> userInfo = newConnection.create(user.UserName); //Code here for creating TARSUser object; this will require // changing the LDAPConnection.create function to only // return the user information that is pertinent to TARS /* * var userEntry = new TARSUser(); * userEntry.userName = userInfo[1]; * TARSUserDB.TARSUserList.Add(userEntry); */ return(RedirectToAction("userMaintanence")); } return(View(user)); } else { return(View("error")); } }
static void Main(string[] args) { string username; string password; try { if (string.IsNullOrWhiteSpace(args[0]) == false || string.IsNullOrWhiteSpace(args[1]) == false) { username = args[0]; password = args[1]; } else { throw new Exception(); } using (var ldapConn = new LDAPConnection("LDAP://ldap.forumsys.com", username, password, AuthenticationTypes.Anonymous)) using (var ldapCMD = new LDAPCommand(ldapConn)) { ldapCMD.Parameters.Add(new LDAPParameter("uid", "einstein")); ldapCMD.Parameters.Add(new LDAPParameter("dc", "example")); ldapCMD.Parameters.Add(new LDAPParameter("dc", "com")); var sr = ldapCMD.FindOne(); } } catch (Exception) { Help(); return; } }
public void ShouldQueryActiveDirectory() { var ldap = new LDAPConnection(); Console.WriteLine("host: " + ldap.Host); Console.WriteLine("base: " + ldap.LDAPbase); Console.WriteLine("connection: " + ldap.LdapConnectionString); Console.WriteLine("ldap host: " + ldap.LDAPHost); Console.WriteLine("password" + ldap.Password); Console.WriteLine("port: " + ldap.Port); Console.WriteLine("username: "******"SearchBase: " + ldap.UserSearchBase); Console.WriteLine("a.pxlee DN: " + Apollo.CA.DirectoryServices.GetUserDNByID("a.pxlee")); //Console.WriteLine("auth: " + DirectoryServices.IsAuthenticated("a.pxlee", "abc")); //Console.WriteLine("ADAM Group count: " + (DirectoryServices.getADAMGroups("a.pxlee")).Count); }
public static bool IsValidCredentials(string domain, string localAddress, string usernameDomain, string username, SecureString password) { try { using (LDAPConnection ldapConnection = new LDAPConnection(domain, LDAP_PORT, localAddress)) { ldapConnection.Bind(usernameDomain, username, password); return true; } } catch { return false; } }
public virtual void DEBUG_SearchEntities(string inputValue, int expectedResultCount, string expectedEntityClaimValue) { if (!TestSearch) { return; } LDAPConnection coco = new LDAPConnection(); coco.EnableAugmentation = true; coco.GetGroupMembershipUsingDotNetHelpers = false; coco.UseSPServerConnectionToAD = false; coco.LDAPPath = "LDAP://test"; coco.LDAPUsername = "******"; Config.LDAPConnectionsProp.Add(coco); Config.Update(); UnitTestsHelper.TestSearchOperation(inputValue, expectedResultCount, expectedEntityClaimValue); }
public virtual void DEBUG_SearchEntities(string inputValue, int expectedResultCount, string expectedEntityClaimValue) { if (!TestSearch) { return; } LDAPConnection coco = new LDAPConnection(); coco.AugmentationEnabled = true; coco.GetGroupMembershipAsADDomain = false; coco.UserServerDirectoryEntry = false; coco.Path = "LDAP://test"; coco.Username = "******"; Config.LDAPConnectionsProp.Add(coco); Config.Update(); UnitTestsHelper.TestSearchOperation(inputValue, expectedResultCount, expectedEntityClaimValue); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { LDAPConnection check = new LDAPConnection(); if (ModelState.IsValid) { // if (check.requestUser(model.UserName, model.Password)) // { model.UserName = "******"; model.Password = "******"; model.RememberMe = false; TARSUserDBContext TARSUserDB = new TARSUserDBContext(); // TARSUserDB.TARSUserList.Find(model.UserName); //check for and save any updates to the user's info in active directory CheckForActiveDirectoryChanges(model); FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } // } /* else * { * ModelState.AddModelError("", "The user name or password provided is incorrect."); * } */ } // If we got this far, something failed, redisplay form return(View(model)); }
protected void grdLDAPConnections_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (ValidatePrerequisite() != ConfigStatus.AllGood) { return; } if (PersistedObject.LDAPConnectionsProp == null) { return; } GridViewRow rowToDelete = grdLDAPConnections.Rows[e.RowIndex]; Guid Id = new Guid(rowToDelete.Cells[0].Text); LDAPConnection connectionToRemove = PersistedObject.LDAPConnectionsProp.FirstOrDefault(x => x.Identifier == Id); if (connectionToRemove != null) { PersistedObject.LDAPConnectionsProp.Remove(connectionToRemove); CommitChanges(); ClaimsProviderLogging.Log($"LDAP server '{connectionToRemove.Directory}' was successfully removed from configuration '{PersistedObjectName}'", TraceSeverity.Medium, EventSeverity.Information, TraceCategory.Configuration); InitializeAugmentation(); PopulateLdapConnectionGrid(); } }
static DirectoryServices() { _ldapconn = new LDAPConnection( (NameValueCollection)ConfigurationManager.GetSection("Apollo.CA.DirectoryServices/LDAP.Connection")); _configDN = (NameValueCollection)ConfigurationManager.GetSection("Apollo.CA.DirectoryServices/AD.knownDNs"); _initialized = (_ldapconn != null && _ldapconn.Host.Length != 0 && _ldapconn.Username.Length != 0 && _ldapconn.UserSearchBase.Length != 0); if (!_initialized) { throw new ConfigurationErrorsException( "Could not initialize LDAP connection in static class DirectoryServices. Check web.config file settings."); } }