Exemple #1
0
        public static void NetCodeGroupCallMethods()
        {
            NetCodeGroup ncg        = new NetCodeGroup(new GacMembershipCondition());
            string       teststring = NetCodeGroup.AbsentOriginScheme;

            teststring = NetCodeGroup.AnyOtherOriginScheme;
            ncg.AddConnectAccess("test", new CodeConnectAccess("test", 0));
            CodeGroup cg     = ncg.Copy();
            bool      equals = ncg.Equals(new object());

            System.Collections.DictionaryEntry[] de = ncg.GetConnectAccessRules();
            int hash = ncg.GetHashCode();

            ncg.ResetConnectAccess();
            PolicyStatement ps = ncg.Resolve(new Evidence());

            cg = ncg.ResolveMatchingCodeGroups(new Evidence());
        }
        public void Resolve_Null()
        {
            NetCodeGroup cg = new NetCodeGroup(new AllMembershipCondition());

            cg.Resolve(null);
        }
        }// FindCurrentPermissionSet

        internal static int FindCurrentPermissionSet(Evidence ev, PermissionSet pSet)
        {
            // Ok, now let's see if the permission set that is currently granted matches
            // either Full Trust, Internet, Intranet, or none.

            if (pSet.IsEmpty())
            {
                return(PermissionSetType.NONE);
            }

            if (pSet.IsUnrestricted())
            {
                return(PermissionSetType.FULLTRUST);
            }

            // Let's grab the internet and intranet permission sets....
            PolicyLevel   pl         = GetPolicyLevelFromType(PolicyLevelType.Enterprise);
            PermissionSet psInternet = pl.GetNamedPermissionSet("Internet");
            PermissionSet psIntranet = pl.GetNamedPermissionSet("LocalIntranet");

            // In addition, the internet and intranet permission sets get additional
            // permissions that are normally provided by custom codegroups. We'll
            // create those codegroups and get the permissions of of those

            // Mess with the custom codegroups
            FileCodeGroup fcg = new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery);
            NetCodeGroup  ncg = new NetCodeGroup(new AllMembershipCondition());

            // The intranet permission set gets unioned with each of these...
            PermissionSet psss = fcg.Resolve(ev).PermissionSet;

            psIntranet = psIntranet.Union(psss);
            psIntranet = psIntranet.Union(ncg.Resolve(ev).PermissionSet);
            // The internet permission set just gets the net codegroup
            psInternet = psInternet.Union(ncg.Resolve(ev).PermissionSet);

            int nPermissionSet = PermissionSetType.UNKNOWN;

            // These 'IsSubsetOf' will throw exceptions if there are non-identical
            // regular expressions.

            try
            {
                if (psIntranet != null && pSet.IsSubsetOf(psIntranet) && psIntranet.IsSubsetOf(pSet))
                {
                    nPermissionSet = PermissionSetType.INTRANET;
                }
            }
            catch (Exception)
            {
            }

            // See if we should keep looking
            if (nPermissionSet == PermissionSetType.UNKNOWN)
            {
                try
                {
                    // See if this is a Internet policy level
                    if (psInternet != null && pSet.IsSubsetOf(psInternet) && psInternet.IsSubsetOf(pSet))
                    {
                        nPermissionSet = PermissionSetType.INTERNET;
                    }
                }
                catch (Exception)
                {
                }
            }
            return(nPermissionSet);
        }// FindCurrentPermissionSet