예제 #1
0
		internal AuthConfig (object parent)
		{
			if (parent is AuthConfig) {
				has_parent = true;
				AuthConfig p = (AuthConfig) parent;
				mode = p.mode;
				cookieName = p.cookieName;
				cookiePath = p.cookiePath;
				loginUrl = p.loginUrl;
				protection = p.protection;
				timeout = p.timeout;
				pwdFormat = p.pwdFormat;
#if NET_1_1
				requireSSL = p.requireSSL;
				slidingExpiration = p.slidingExpiration;
#endif
#if NET_2_0
				cookie_domain = p.cookie_domain;
				cookie_mode = p.cookie_mode;
				cookies_supported = p.cookies_supported;
				default_url = p.default_url;
				enable_crossapp_redirects = p.enable_crossapp_redirects;
#endif
				credentialUsers = new Hashtable (p.CredentialUsers);
			}
		}
예제 #2
0
파일: AuthConfig.cs 프로젝트: raj581/Marvin
        internal AuthConfig(object parent)
        {
            if (parent is AuthConfig)
            {
                has_parent = true;
                AuthConfig p = (AuthConfig)parent;
                mode       = p.mode;
                cookieName = p.cookieName;
                cookiePath = p.cookiePath;
                loginUrl   = p.loginUrl;
                protection = p.protection;
                timeout    = p.timeout;
                pwdFormat  = p.pwdFormat;
#if NET_1_1
                requireSSL        = p.requireSSL;
                slidingExpiration = p.slidingExpiration;
#endif
#if NET_2_0
                cookie_domain             = p.cookie_domain;
                cookie_mode               = p.cookie_mode;
                cookies_supported         = p.cookies_supported;
                default_url               = p.default_url;
                enable_crossapp_redirects = p.enable_crossapp_redirects;
#endif
                credentialUsers = new Hashtable(p.CredentialUsers);
            }
        }
        public static void Initialize()
        {
            if (initialized)
            {
                return;
            }

            lock (locker)
            {
                if (initialized)
                {
                    return;
                }

                AuthenticationSection            section = (AuthenticationSection)WebConfigurationManager.GetSection(authConfigPath);
                FormsAuthenticationConfiguration config  = section.Forms;

                cookieName = config.Name;
#if NET_4_0
                Timeout = config.Timeout;
#endif
                timeout           = (int)config.Timeout.TotalMinutes;
                cookiePath        = config.Path;
                protection        = config.Protection;
                requireSSL        = config.RequireSSL;
                slidingExpiration = config.SlidingExpiration;
                cookie_domain     = config.Domain;
                cookie_mode       = config.Cookieless;
                cookies_supported = true; /* XXX ? */
#if NET_4_0
                if (!String.IsNullOrEmpty(default_url))
                {
                    default_url = MapUrl(default_url);
                }
                else
#endif
                default_url = MapUrl(config.DefaultUrl);
                enable_crossapp_redirects = config.EnableCrossAppRedirects;
#if NET_4_0
                if (!String.IsNullOrEmpty(login_url))
                {
                    login_url = MapUrl(login_url);
                }
                else
#endif
                login_url = MapUrl(config.LoginUrl);

                initialized = true;
            }
        }
예제 #4
0
		internal AuthConfig (object parent)
		{
			if (parent is AuthConfig) {
				has_parent = true;
				AuthConfig p = (AuthConfig) parent;
				mode = p.mode;
				cookieName = p.cookieName;
				cookiePath = p.cookiePath;
				loginUrl = p.loginUrl;
				protection = p.protection;
				timeout = p.timeout;
				pwdFormat = p.pwdFormat;
#if NET_1_1
				requireSSL = p.requireSSL;
				slidingExpiration = p.slidingExpiration;
#endif
				credentialUsers = new Hashtable (p.CredentialUsers);
			}
		}
예제 #5
0
 public static void Initialize()
 {
     if (!_Initialized)
     {
         lock (_lockObject)
         {
             if (!_Initialized)
             {
                 AuthenticationSection authentication = RuntimeConfig.GetAppConfig().Authentication;
                 authentication.ValidateAuthenticationMode();
                 _FormsName         = authentication.Forms.Name;
                 _RequireSSL        = authentication.Forms.RequireSSL;
                 _SlidingExpiration = authentication.Forms.SlidingExpiration;
                 if (_FormsName == null)
                 {
                     _FormsName = ".ASPXAUTH";
                 }
                 _Protection      = authentication.Forms.Protection;
                 _Timeout         = (int)authentication.Forms.Timeout.TotalMinutes;
                 _FormsCookiePath = authentication.Forms.Path;
                 _LoginUrl        = authentication.Forms.LoginUrl;
                 if (_LoginUrl == null)
                 {
                     _LoginUrl = "login.aspx";
                 }
                 _DefaultUrl = authentication.Forms.DefaultUrl;
                 if (_DefaultUrl == null)
                 {
                     _DefaultUrl = "default.aspx";
                 }
                 _CookieMode              = authentication.Forms.Cookieless;
                 _CookieDomain            = authentication.Forms.Domain;
                 _EnableCrossAppRedirects = authentication.Forms.EnableCrossAppRedirects;
                 _TicketCompatibilityMode = authentication.Forms.TicketCompatibilityMode;
                 _Initialized             = true;
             }
         }
     }
 }
예제 #6
0
        private void ReadFormsSettings(XmlNode node)
        {
            XmlNode tempAttr = HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "name", ref _CookieName);

            //Trace("FormsAuthConfigSettings::ReadSettings cookie name " + _CookieName);

            tempAttr = HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "loginUrl", ref _LoginUrl);
            if (tempAttr != null)
            {
                if (_LoginUrl.StartsWith("\\\\") || (_LoginUrl.Length > 1 && _LoginUrl[1] == ':'))
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Auth_bad_url),
                              tempAttr);
                }
            }
            //Trace("FormsAuthConfigSettings::ReadSettings login url " + _LoginUrl);

            int iTemp = 0;

            tempAttr = HandlerBase.GetAndRemoveEnumAttribute(node, "protection", typeof(FormsProtectionEnum), ref iTemp);
            if (tempAttr != null)
            {
                _Protection = (FormsProtectionEnum)iTemp;
            }

            tempAttr = HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "timeout", ref _Timeout);
            tempAttr = HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "path", ref _FormsCookiePath);
            HandlerBase.GetAndRemoveBooleanAttribute(node, "requireSSL", ref _RequireSSL);
            HandlerBase.GetAndRemoveBooleanAttribute(node, "slidingExpiration", ref _SlidingExpiration);
            HandlerBase.CheckForUnrecognizedAttributes(node);

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (child.Name != "credentials")
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }

                tempAttr = HandlerBase.GetAndRemoveEnumAttribute(child, "passwordFormat", typeof(FormsAuthPasswordFormat), ref iTemp);
                if (tempAttr != null)
                {
                    _PasswordFormat = (FormsAuthPasswordFormat)iTemp;
                    //Trace("FormsAuthConfigSettings::ReadSettings password format " + strTemp);
                }

                HandlerBase.CheckForUnrecognizedAttributes(child);

                foreach (XmlNode child2 in child.ChildNodes)
                {
                    if (child2.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (child2.Name != "user")
                    {
                        HandlerBase.ThrowUnrecognizedElement(child2);
                    }

                    string strUser = null;
                    string strPass = null;
                    tempAttr = HandlerBase.GetAndRemoveRequiredStringAttribute(child2, "name", ref strUser);
                    HandlerBase.GetAndRemoveRequiredStringAttribute(child2, "password", ref strPass);
                    HandlerBase.CheckForUnrecognizedAttributes(child2);
                    HandlerBase.CheckForChildNodes(child2);

                    //Trace("FormsAuthConfigSettings::ReadSettings adding user " + strUser + " " + strPass);
                    strUser = strUser.ToLower(CultureInfo.InvariantCulture);
                    String strPassInTable = (String)_Credentials[strUser];
                    if (strPassInTable == null)
                    {
                        _Credentials.Add(strUser, strPass);
                    }
                    else
                    {
                        if (String.Compare(strPassInTable, strPass, false, CultureInfo.InvariantCulture) != 0)
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.User_Already_Specified, strUser), tempAttr);
                        }
                    }
                }
            }
        }
예제 #7
0
        internal AuthenticationConfig(AuthenticationConfig parent, XmlNode section)
        {
            if (parent != null)
            {
                _CookieName        = parent.CookieName;
                _LoginUrl          = parent.LoginUrl;
                _PasswordFormat    = parent.PasswordFormat;
                _Credentials       = (Hashtable)parent.Credentials.Clone();
                _Mode              = parent.Mode;
                _PassportUrl       = parent.PassportUrl;
                _Protection        = parent.Protection;
                _FormsCookiePath   = parent.FormsCookiePath;
                _Timeout           = parent.Timeout;
                _RequireSSL        = parent.RequireSSL;
                _SlidingExpiration = parent.SlidingExpiration;
            }
            else
            {
                _Credentials = new Hashtable();
            }

            ////////////////////////////////////////////////////////////
            // Step 1: Read the mode
            int     iMode     = 0;
            XmlNode attribute = HandlerBase.GetAndRemoveEnumAttribute(section, "mode", typeof(AuthenticationMode), ref iMode);

            if (attribute != null)
            {
                _Mode = (AuthenticationMode)iMode;
                if (_Mode == AuthenticationMode.Passport && UnsafeNativeMethods.PassportVersion() < 0)
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Passport_not_installed),
                              attribute);
                }
            }
            HandlerBase.CheckForUnrecognizedAttributes(section);

            ////////////////////////////////////////////////////////////
            // Step 2: Read children nodes
            foreach (XmlNode child in section.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (child.Name == "forms")
                {
                    ReadFormsSettings(child);
                }
                else if (child.Name == "passport")
                {
                    attribute = child.Attributes.RemoveNamedItem("redirectUrl");
                    if (attribute != null)
                    {
                        _PassportUrl = attribute.Value;
                        if (_PassportUrl.StartsWith("\\\\") || (_PassportUrl.Length > 1 && _PassportUrl[1] == ':'))
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.Auth_bad_url),
                                      attribute);
                        }
                    }

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);
                }
                else
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Auth_unrecognized_tag, child.Name),
                              child);
                }
            }
        }
		public static void Initialize ()
		{
			if (initialized)
				return;

			lock (locker) {
				if (initialized)
					return;

				HttpContext context = HttpContext.Current;
				if (context == null)
					throw new HttpException ("Context is null!");

				AuthConfig authConfig = context.GetConfig (authConfigPath) as AuthConfig;
				if (authConfig != null) {
					cookieName = authConfig.CookieName;
					timeout = authConfig.Timeout;
					cookiePath = authConfig.CookiePath;
					protection = authConfig.Protection;
#if NET_1_1
					requireSSL = authConfig.RequireSSL;
					slidingExpiration = authConfig.SlidingExpiration;
#endif
				} else {
					cookieName = ".MONOAUTH";
					timeout = 30;
					cookiePath = "/";
					protection = FormsProtectionEnum.All;
#if NET_1_1
					slidingExpiration = true;
#endif
				}

				// IV is 8 bytes long for 3DES
				init_vector = new byte [8];
				int len = cookieName.Length;
				for (int i = 0; i < 8; i++) {
					if (i >= len)
						break;

					init_vector [i] = (byte) cookieName [i];
				}

				initialized = true;
			}
		}
 public static void Initialize()
 {
     if (!_Initialized)
     {
         lock (_lockObject)
         {
             if (!_Initialized)
             {
                 AuthenticationSection authentication = RuntimeConfig.GetAppConfig().Authentication;
                 authentication.ValidateAuthenticationMode();
                 _FormsName = authentication.Forms.Name;
                 _RequireSSL = authentication.Forms.RequireSSL;
                 _SlidingExpiration = authentication.Forms.SlidingExpiration;
                 if (_FormsName == null)
                 {
                     _FormsName = ".ASPXAUTH";
                 }
                 _Protection = authentication.Forms.Protection;
                 _Timeout = (int) authentication.Forms.Timeout.TotalMinutes;
                 _FormsCookiePath = authentication.Forms.Path;
                 _LoginUrl = authentication.Forms.LoginUrl;
                 if (_LoginUrl == null)
                 {
                     _LoginUrl = "login.aspx";
                 }
                 _DefaultUrl = authentication.Forms.DefaultUrl;
                 if (_DefaultUrl == null)
                 {
                     _DefaultUrl = "default.aspx";
                 }
                 _CookieMode = authentication.Forms.Cookieless;
                 _CookieDomain = authentication.Forms.Domain;
                 _EnableCrossAppRedirects = authentication.Forms.EnableCrossAppRedirects;
                 _TicketCompatibilityMode = authentication.Forms.TicketCompatibilityMode;
                 _Initialized = true;
             }
         }
     }
 }
        public static void Main()
        {
            // <Snippet1>
            // Get the Web application configuration.
            System.Configuration.Configuration configuration =
                WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

            // Get the external Authentication section.
            AuthenticationSection authenticationSection =
                (AuthenticationSection)configuration.GetSection(
                    "system.web/authentication");

            // Get the external Forms section .
            FormsAuthenticationConfiguration formsAuthentication =
                authenticationSection.Forms;

            //</Snippet1>

            // <Snippet2>
            // Create a new FormsAuthentication object.
            FormsAuthenticationConfiguration newformsAuthentication =
                new FormsAuthenticationConfiguration();

            // </Snippet2>

            // <Snippet3>
            // Get the current LoginUrl.
            string currentLoginUrl = formsAuthentication.LoginUrl;

            // Set the LoginUrl.
            formsAuthentication.LoginUrl = "newLoginUrl";

            // </Snippet3>

            // <Snippet4>
            // Get current DefaultUrl.
            string currentDefaultUrl =
                formsAuthentication.DefaultUrl;

            // Set current DefaultUrl.
            formsAuthentication.DefaultUrl = "newDefaultUrl";

            // </Snippet4>

            // <Snippet5>
            // Get current Cookieless.
            System.Web.HttpCookieMode currentCookieless =
                formsAuthentication.Cookieless;

            // Set current Cookieless.
            formsAuthentication.Cookieless =
                HttpCookieMode.AutoDetect;

            // </Snippet5>

            // <Snippet6>
            // Get the current Domain.
            string currentDomain =
                formsAuthentication.Domain;

            // Set the current Domain
            formsAuthentication.Domain = "newDomain";

            // </Snippet6>

            // <Snippet7>
            // Get the current SlidingExpiration.
            bool currentSlidingExpiration =
                formsAuthentication.SlidingExpiration;

            // Set the SlidingExpiration.
            formsAuthentication.SlidingExpiration = false;

            // </Snippet7>

            // <Snippet8>
            // Get the current EnableCrossAppRedirects.
            bool currentEnableCrossAppRedirects =
                formsAuthentication.EnableCrossAppRedirects;

            // Set the EnableCrossAppRedirects.
            formsAuthentication.EnableCrossAppRedirects = false;

            // </Snippet8>

            // <Snippet9>
            // Get the current Path.
            string currentPath = formsAuthentication.Path;

            // Set the Path property.
            formsAuthentication.Path = "newPath";

            // </Snippet9>

            // <Snippet10>
            // Get the current Timeout.
            System.TimeSpan currentTimeout =
                formsAuthentication.Timeout;

            // Set the Timeout.
            formsAuthentication.Timeout =
                System.TimeSpan.FromMinutes(10);

            // </Snippet10>

            // <Snippet11>
            // Get the current Protection.
            FormsProtectionEnum currentProtection =
                formsAuthentication.Protection;

            // Set the Protection property.
            formsAuthentication.Protection =
                FormsProtectionEnum.All;

            // </Snippet11>

            // <Snippet12>
            // Get the current RequireSSL.
            bool currentRequireSSL =
                formsAuthentication.RequireSSL;

            // Set the RequireSSL property value.
            formsAuthentication.RequireSSL = true;

            // </Snippet12>

            // <Snippet13>
            // Get the current Name property value.
            string currentName = formsAuthentication.Name;

            // Set the Name property value.
            formsAuthentication.Name = "newName";

            // </Snippet13>

            // <Snippet14>
            // Get the current Credentials.
            FormsAuthenticationCredentials currentCredentials =
                formsAuthentication.Credentials;

            StringBuilder credentials = new StringBuilder();

            // Get all the credentials.
            for (System.Int32 i = 0; i < currentCredentials.Users.Count; i++)
            {
                credentials.Append("Name: " +
                                   currentCredentials.Users[i].Name +
                                   " Password: " +
                                   currentCredentials.Users[i].Password);
                credentials.Append(Environment.NewLine);
            }
            // </Snippet14>
        }
예제 #11
0
		public static void Initialize ()
		{
			if (initialized)
				return;

			lock (locker) {
				if (initialized)
					return;

				AuthenticationSection section = (AuthenticationSection)WebConfigurationManager.GetSection (authConfigPath);
				FormsAuthenticationConfiguration config = section.Forms;

				cookieName = config.Name;
				Timeout = config.Timeout;
				timeout = (int)config.Timeout.TotalMinutes;
				cookiePath = config.Path;
				protection = config.Protection;
				requireSSL = config.RequireSSL;
				slidingExpiration = config.SlidingExpiration;
				cookie_domain = config.Domain;
				cookie_mode = config.Cookieless;
				cookies_supported = true; /* XXX ? */
				if (!String.IsNullOrEmpty (default_url))
					default_url = MapUrl (default_url);
				else
					default_url = MapUrl(config.DefaultUrl);
				enable_crossapp_redirects = config.EnableCrossAppRedirects;
				if (!String.IsNullOrEmpty (login_url))
					login_url = MapUrl (login_url);
				else
					login_url = MapUrl(config.LoginUrl);

				initialized = true;
			}
		}
예제 #12
0
        public static void Main()
        {
            // <Snippet1>
            // Get the Web application configuration.
            System.Configuration.Configuration configuration =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(
                    "/aspnetTest");

            // Get the section.
            AuthenticationSection authenticationSection =
                (AuthenticationSection)configuration.GetSection(
                    "system.web/authentication");

            // </Snippet1>


            // <Snippet2>
            AuthenticationSection newauthenticationSection =
                new AuthenticationSection();

            // </Snippet2>


            // <Snippet3>
            // Get the current Passport property.
            PassportAuthentication currentPassport =
                authenticationSection.Passport;

            // Get the Passport redirect URL.
            string passRedirectUrl =
                currentPassport.RedirectUrl;

            // </Snippet3>


            // <Snippet4>
            // Get the current Mode property.
            AuthenticationMode currentMode =
                authenticationSection.Mode;

            // Set the Mode property to Windows.
            authenticationSection.Mode =
                AuthenticationMode.Windows;

            // </Snippet4>


            // <Snippet5>
            // Get the current Forms property.

            FormsAuthenticationConfiguration currentForms =
                authenticationSection.Forms;

            // Get the Forms attributes.
            string         name               = currentForms.Name;
            string         login              = currentForms.LoginUrl;
            string         path               = currentForms.Path;
            HttpCookieMode cookieLess         = currentForms.Cookieless;
            bool           requireSSL         = currentForms.RequireSSL;
            bool           slidingExpiration  = currentForms.SlidingExpiration;
            bool           enableXappRedirect = currentForms.EnableCrossAppRedirects;

            TimeSpan            timeout    = currentForms.Timeout;
            FormsProtectionEnum protection = currentForms.Protection;
            string defaultUrl = currentForms.DefaultUrl;
            string domain     = currentForms.Domain;

            // </Snippet5>
        }