Exemplo n.º 1
0
        public void GetHashCode_()
        {
            AllMembershipCondition all  = new AllMembershipCondition();
            AllMembershipCondition copy = (AllMembershipCondition)all.Copy();

            Assert.AreEqual(all.GetHashCode(), copy.GetHashCode());
        }
Exemplo n.º 2
0
        public void FromXml()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            all.FromXml(se);
        }
Exemplo n.º 3
0
        private void SetSandBoxPolicy()
        {
            if (!this.SandBox)
            {
                throw new InvalidOperationException("SandBox property is not set to true");
            }
            // http://www.dotnetthis.com/Articles/DynamicSandboxing.htm

            // Now we need to set the appdomain policy,
            // and to do that we will need to create a Policy Level.
            // A Policy Level is a tree-like structure that has Code Groups as its nodes.
            // Each code group consists of a Membership Condition (something that
            // defines if an assembly in question belongs to the code group) and
            // a Permission Set that is granted to the assembly if it does.
            PolicyLevel domainPolicy = PolicyLevel.CreateAppDomainLevel();

            // Let's create a code group that gives Internet permission set
            // to all code.
            // First, let's create a membership condition that accepts all code.
            AllMembershipCondition allCodeMC = new AllMembershipCondition();

            // If you were to build a more complex policy (giving different permissions
            // to different assemblies) you could use other membership conditions,
            // such as ZoneMembershipCondition, StrongNameMembershipCondition, etc.

            // Now let's create a policy statement that represents Internet permissions.
            // Here we just grab named permission set called "Internet" from the default policy,
            // but you could also create your own permission set with whatever permissions
            // you want in there.
            PermissionSet   internetPermissionSet   = domainPolicy.GetNamedPermissionSet("Internet");
            PolicyStatement internetPolicyStatement = new PolicyStatement(internetPermissionSet);

            // We are ready to create a code group that maps all code to Internet permissions
            CodeGroup allCodeInternetCG = new UnionCodeGroup(allCodeMC, internetPolicyStatement);

            // We have used a UnionCodeGroup here. It does not make much difference for
            // a simple policy like ours here, but if you were to set up a more complex one
            // you would probably add some child code groups and then the type of the parent
            // code group would matter. UnionCodeGroup unions all permissions granted by its
            // child code groups (as opposed to FirstMatchCodeGroup that only takes one child
            // code group into effect).
            // Once we have the CodeGroup set up we can add it to our Policy Level.
            domainPolicy.RootCodeGroup = allCodeInternetCG;

            // If our root code group had any children the whole tree would be added
            // to the appdomain security policy now.
            // Imagine you wanted to modify our policy so that your strongname signed
            // assemblies would get FullTrust and all other assemblies would get Internet
            // permissions. Do accomplish that you would create a new UnionCodeGroup,
            // whose membership condition would be a StrongNameMembershipCondition
            // specifying your public key, and its permission set would be a "FullTrust"
            // or just a "new PermissionSet(PermissionState.Unrestricted)".
            // Then you would add that code group as a child to our allCodeInternetCG by
            // calling its AddChild method. Whenever you then loaded a correct strong
            // name signed assembly into your appdomain it would get Internet from the
            // root code group and FullTrust from the child code group, and the effective
            // permissions would be a union of the two, which is FullTrust.
            // and our final policy related step is setting the AppDomain policy
            this.Domain.SetAppDomainPolicy(domainPolicy);
        }
Exemplo n.º 4
0
        public void FromXml_PolicyLevelNull()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            all.FromXml(se, null);
        }
Exemplo n.º 5
0
        public void FromXml_InvalidClass()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            se.Attributes ["class"] = "Hello world";
            all.FromXml(se);
        }
Exemplo n.º 6
0
        public void FromXml_WrongTagCase()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            se.Tag = "IMEMBERSHIPCONDITION";             // instead of IMembershipCondition
            all.FromXml(se);
        }
Exemplo n.º 7
0
        public void FromXml_InvalidTag()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            se.Tag = "IMonoship";
            all.FromXml(se);
        }
Exemplo n.º 8
0
        public void Copy()
        {
            AllMembershipCondition all  = new AllMembershipCondition();
            AllMembershipCondition copy = (AllMembershipCondition)all.Copy();

            Assert.AreEqual(all, copy, "Equals");
            Assert.IsFalse(Object.ReferenceEquals(all, copy), "ReferenceEquals");
        }
Exemplo n.º 9
0
        public void FromXml_NoVersion()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", se.Attribute("class"));
            all.FromXml(w);
        }
Exemplo n.º 10
0
        public void ToXml()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            Assert.AreEqual("IMembershipCondition", se.Tag, "Tag");
            Assert.IsTrue(se.Attribute("class").StartsWith("System.Security.Policy.AllMembershipCondition"), "class");
            Assert.AreEqual("1", se.Attribute("version"), "version");
            Assert.AreEqual(se.ToString(), all.ToXml(null).ToString(), "ToXml(null)");
            Assert.AreEqual(se.ToString(), all.ToXml(PolicyLevel.CreateAppDomainLevel()).ToString(), "ToXml(PolicyLevel)");
        }
Exemplo n.º 11
0
        public void Equals()
        {
            AllMembershipCondition all = new AllMembershipCondition();

            Assert.IsFalse(all.Equals(null), "Equals(null)");
            AllMembershipCondition g2 = new AllMembershipCondition();

            Assert.IsTrue(all.Equals(g2), "Equals(g2)");
            Assert.IsTrue(g2.Equals(all), "Equals(all)");
            Assert.IsFalse(all.Equals(new object()), "Equals (object)");
        }
Exemplo n.º 12
0
        public void FromXml_NoClass()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("version", se.Attribute("version"));
            all.FromXml(w);
            // doesn't even care of the class attribute presence
        }
Exemplo n.º 13
0
        public void FromXml_InvalidVersion()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            SecurityElement        se  = all.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", se.Attribute("class"));
            w.AddAttribute("version", "2");
            all.FromXml(w);
            // doesn't seems to care about the version number!
        }
Exemplo n.º 14
0
        public static void AllMembershipConditionCallMethods()
        {
            AllMembershipCondition amc = new AllMembershipCondition();
            bool check = amc.Check(new Evidence());
            IMembershipCondition imc = amc.Copy();

            check = amc.Equals(new object());
            int             hash = amc.GetHashCode();
            string          str  = amc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)Activator.CreateInstance(typeof(PolicyLevel), true);

            amc.FromXml(se);
            amc.FromXml(se, pl);
            se = amc.ToXml();
            se = amc.ToXml(pl);
        }
        public static void AllMembershipConditionCallMethods()
        {
            AllMembershipCondition amc = new AllMembershipCondition();
            bool check = amc.Check(new Evidence());
            IMembershipCondition imc = amc.Copy();

            check = amc.Equals(new object());
            int             hash = amc.GetHashCode();
            string          str  = amc.ToString();
            SecurityElement se   = new SecurityElement("");
            PolicyLevel     pl   = (PolicyLevel)FormatterServices.GetUninitializedObject(typeof(PolicyLevel));

            amc.FromXml(se);
            amc.FromXml(se, pl);
            se = amc.ToXml();
            se = amc.ToXml(pl);
        }
Exemplo n.º 16
0
        public void Check()
        {
            AllMembershipCondition all = new AllMembershipCondition();
            Evidence e = null;

            Assert.IsTrue(all.Check(e), "Check (null)");
            e = new Evidence();
            Assert.IsTrue(all.Check(e), "Check (empty)");
            e.AddHost(new Zone(SecurityZone.MyComputer));
            Assert.IsTrue(all.Check(e), "Check (zone)");
            Url u = new Url("http://www.go-mono.com/");

            e.AddAssembly(u);
            Assert.IsTrue(all.Check(e), "Check (all-assembly)");
            Site s = new Site("www.go-mono.com");

            e.AddHost(s);
            Assert.IsTrue(all.Check(e), "Check (all-host)");
        }
Exemplo n.º 17
0
        //-----------------------------------------------------------------------------------------------
        // private methods
        //-----------------------------------------------------------------------------------------------

        /// <summary>
        /// Written by Abhishek Kumar on March 05, 2007
        /// purpose: to initiate the central Application Domain that
        /// all Grid Threads will be run on.
        ///
        /// Police and permissions will also be set.
        /// ADV: a crash in this App Domain(because of poor code in GThread)
        /// does not affect eduGRID's Framework i.e. the Alchemi executor is maintained steady even in error
        ///
        /// initially Alchemi created separate app domains for each Gthread it received.
        /// now, instead, we create 1 appdomain and run all gthreads on it
        /// the Bot Logic resides in this app domain.
        /// (this saves the overhead of initializing bot logic for every Gthread (or every query))
        /// </summary>
        private void initialize_GridThreadExecutor()
        {
            if (GridThreadExecutor == null)
            {
                string         appDir = GetApplicationDirectory(_CurTi.ApplicationId);
                AppDomainSetup info   = new AppDomainSetup();
                info.PrivateBinPath         = appDir;
                GridThreadApplicationDomain = AppDomain.CreateDomain("Central_AppDomain", null, info);

                // ***
                // http://www.dotnetthis.com/Articles/DynamicSandboxing.htm
                PolicyLevel            domainPolicy = PolicyLevel.CreateAppDomainLevel();
                AllMembershipCondition allCodeMC    = new AllMembershipCondition();
                // TODO: 'FullTrust' in the following line needs to be replaced with something like 'AlchemiGridThread'
                //        This permission set needs to be defined and set automatically as part of the installation.
                PermissionSet   internetPermissionSet   = domainPolicy.GetNamedPermissionSet("FullTrust");
                PolicyStatement internetPolicyStatement = new PolicyStatement(internetPermissionSet);
                CodeGroup       allCodeInternetCG       = new UnionCodeGroup(allCodeMC, internetPolicyStatement);
                domainPolicy.RootCodeGroup = allCodeInternetCG;
                GridThreadApplicationDomain.SetAppDomainPolicy(domainPolicy);

                GridThreadExecutor = (AppDomainExecutor)GridThreadApplicationDomain.CreateInstanceFromAndUnwrap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Alchemi.Executor.dll"), "Alchemi.Executor.AppDomainExecutor");
            }

            if (!GridThreadExecutor.Initialized)
            {
                try
                {
                    GridThreadExecutor.initialize();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error during initialization of GridThreadExecutor");
                }
            }
        }
Exemplo n.º 18
0
        public void FromXml_SecurityElementNull()
        {
            AllMembershipCondition all = new AllMembershipCondition();

            all.FromXml(null, PolicyLevel.CreateAppDomainLevel());
        }
Exemplo n.º 19
0
        public void FromXml_Null()
        {
            AllMembershipCondition all = new AllMembershipCondition();

            all.FromXml(null);
        }
Exemplo n.º 20
0
        public void ToString_()
        {
            AllMembershipCondition all = new AllMembershipCondition();

            Assert.AreEqual("All code", all.ToString());
        }
Exemplo n.º 21
0
        public void Constructor()
        {
            AllMembershipCondition all = new AllMembershipCondition();

            Assert.IsNotNull(all);
        }