private static Type CheckType(string typeName, Type baseType, System.Xml.XmlNode child)
        {
            Type c = ConfigUtil.GetType(typeName, child, true);

            if (!baseType.IsAssignableFrom(c))
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Type_doesnt_inherit_from_type", new object[] { typeName, baseType.FullName }), child);
            }
            if (!HttpRuntime.IsTypeAllowedInConfig(c))
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Type_from_untrusted_assembly", new object[] { typeName }), child);
            }
            return(c);
        }
Esempio n. 2
0
 internal Hashtable GetTransformerEntries()
 {
     if (this._transformerEntries == null)
     {
         lock (this)
         {
             if (this._transformerEntries == null)
             {
                 this._transformerEntries = new Hashtable(StringComparer.OrdinalIgnoreCase);
                 foreach (TransformerInfo info in this)
                 {
                     Type consumerType;
                     Type providerType;
                     Type transformerType = ConfigUtil.GetType(info.Type, "type", info);
                     if (!transformerType.IsSubclassOf(typeof(WebPartTransformer)))
                     {
                         throw new ConfigurationErrorsException(System.Web.SR.GetString("Type_doesnt_inherit_from_type", new object[] { info.Type, typeof(WebPartTransformer).FullName }), info.ElementInformation.Properties["type"].Source, info.ElementInformation.Properties["type"].LineNumber);
                     }
                     try
                     {
                         consumerType = WebPartTransformerAttribute.GetConsumerType(transformerType);
                         providerType = WebPartTransformerAttribute.GetProviderType(transformerType);
                     }
                     catch (Exception exception)
                     {
                         throw new ConfigurationErrorsException(System.Web.SR.GetString("Transformer_attribute_error", new object[] { exception.Message }), exception, info.ElementInformation.Properties["type"].Source, info.ElementInformation.Properties["type"].LineNumber);
                     }
                     if (this._transformerEntries.Count != 0)
                     {
                         foreach (DictionaryEntry entry in this._transformerEntries)
                         {
                             Type type4 = (Type)entry.Value;
                             Type type5 = WebPartTransformerAttribute.GetConsumerType(type4);
                             Type type6 = WebPartTransformerAttribute.GetProviderType(type4);
                             if ((consumerType == type5) && (providerType == type6))
                             {
                                 throw new ConfigurationErrorsException(System.Web.SR.GetString("Transformer_types_already_added", new object[] { (string)entry.Key, info.Name }), info.ElementInformation.Properties["type"].Source, info.ElementInformation.Properties["type"].LineNumber);
                             }
                         }
                     }
                     this._transformerEntries[info.Name] = transformerType;
                 }
             }
         }
     }
     return(this._transformerEntries);
 }
Esempio n. 3
0
        private void InitCustomEvaluator(RuleInfo ruleInfo)
        {
            string str = ruleInfo._customEvaluator;

            if ((str == null) || (str.Trim().Length == 0))
            {
                ruleInfo._customEvaluatorType = null;
            }
            else
            {
                ruleInfo._customEvaluatorType = ConfigUtil.GetType(ruleInfo._customEvaluator, "custom", ruleInfo._customEvaluatorConfig);
                System.Web.Configuration.HandlerBase.CheckAssignableType(ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].Source, ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].LineNumber, typeof(IWebEventCustomEvaluator), ruleInfo._customEvaluatorType);
                if (this._customEvaluatorInstances[ruleInfo._customEvaluatorType] == null)
                {
                    this._customEvaluatorInstances[ruleInfo._customEvaluatorType] = HttpRuntime.CreatePublicInstance(ruleInfo._customEvaluatorType);
                }
            }
        }
        internal void InitValidateInternal()
        {
            string pattern = this.Verb.Replace(" ", string.Empty);

            this._requestType = new Wildcard(pattern, false);
            this._path        = new WildcardUrl(this.Path, true);
            if (!this.Validate)
            {
                this._type = null;
            }
            else
            {
                this._type = ConfigUtil.GetType(this.Type, "type", this);
                if (!ConfigUtil.IsTypeHandlerOrFactory(this._type))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Type_not_factory_or_handler", new object[] { this.Type }), base.ElementInformation.Source, base.ElementInformation.LineNumber);
                }
            }
        }
Esempio n. 5
0
        private void BasicSanityCheck()
        {
            Type type;

            foreach (ProviderSettings settings in this._section.Providers)
            {
                type = ConfigUtil.GetType(settings.Type, "type", settings);
                System.Web.Configuration.HandlerBase.CheckAssignableType(settings.ElementInformation.Properties["type"].Source, settings.ElementInformation.Properties["type"].LineNumber, typeof(WebEventProvider), type);
            }
            foreach (EventMappingSettings settings2 in this._section.EventMappings)
            {
                type = ConfigUtil.GetType(settings2.Type, "type", settings2);
                if (settings2.StartEventCode > settings2.EndEventCode)
                {
                    string str = "startEventCode";
                    if (settings2.ElementInformation.Properties[str].LineNumber == 0)
                    {
                        str = "endEventCode";
                    }
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Event_name_invalid_code_range"), settings2.ElementInformation.Properties[str].Source, settings2.ElementInformation.Properties[str].LineNumber);
                }
                System.Web.Configuration.HandlerBase.CheckAssignableType(settings2.ElementInformation.Properties["type"].Source, settings2.ElementInformation.Properties["type"].LineNumber, typeof(WebBaseEvent), type);
                settings2.RealType = type;
            }
            foreach (RuleSettings settings3 in this._section.Rules)
            {
                string provider = settings3.Provider;
                if (!string.IsNullOrEmpty(provider) && (this._section.Providers[provider] == null))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Health_mon_provider_not_found", new object[] { provider }), settings3.ElementInformation.Properties["provider"].Source, settings3.ElementInformation.Properties["provider"].LineNumber);
                }
                string profile = settings3.Profile;
                if (!string.IsNullOrEmpty(profile) && (this._section.Profiles[profile] == null))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Health_mon_profile_not_found", new object[] { profile }), settings3.ElementInformation.Properties["profile"].Source, settings3.ElementInformation.Properties["profile"].LineNumber);
                }
                if (this._section.EventMappings[settings3.EventName] == null)
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Event_name_not_found", new object[] { settings3.EventName }), settings3.ElementInformation.Properties["eventName"].Source, settings3.ElementInformation.Properties["eventName"].LineNumber);
                }
            }
        }
        private static Type CheckType(string typeName, Type baseType, XmlNode child)
        {
            // Use BuildManager to verify control types.
            // Note for machine level browser files, this will only check assemblies in GAC.
            Type type = ConfigUtil.GetType(typeName, child, true /*ignoreCase*/);

            if (!baseType.IsAssignableFrom(type))
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Type_doesnt_inherit_from_type, typeName,
                                       baseType.FullName), child);
            }

            if (!HttpRuntime.IsTypeAllowedInConfig(type))
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Type_from_untrusted_assembly, typeName), child);
            }

            return(type);
        }
Esempio n. 7
0
        internal static ProviderBase InstantiateProvider(NameValueCollection providerSettings, Type providerType)
        {
            ProviderBase provider = null;

            try {
                string pnName = GetAndRemoveStringValue(providerSettings, "name");
                string pnType = GetAndRemoveStringValue(providerSettings, "type");
                if (string.IsNullOrEmpty(pnType))
                {
                    throw new ArgumentException(SR.GetString(SR.Provider_no_type_name));
                }
                Type t = ConfigUtil.GetType(pnType, "type", null, null, true, true);

                if (!providerType.IsAssignableFrom(t))
                {
                    throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, providerType.ToString()));
                }
                provider = (ProviderBase)HttpRuntime.CreatePublicInstanceByWebObjectActivator(t);

                // Because providers modify the parameters collection (i.e. delete stuff), pass in a clone of the collection
                NameValueCollection cloneParams = new NameValueCollection(providerSettings.Count, StringComparer.Ordinal);
                foreach (string key in providerSettings)
                {
                    cloneParams[key] = providerSettings[key];
                }
                provider.Initialize(pnName, cloneParams);

                TelemetryLogger.LogProvider(t);
            }
            catch (Exception e) {
                if (e is ConfigurationException)
                {
                    throw;
                }
                throw new ConfigurationErrorsException(e.Message, e);
            }

            return(provider);
        }
Esempio n. 8
0
        public static ProviderBase InstantiateProvider(ProviderSettings providerSettings, Type providerType)
        {
            ProviderBase provider = null;

            try {
                string pnType = (providerSettings.Type == null) ? null : providerSettings.Type.Trim();
                if (string.IsNullOrEmpty(pnType))
                {
                    throw new ArgumentException(SR.GetString(SR.Provider_no_type_name));
                }
                Type t = ConfigUtil.GetType(pnType, "type", providerSettings, true, true);

                if (!providerType.IsAssignableFrom(t))
                {
                    throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, providerType.ToString()));
                }
                provider = (ProviderBase)HttpRuntime.CreatePublicInstanceByWebObjectActivator(t);

                // Because providers modify the parameters collection (i.e. delete stuff), pass in a clone of the collection
                NameValueCollection pars        = providerSettings.Parameters;
                NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal);
                foreach (string key in pars)
                {
                    cloneParams[key] = pars[key];
                }
                provider.Initialize(providerSettings.Name, cloneParams);

                TelemetryLogger.LogProvider(t);
            } catch (Exception e) {
                if (e is ConfigurationException)
                {
                    throw;
                }
                throw new ConfigurationErrorsException(e.Message, e, providerSettings.ElementInformation.Properties["type"].Source, providerSettings.ElementInformation.Properties["type"].LineNumber);
            }

            return(provider);
        }
Esempio n. 9
0
        internal Object Create()
        {
            // HACKHACK: for now, let uncreatable types through and error later (for .soap factory)
            // This design should change - developers will want to know immediately
            // when they misspell a type

            if (_type == null)
            {
                Type t = ConfigUtil.GetType(Type, "type", this);

                // throw for bad types in deferred case
                if (!ConfigUtil.IsTypeHandlerOrFactory(t))
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Type_not_factory_or_handler, Type),
                              ElementInformation.Source, ElementInformation.LineNumber);
                }

                _type = t;
            }

            return(HttpRuntime.CreateNonPublicInstanceByWebObjectActivator(_type));
        }
        internal Hashtable GetTransformerEntries()
        {
            if (_transformerEntries == null)
            {
                lock (this) {
                    if (_transformerEntries == null)
                    {
                        _transformerEntries = new Hashtable(StringComparer.OrdinalIgnoreCase);

                        foreach (TransformerInfo ti in this)
                        {
                            Type transformerType = ConfigUtil.GetType(ti.Type, "type", ti);

                            if (transformerType.IsSubclassOf(typeof(WebPartTransformer)) == false)
                            {
                                throw new ConfigurationErrorsException(
                                          SR.GetString(SR.Type_doesnt_inherit_from_type,
                                                       ti.Type,
                                                       typeof(WebPartTransformer).FullName),
                                          ti.ElementInformation.Properties["type"].Source,
                                          ti.ElementInformation.Properties["type"].LineNumber);
                            }

                            Type consumerType;
                            Type providerType;
                            try {
                                consumerType = WebPartTransformerAttribute.GetConsumerType(transformerType);
                                providerType = WebPartTransformerAttribute.GetProviderType(transformerType);
                            }
                            catch (Exception e) {
                                throw new ConfigurationErrorsException(
                                          SR.GetString(SR.Transformer_attribute_error, e.Message),
                                          e,
                                          ti.ElementInformation.Properties["type"].Source,
                                          ti.ElementInformation.Properties["type"].LineNumber);
                            }

                            if (_transformerEntries.Count != 0)
                            {
                                foreach (DictionaryEntry entry in _transformerEntries)
                                {
                                    Type existingTransformerType = (Type)entry.Value;

                                    // We know these methods will not throw, because for the type to be in the transformers
                                    // collection, we must have successfully gotten the types previously without an exception.
                                    Type existingConsumerType =
                                        WebPartTransformerAttribute.GetConsumerType(existingTransformerType);
                                    Type existingProviderType =
                                        WebPartTransformerAttribute.GetProviderType(existingTransformerType);

                                    if ((consumerType == existingConsumerType) && (providerType == existingProviderType))
                                    {
                                        throw new ConfigurationErrorsException(
                                                  SR.GetString(SR.Transformer_types_already_added,
                                                               (string)entry.Key,
                                                               ti.Name),
                                                  ti.ElementInformation.Properties["type"].Source,
                                                  ti.ElementInformation.Properties["type"].LineNumber);
                                    }
                                }
                            }

                            _transformerEntries[ti.Name] = transformerType;
                        }
                    }
                }
            }
            //
            return(_transformerEntries);
        }
Esempio n. 11
0
        void BasicSanityCheck()
        {
            Type type;

            foreach (ProviderSettings providerSettings in _section.Providers)
            {
                // Make sure the type is valid.
                type = ConfigUtil.GetType(providerSettings.Type, "type", providerSettings);

                // Make sure the type support WebEventProvider
                HandlerBase.CheckAssignableType(providerSettings.ElementInformation.Properties["type"].Source,
                                                providerSettings.ElementInformation.Properties["type"].LineNumber,
                                                typeof(WebEventProvider), type);
            }

            foreach (EventMappingSettings eventMappingSettings in _section.EventMappings)
            {
                // Make sure the type is valid.
                type = ConfigUtil.GetType(eventMappingSettings.Type, "type", eventMappingSettings);

                // Make sure startEventCode <= endEventCode
                if (!(eventMappingSettings.StartEventCode <= eventMappingSettings.EndEventCode))
                {
                    string attribute;

                    // We don't know which one was specified unless we test it
                    attribute = "startEventCode";
                    if (eventMappingSettings.ElementInformation.Properties[attribute].LineNumber == 0)
                    {
                        attribute = "endEventCode";
                        Debug.Assert(eventMappingSettings.ElementInformation.Properties[attribute].LineNumber != 0,
                                     "eventMappingSettings.ElementInformation.Properties[attribute].LineNumber != 0");
                    }

                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Event_name_invalid_code_range),
                              eventMappingSettings.ElementInformation.Properties[attribute].Source, eventMappingSettings.ElementInformation.Properties[attribute].LineNumber);
                }

                // Make sure the type support WebBaseEvent
                HandlerBase.CheckAssignableType(eventMappingSettings.ElementInformation.Properties["type"].Source,
                                                eventMappingSettings.ElementInformation.Properties["type"].LineNumber,
                                                typeof(System.Web.Management.WebBaseEvent), type);

                // It's a valid type.  Might as well save it.
                eventMappingSettings.RealType = type;
            }

            foreach (RuleSettings rule in _section.Rules)
            {
                // Go thru all the Rules, and make sure all referenced provider, eventName
                // and profile exist.

                string provider = rule.Provider;
                if (!String.IsNullOrEmpty(provider))
                {
                    ProviderSettings providerSettings = _section.Providers[provider];
                    if (providerSettings == null)
                    {
                        throw new ConfigurationErrorsException(
                                  SR.GetString(SR.Health_mon_provider_not_found, provider),
                                  rule.ElementInformation.Properties["provider"].Source,
                                  rule.ElementInformation.Properties["provider"].LineNumber);
                    }
                }

                string profile = rule.Profile;
                if (!String.IsNullOrEmpty(profile))
                {
                    if (_section.Profiles[profile] == null)
                    {
                        throw new ConfigurationErrorsException(
                                  SR.GetString(SR.Health_mon_profile_not_found, profile),
                                  rule.ElementInformation.Properties["profile"].Source,
                                  rule.ElementInformation.Properties["profile"].LineNumber);
                    }
                }

                if (_section.EventMappings[rule.EventName] == null)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Event_name_not_found, rule.EventName),
                              rule.ElementInformation.Properties["eventName"].Source, rule.ElementInformation.Properties["eventName"].LineNumber);
                }
            }
        }