Пример #1
0
        /// <summary>
        /// Sets the authentication settings for the site
        /// </summary>
        /// /// <param name="server">The atype of server</param>
        /// <param name="site">The name of the site</param>
        /// <param name="appPath">The application path</param>
        /// <param name="settings">The authentication settings</param>
        protected void SetAuthentication(string server, string site, string appPath, AuthenticationSettings settings)
        {
            if (settings != null)
            {
                //Authentication
                var config = _Server.GetApplicationHostConfiguration();

                var locationPath   = site + appPath;
                var authentication = config.GetSection("system." + server + "/security/authorization", locationPath);



                // Anonymous Authentication
                var anonymousAuthentication = authentication.GetChildElement("anonymousAuthentication");

                anonymousAuthentication.SetAttributeValue("enabled", settings.EnableAnonymousAuthentication);

                _Log.Information("Anonymous Authentication enabled: {0}", settings.EnableAnonymousAuthentication);



                // Basic Authentication
                var basicAuthentication = authentication.GetChildElement("basicAuthentication");

                basicAuthentication.SetAttributeValue("enabled", settings.EnableBasicAuthentication);
                basicAuthentication.SetAttributeValue("userName", settings.Username);
                basicAuthentication.SetAttributeValue("password", settings.Password);

                _Log.Information("Basic Authentication enabled: {0}", settings.EnableBasicAuthentication);



                // Windows Authentication
                var windowsAuthentication = authentication.GetChildElement("windowsAuthentication");

                windowsAuthentication.SetAttributeValue("enabled", settings.EnableWindowsAuthentication);

                _Log.Information("Windows Authentication enabled: {0}", settings.EnableWindowsAuthentication);
            }
        }
Пример #2
0
        /// <summary>
        /// Sets the authentication settings for the site.
        /// </summary>
        /// <param name="config">The config object to adjust.</param>
        /// <param name="serverType">The type of the server.</param>
        /// <param name="site">The name of the site.</param>
        /// <param name="appPath">The application path.</param>
        /// <param name="settings">The authentication settings.</param>
        /// <param name="log">ICakeLog.</param>
        /// <returns></returns>
        public static Configuration SetAuthentication(this Configuration config, string serverType, string site, string appPath, AuthenticationSettings settings, ICakeLog log)
        {
            if (settings != null)
            {
                var locationPath = site + appPath;
                var sectionName  = $"system.{serverType}/security/authentication/";

                // Anonymous Authentication
                if (settings.EnableAnonymousAuthentication.HasValue)
                {
                    var anonymousAuthentication = config.GetSection(sectionName + "anonymousAuthentication", locationPath);

                    anonymousAuthentication.SetAttributeValue("enabled", settings.EnableAnonymousAuthentication.Value);

                    log.Information("Anonymous Authentication enabled: {0}", settings.EnableAnonymousAuthentication.Value);
                }

                // Basic Authentication
                if (settings.EnableBasicAuthentication.HasValue)
                {
                    var basicAuthentication = config.GetSection(sectionName + "basicAuthentication", locationPath);

                    basicAuthentication.SetAttributeValue("enabled", settings.EnableBasicAuthentication.Value);

                    if (settings.EnableBasicAuthentication.Value && !String.IsNullOrEmpty(settings.Username) && !String.IsNullOrEmpty(settings.Password))
                    {
                        basicAuthentication.SetAttributeValue("userName", settings.Username);
                        basicAuthentication.SetAttributeValue("password", settings.Password);
                    }

                    log.Information("Basic Authentication enabled: {0}", settings.EnableWindowsAuthentication.Value);
                }

                // Windows Authentication
                if (settings.EnableWindowsAuthentication.HasValue)
                {
                    var windowsAuthentication = config.GetSection(sectionName + "windowsAuthentication", locationPath);

                    windowsAuthentication.SetAttributeValue("enabled", settings.EnableWindowsAuthentication.Value);

                    log.Information("Windows Authentication enabled: {0}", settings.EnableWindowsAuthentication.Value);
                }
            }

            return(config);
        }
Пример #3
0
        /// <summary>
        /// Sets the authentication settings for the site.
        /// </summary>
        /// <param name="config">The config object to adjust.</param>
        /// <param name="serverType">The type of the server.</param>
        /// <param name="site">The name of the site.</param>
        /// <param name="appPath">The application path.</param>
        /// <param name="settings">The authentication settings.</param>
        /// <param name="log">ICakeLog.</param>
        /// <returns></returns>
        public static Configuration SetAuthentication(this Configuration config, string serverType, string site, string appPath, AuthenticationSettings settings, ICakeLog log)
        {
            if (settings != null)
            {
                var location    = site + appPath;
                var sectionName = "system." + serverType + "/security/authentication/{0}";

                // Anonymous Authentication
                if (settings.EnableAnonymousAuthentication.HasValue)
                {
                    var anonymousAuthentication = config.GetSection(string.Format(sectionName, "anonymousAuthentication"), location);
                    anonymousAuthentication["enabled"] = settings.EnableAnonymousAuthentication;

                    log.Information("Anonymous Authentication enabled: {0}", settings.EnableAnonymousAuthentication);
                }

                // Basic Authentication
                if (settings.EnableBasicAuthentication.HasValue)
                {
                    var basicAuthentication = config.GetSection(string.Format(sectionName, "basicAuthentication"), location);
                    basicAuthentication["enabled"] = settings.EnableBasicAuthentication;

                    log.Information("Basic Authentication enabled: {0}", settings.EnableBasicAuthentication);
                }

                // Windows Authentication
                if (settings.EnableWindowsAuthentication.HasValue)
                {
                    var windowsAuthentication = config.GetSection(string.Format(sectionName, "windowsAuthentication"), location);
                    windowsAuthentication["enabled"] = settings.EnableWindowsAuthentication;

                    log.Information("Windows Authentication enabled: {0}", settings.EnableWindowsAuthentication);
                }
            }
            return(config);
        }