コード例 #1
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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /*
         * /*
         * <identification>
         * <userAgent match="xxx" />
         * <header name="HTTP_X_JPHONE_DISPLAY" match="xxx" />
         * <capability name="majorVersion" match="^6$" />
         * </identification>
         * <capture>
         * <header name="HTTP_X_UP_DEVCAP_NUMSOFTKEYS" match="?'softkeys'\d+)" />
         * </capture>
         */
        internal void ProcessIdentificationNode(XmlNode node, BrowserCapsElementType elementType)
        {
            string match  = null;
            string header = null;
            bool   nonMatch;
            bool   emptyIdentification = true;

            foreach (XmlNode child in node.ChildNodes)
            {
                match    = String.Empty;
                nonMatch = false;
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (child.Name)
                {
                case "userAgent":
                    emptyIdentification = false;

                    //match the user agent
                    HandlerBase.GetAndRemoveNonEmptyStringAttribute(child, "match", ref match);
                    if (String.IsNullOrEmpty(match))
                    {
                        HandlerBase.GetAndRemoveNonEmptyStringAttribute(child, "nonMatch", ref match);

                        if (String.IsNullOrEmpty(match))
                        {
                            HandleMissingMatchAndNonMatchError(child);
                        }

                        nonMatch = true;
                    }
                    _idHeaderChecks.Add(new CheckPair("User-Agent", match, nonMatch));
                    if (nonMatch == false)
                    {
                        DisallowNonMatchAttribute(child);
                    }

                    break;

                case "header":
                    emptyIdentification = false;

                    //match some arbitrary header
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "name", ref header);
                    HandlerBase.GetAndRemoveNonEmptyStringAttribute(child, "match", ref match);
                    if (String.IsNullOrEmpty(match))
                    {
                        HandlerBase.GetAndRemoveNonEmptyStringAttribute(child, "nonMatch", ref match);

                        if (String.IsNullOrEmpty(match))
                        {
                            HandleMissingMatchAndNonMatchError(child);
                        }

                        nonMatch = true;
                    }
                    _idHeaderChecks.Add(new CheckPair(header, match, nonMatch));
                    if (nonMatch == false)
                    {
                        DisallowNonMatchAttribute(child);
                    }
                    break;

                case "capability":
                    emptyIdentification = false;

                    //match against an already set capability
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "name", ref header);
                    HandlerBase.GetAndRemoveNonEmptyStringAttribute(child, "match", ref match);
                    if (String.IsNullOrEmpty(match))
                    {
                        HandlerBase.GetAndRemoveNonEmptyStringAttribute(child, "nonMatch", ref match);

                        if (String.IsNullOrEmpty(match))
                        {
                            HandleMissingMatchAndNonMatchError(child);
                        }

                        nonMatch = true;
                    }
                    _idCapabilityChecks.Add(new CheckPair(header, match, nonMatch));
                    //verify that match and nonMatch are not both specified
                    if (nonMatch == false)
                    {
                        DisallowNonMatchAttribute(child);
                    }
                    break;

                default:
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_invalid_element, child.ToString()), child);
                }
            }

            if (emptyIdentification)
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Browser_empty_identification), node);
            }

            return;
        }
コード例 #3
0
        //
        // As required by IConfigurationSectionHandler
        //
        public object Create(object parent, object configurationContext, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configurationContext))
            {
                return(null);
            }

            ParseState parseState = new ParseState();

            parseState.SectionName = section.Name;

            // the rule is going to be the previous rule followed by a list containing the new rules
            parseState.Evaluator = new HttpCapabilitiesDefaultProvider((HttpCapabilitiesDefaultProvider)parent);

            int userAgentCacheKeyLength = 0;

            // Get the useragent string cachekey length
            if (parent != null)
            {
                userAgentCacheKeyLength = ((HttpCapabilitiesDefaultProvider)parent).UserAgentCacheKeyLength;
            }
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "userAgentCacheKeyLength", ref userAgentCacheKeyLength);

            if (userAgentCacheKeyLength == 0)
            {
                userAgentCacheKeyLength = _defaultUserAgentCacheKeyLength;
            }
            parseState.Evaluator.UserAgentCacheKeyLength = userAgentCacheKeyLength;

            string browserCapabilitiesProviderType = null;

            if (parent != null)
            {
                browserCapabilitiesProviderType = ((HttpCapabilitiesDefaultProvider)parent).BrowserCapabilitiesProviderType;
            }
            HandlerBase.GetAndRemoveNonEmptyStringAttribute(section, "provider", ref browserCapabilitiesProviderType);
            parseState.Evaluator.BrowserCapabilitiesProviderType = browserCapabilitiesProviderType;

            // check for random attributes
            HandlerBase.CheckForUnrecognizedAttributes(section);


            // iterate through XML section in order and apply the directives

            ArrayList sublist;

            sublist = RuleListFromElement(parseState, section, true);

            if (sublist.Count > 0)
            {
                parseState.RuleList.Add(new CapabilitiesSection(CapabilitiesRule.Filter, null, null, sublist));
            }

            if (parseState.FileList.Count > 0)
            {
                parseState.IsExternalFile = true;
                ResolveFiles(parseState, configurationContext);
            }

            // Add the new rules

            parseState.Evaluator.AddRuleList(parseState.RuleList);

            return(parseState.Evaluator);
        }
コード例 #4
0
        internal BrowserDefinition(XmlNode node, bool isDefaultBrowser)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            _capabilities            = new NameValueCollection();
            _idHeaderChecks          = new ArrayList();
            _idCapabilityChecks      = new ArrayList();
            _captureHeaderChecks     = new ArrayList();
            _captureCapabilityChecks = new ArrayList();
            _adapters         = new AdapterDictionary();
            _browsers         = new BrowserDefinitionCollection();
            _gateways         = new BrowserDefinitionCollection();
            _refBrowsers      = new BrowserDefinitionCollection();
            _refGateways      = new BrowserDefinitionCollection();
            _node             = node;
            _isDefaultBrowser = isDefaultBrowser;

            string refID = null;

            HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "id", ref _id);
            HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "refID", ref refID);

            if ((refID != null) && (_id != null))
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Browser_mutually_exclusive_attributes, "id", "refID"), node);
            }

            if (_id != null)
            {
                if (!System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(_id))
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Browser_InvalidID, "id", _id), node);
                }
            }
            else
            {
                if (refID == null)
                {
                    if (this is GatewayDefinition)
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Browser_attributes_required, "gateway", "refID", "id"), node);
                    }

                    throw new ConfigurationErrorsException(SR.GetString(SR.Browser_attributes_required, "browser", "refID", "id"), node);
                }
                else
                {
                    if (!System.CodeDom.Compiler.CodeGenerator.IsValidLanguageIndependentIdentifier(refID))
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Browser_InvalidID, "refID", refID), node);
                    }
                }

                _parentID = refID;
                _isRefID  = true;
                _id       = refID;

                if (this is GatewayDefinition)
                {
                    _name = "refgatewayid$";
                }
                else
                {
                    _name = "refbrowserid$";
                }

                String parentID = null;
                HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "parentID", ref parentID);
                if ((parentID != null) && (parentID.Length != 0))
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Browser_mutually_exclusive_attributes, "parentID", "refID"), node);
                }
            }

            _name = MakeValidTypeNameFromString(_id + _name);

            if (!_isRefID)
            {
                // Not a default browser definition
                if (!("Default".Equals(_id)))
                {
                    HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "parentID", ref _parentID);
                }
                // Make sure parentID is not specified on default browser
                else
                {
                    HandlerBase.GetAndRemoveNonEmptyStringAttribute(node, "parentID", ref _parentID);
                    if (_parentID != null)
                    {
                        throw new ConfigurationErrorsException(
                                  SR.GetString(SR.Browser_parentID_applied_to_default), node);
                    }
                }
            }

            _parentName = MakeValidTypeNameFromString(_parentID);

            if (_id.IndexOf(" ", StringComparison.Ordinal) != -1)
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Space_attribute, "id " + _id), node);
            }

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

                switch (child.Name)
                {
                case "identification":
                    // refID nodes do not allow <identification>
                    if (_isRefID)
                    {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Browser_refid_prohibits_identification), node);
                    }

                    this.ProcessIdentificationNode(child, BrowserCapsElementType.Identification);
                    break;

                case "capture":
                    this.ProcessCaptureNode(child, BrowserCapsElementType.Capture);
                    break;

                case "capabilities":
                    this.ProcessCapabilitiesNode(child);
                    break;

                case "controlAdapters":
                    this.ProcessControlAdaptersNode(child);
                    break;

                case "sampleHeaders":
                    break;

                default:
                    throw new ConfigurationErrorsException(SR.GetString(SR.Browser_invalid_element, child.Name), node);
                }
            }
        }