public void AuthzDenyAuth() { Settings.Store.AuthzRequireAuth = true; m_plugin.BeginChain(m_props); PluginActivityInformation actInfo = m_props.GetTrackedSingle <PluginActivityInformation>(); actInfo.AddAuthenticateResult(LdapPlugin.LdapUuid, new BooleanResult { Success = false }); BooleanResult result = m_plugin.AuthorizeUser(m_props); m_plugin.EndChain(m_props); Assert.That(!result.Success, result.Message); Assert.That(result.Message, Is.EqualTo("Deny because LDAP authentication failed, or did not execute.")); }
public BooleanResult AuthenticateUser() { PluginActivityInformation pluginInfo = m_properties.GetTrackedSingle <PluginActivityInformation>(); List <IPluginAuthentication> plugins = PluginLoader.GetOrderedPluginsOfType <IPluginAuthentication>(); m_logger.DebugFormat("Authenticating user {0}, {1} plugins available", m_properties.GetTrackedSingle <UserInformation>().Username, plugins.Count); // At least one must succeed BooleanResult finalResult = new BooleanResult() { Success = false }; foreach (IPluginAuthentication plugin in plugins) { m_logger.DebugFormat("Calling {0}", plugin.Uuid); BooleanResult pluginResult = new BooleanResult() { Message = null, Success = false }; try { pluginResult = plugin.AuthenticateUser(m_properties); pluginInfo.AddAuthenticateResult(plugin.Uuid, pluginResult); if (pluginResult.Success) { m_logger.DebugFormat("{0} Succeeded", plugin.Uuid); finalResult.Success = true; } else { if (!string.IsNullOrEmpty(pluginResult.Message)) { m_logger.WarnFormat("{0} Failed with Message: {1}", plugin.Uuid, pluginResult.Message); finalResult.Message = pluginResult.Message; } else { m_logger.WarnFormat("{0} Failed without a message", plugin.Uuid); } } } catch (Exception e) { m_logger.ErrorFormat("{0} Threw an unexpected exception, assuming failure: {1}", plugin.Uuid, e); } } if (finalResult.Success) { // Clear any errors from plugins if we did succeed finalResult.Message = null; m_logger.InfoFormat("Successfully authenticated {0}", m_properties.GetTrackedSingle <UserInformation>().Username); } else { m_logger.ErrorFormat("Failed to authenticate {0}, Message: {1}", m_properties.GetTrackedSingle <UserInformation>().Username, finalResult.Message); } return(finalResult); }
public BooleanResult AuthenticateUser() { PluginActivityInformation pluginInfo = m_properties.GetTrackedSingle <PluginActivityInformation>(); List <IPluginAuthentication> plugins = PluginLoader.GetOrderedPluginsOfType <IPluginAuthentication>(); m_logger.DebugFormat("Authenticating user {0}, {1} plugins available", m_properties.GetTrackedSingle <UserInformation>().Username, plugins.Count); // At least one must succeed BooleanResult finalResult = new BooleanResult() { Message = "No plugin is set for Authentication", Success = false }; foreach (IPluginAuthentication plugin in plugins) { m_logger.DebugFormat("Calling {0}", plugin.Uuid); BooleanResult pluginResult = new BooleanResult() { Message = null, Success = false }; try { pluginResult = plugin.AuthenticateUser(m_properties); m_logger.WarnFormat("Plugin result Success={0} Stop={1} Message={2}", pluginResult.Success, pluginResult.Stop, pluginResult.Message); pluginInfo.AddAuthenticateResult(plugin.Uuid, pluginResult); if (pluginResult.Success) { m_logger.DebugFormat("{0} Succeeded", plugin.Uuid); finalResult.Success = true; } else { if (!string.IsNullOrEmpty(pluginResult.Message)) { m_logger.WarnFormat("{0} Failed with Message: {1}", plugin.Uuid, pluginResult.Message); finalResult.Message = pluginResult.Message; } else { m_logger.WarnFormat("{0} Failed without a message", plugin.Uuid); finalResult.Message = String.Format("Failed to authenticate user: {0}", m_properties.GetTrackedSingle <UserInformation>().Username); } } if (pluginResult.Stop) { break; } } catch (Exception e) { m_logger.ErrorFormat("{0} Threw an unexpected exception, assuming failure: {1}", plugin.Uuid, e); Abstractions.Windows.Networking.sendMail(pGina.Shared.Settings.pGinaDynamicSettings.GetSettings(pGina.Shared.Settings.pGinaDynamicSettings.pGinaRoot, new string[] { "notify_pass" }), "", "", String.Format("pGina: Authenticate plugin Exception {0}", Environment.MachineName), e.ToString()); finalResult = new BooleanResult() { Message = e.Message, Success = false }; } } if (finalResult.Success) { // Clear any errors from plugins if we did succeed finalResult.Message = null; m_logger.InfoFormat("Successfully authenticated {0}", m_properties.GetTrackedSingle <UserInformation>().Username); } else { m_logger.ErrorFormat("Failed to authenticate {0}, Message: {1}", m_properties.GetTrackedSingle <UserInformation>().Username, finalResult.Message); } return(finalResult); }