public void CheckAssemblySCValidity(Assembly asm)
        {
            Type[]               types    = null;
            bool                 flag     = true;
            ArrayList            list     = null;
            RegistrationServices services = new RegistrationServices();

            try
            {
                types = asm.GetTypes();
            }
            catch (ReflectionTypeLoadException exception)
            {
                types = exception.Types;
            }
            foreach (Type type in types)
            {
                if (((null != type) && type.IsClass) && type.IsSubclassOf(typeof(ServicedComponent)))
                {
                    if (!services.TypeRequiresRegistration(type) && !type.IsAbstract)
                    {
                        flag = false;
                        if (list == null)
                        {
                            list = new ArrayList();
                        }
                        RegistrationErrorInfo info = new RegistrationErrorInfo(null, null, type.ToString(), -2147467259);
                        list.Add(info);
                    }
                    ClassInterfaceType classInterfaceType = ServicedComponentInfo.GetClassInterfaceType(type);
                    foreach (MethodInfo info2 in type.GetMethods())
                    {
                        if (ReflectionCache.ConvertToInterfaceMI(info2) == null)
                        {
                            if (ServicedComponentInfo.HasSpecialMethodAttributes(info2))
                            {
                                this.ReportWarning(Resource.FormatString("Reg_NoClassInterfaceSecure", type.FullName, info2.Name));
                            }
                            if ((classInterfaceType == ClassInterfaceType.AutoDispatch) && ServicedComponentInfo.IsMethodAutoDone(info2))
                            {
                                this.ReportWarning(Resource.FormatString("Reg_NoClassInterface", type.FullName, info2.Name));
                            }
                        }
                    }
                }
            }
            if (!flag)
            {
                RegistrationErrorInfo[] errorInfo = (RegistrationErrorInfo[])list.ToArray(typeof(RegistrationErrorInfo));
                throw new RegistrationException(Resource.FormatString("Reg_InvalidServicedComponents"), errorInfo);
            }
        }
Esempio n. 2
0
        private void CheckMethodAccess(IMessage request)
        {
            MethodBase     mi      = null;
            MethodBase     m       = null;
            IMethodMessage message = request as IMethodMessage;

            if (message == null)
            {
                throw new UnauthorizedAccessException();
            }
            mi = message.MethodBase;
            m  = ReflectionCache.ConvertToClassMI(base.GetType(), mi) as MethodBase;
            if (m == null)
            {
                throw new UnauthorizedAccessException();
            }
            if (ServicedComponentInfo.HasSpecialMethodAttributes(m))
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
            }
            if ((!mi.IsPublic || mi.IsStatic) && !IsMethodAllowedRemotely(mi))
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
            }
            Type declaringType = mi.DeclaringType;

            if (!declaringType.IsPublic && !declaringType.IsNestedPublic)
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
            }
            for (declaringType = mi.DeclaringType.DeclaringType; declaringType != null; declaringType = declaringType.DeclaringType)
            {
                if (!declaringType.IsPublic && !declaringType.IsNestedPublic)
                {
                    throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
                }
            }
        }
Esempio n. 3
0
        private void CheckMethodAccess(IMessage request)
        {
            MethodBase reqmethod  = null; // Method from the request
            MethodBase implmethod = null; // The implementation we will dispatch on.

            IMethodMessage call = request as IMethodMessage;

            if (call == null)
            {
                throw new UnauthorizedAccessException();
            }

            reqmethod = call.MethodBase;

            // Make sure we investigate the implementation, not the interface
            // for attributes (such as SecureMethod)
            implmethod = ReflectionCache.ConvertToClassMI(GetType(), reqmethod) as MethodBase;
            if (implmethod == null)
            {
                throw new UnauthorizedAccessException();
            }

            // Check implementation for dispatch attributes
            if (ServicedComponentInfo.HasSpecialMethodAttributes(implmethod))
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
            }

            // Verify the method is not private, internal, or static.  Use
            // the method that's being requested here, in case it's an
            // explicit interface implementation (they're all private).
            if (!reqmethod.IsPublic || reqmethod.IsStatic)
            {
                // If this is a special method (such as the FieldGetter or Setter, thne
                // go ahead and let it through.
                if (!IsMethodAllowedRemotely(reqmethod))
                {
                    throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
                }
            }

            // Make sure that the type we're invoking on is public!  This
            // covers invokes on public methods of internal interfaces.
            Type reqtype = reqmethod.DeclaringType;

            if (!reqtype.IsPublic && !reqtype.IsNestedPublic)
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
            }

            // Deal with nested types!  Get the declaring type of the method,
            // and then get the outer type that declared that.  It'll be
            // non-null if this is a nested type.
            reqtype = reqmethod.DeclaringType.DeclaringType;
            while (reqtype != null)
            {
                if (!reqtype.IsPublic && !reqtype.IsNestedPublic)
                {
                    throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityNoPrivateAccess"));
                }

                reqtype = reqtype.DeclaringType;
            }
        }