/// <summary> /// Error Handling for LDAP Errors /// </summary> /// <param name="e"></param> protected override void ErrorHandler(Exception e) { if (e.Message.Contains("LDAP Result Code 200")) { VaultException ve = new VaultException("Problems Connecting to the LDAP Server", e); ve.SpecificErrorCode = EnumVaultExceptionCodes.LDAPLoginServerConnectionIssue; throw ve; } else if (e.Message.Contains("ldap operation failed")) { VaultException ve = new VaultException("Invalid username or password", e); ve.SpecificErrorCode = EnumVaultExceptionCodes.LDAPLoginCredentialsFailure; throw ve; } else { throw e; } }
/// <summary> /// Logs the user into the LDAP backend. /// <para>Throws a VaultInvalidaDataException if the login failed for any reason.</para> /// </summary> /// <param name="userName">The ldap user name that wants to login</param> /// <param name="password">The password for said user</param> /// <returns></returns> public async Task <LoginResponse> Login(string userName, string password) { string path = MountPointPath + "login/" + userName; JObject json = new JObject(); json.Add("password", password); try { VaultDataResponseObjectB vdro = await ParentVault._httpConnector.PostAsync_B(path, "LdapAuthEngine:Login", json.ToString()); if (vdro.Success) { return(await vdro.GetDotNetObject <LoginResponse>("auth")); } else { return(null); } } catch (Exception e) { if (e.Message.Contains("LDAP Result Code 200")) { VaultException ve = new VaultException("Problems Connecting to the LDAP Server", e); ve.SpecificErrorCode = EnumVaultExceptionCodes.LDAPLoginServerConnectionIssue; throw ve; } else if (e.Message.Contains("ldap operation failed")) { VaultException ve = new VaultException("Invalid username or password", e); ve.SpecificErrorCode = EnumVaultExceptionCodes.LDAPLoginCredentialsFailure; throw ve; } else { throw e; } } }