public override void Install(System.Collections.IDictionary stateSaver)
        {
            PolicyLevel ent;
            PolicyLevel mach;
            PolicyLevel user;
            string sAssemblyPath = this.Context.Parameters["custassembly"];
            //string sAssemblyPath = this.Context.Parameters["XWord.dll"];
            System.Collections.IEnumerator policies = SecurityManager.PolicyHierarchy();
            policies.MoveNext();
            ent = (PolicyLevel)policies.Current;
            policies.MoveNext();
            mach = (PolicyLevel)policies.Current;
            policies.MoveNext();
            user = (PolicyLevel)policies.Current;

            PermissionSet fullTrust = user.GetNamedPermissionSet("FullTrust");
            PolicyStatement statement = new PolicyStatement(fullTrust, PolicyStatementAttribute.Nothing);
            UrlMembershipCondition condition = new UrlMembershipCondition(sAssemblyPath);
            CodeGroup group = new UnionCodeGroup(condition, statement);
            group.Name = "TestWordAddInCS";
            user.RootCodeGroup.AddChild(group);
            SecurityManager.SavePolicy();

            base.Install(stateSaver);
        }
Пример #2
0
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            try
            {
                PolicyLevel enterprise;
                PolicyLevel machine;
                PolicyLevel user;

                string assemblyLocation = this.Context.Parameters["assemblyLocation"];
                string groupName = this.Context.Parameters["groupName"];

                IEnumerator enumerator = SecurityManager.PolicyHierarchy();
                // 1st one is enterprise
                enumerator.MoveNext();
                enterprise = (PolicyLevel)enumerator.Current;
                // 2nd one is machine
                enumerator.MoveNext();
                machine = (PolicyLevel)enumerator.Current;
                // 3rd one is user
                enumerator.MoveNext();
                user = (PolicyLevel)enumerator.Current;

                PermissionSet permissionSet = user.GetNamedPermissionSet("FullTrust");
                PolicyStatement statement = new PolicyStatement(permissionSet, PolicyStatementAttribute.Nothing);
                UrlMembershipCondition condition = new UrlMembershipCondition(assemblyLocation);
                CodeGroup codeGroup = new UnionCodeGroup(condition, statement);
                codeGroup.Name = groupName;

                // see if the code group already exists, and if so, remove it
                CodeGroup existingCodeGroup = null;
                foreach (CodeGroup group in user.RootCodeGroup.Children)
                {
                    if (group.Name == codeGroup.Name)
                    {
                        existingCodeGroup = group;
                        break;
                    }
                }
                if (existingCodeGroup != null) user.RootCodeGroup.RemoveChild(existingCodeGroup);
                SecurityManager.SavePolicy();

                // add the code group
                user.RootCodeGroup.AddChild(codeGroup);
                SecurityManager.SavePolicy();
            }
            catch (Exception ex)
            {
                throw new InstallException("Cannot set the security policy.", ex);
            }

            // Call the base implementation.
            base.Install(stateSaver);
        }
Пример #3
0
		public void UrlMembershipCondition_GoMonoWebUrl () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com/");
			Assert.AreEqual ("http://www.go-mono.com/", umc.Url, "Url");
			Assert.AreEqual ("Url - http://www.go-mono.com/", umc.ToString (), "ToString");

			UrlMembershipCondition umc2 = (UrlMembershipCondition) umc.Copy ();
			Assert.AreEqual (umc.Url, umc2.Url, "Copy.Url");
			Assert.AreEqual (umc.GetHashCode (), umc2.GetHashCode (), "Copy.GetHashCode");

			SecurityElement se = umc2.ToXml ();
			UrlMembershipCondition umc3 = new UrlMembershipCondition ("*");
			umc3.FromXml (se);
			Assert.AreEqual (umc.Url, umc3.Url, "ToXml/FromXml");

			Assert.IsTrue (umc.Equals (umc2), "Equals");
			UrlMembershipCondition umc4 = new UrlMembershipCondition ("http://www.go-mono.com");
			// note that a last slash is added to Url - so it's equal
			Assert.IsTrue (umc.Equals (umc4), "Equals-AutoAddedLastSlash");
		}
Пример #4
0
        /// <summary>确定指定对象中的 URL 是否等效于包含在当前 <see cref="T:System.Security.Policy.UrlMembershipCondition" /> 中的 URL。</summary>
        /// <returns>如果指定对象中的 URL 等效于包含在当前 <see cref="T:System.Security.Policy.UrlMembershipCondition" /> 中的 URL,则为 true;否则为 false。</returns>
        /// <param name="o">与当前的 <see cref="T:System.Security.Policy.UrlMembershipCondition" /> 比较的对象。</param>
        /// <exception cref="T:System.ArgumentNullException">当前对象或指定对象的 <see cref="P:System.Security.Policy.UrlMembershipCondition.Url" /> 属性是 null。</exception>
        public override bool Equals(object o)
        {
            UrlMembershipCondition membershipCondition = o as UrlMembershipCondition;

            if (membershipCondition != null)
            {
                if (this.m_url == null && this.m_element != null)
                {
                    this.ParseURL();
                }
                if (membershipCondition.m_url == null && membershipCondition.m_element != null)
                {
                    membershipCondition.ParseURL();
                }
                if (object.Equals((object)this.m_url, (object)membershipCondition.m_url))
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>Determines whether the URL from the specified object is equivalent to the URL contained in the current <see cref="T:System.Security.Policy.UrlMembershipCondition" />.</summary>
        /// <returns>true if the URL from the specified object is equivalent to the URL contained in the current <see cref="T:System.Security.Policy.UrlMembershipCondition" />; otherwise, false.</returns>
        /// <param name="o">The object to compare to the current <see cref="T:System.Security.Policy.UrlMembershipCondition" />. </param>
        /// <exception cref="T:System.ArgumentNullException">The <see cref="P:System.Security.Policy.UrlMembershipCondition.Url" /> property of the current object or the specified object is null. </exception>
        public override bool Equals(object o)
        {
            UrlMembershipCondition urlMembershipCondition = o as UrlMembershipCondition;

            if (o == null)
            {
                return(false);
            }
            string value = this.url.Value;
            int    num   = value.Length;

            if (value[num - 1] == '*')
            {
                num--;
                if (value[num - 1] == '/')
                {
                    num--;
                }
            }
            return(string.Compare(value, 0, urlMembershipCondition.Url, 0, num, true, CultureInfo.InvariantCulture) == 0);
        }
        public override bool Equals(object o)
        {
            UrlMembershipCondition condition = o as UrlMembershipCondition;

            if (condition != null)
            {
                if ((this.m_url == null) && (this.m_element != null))
                {
                    this.ParseURL();
                }
                if ((condition.m_url == null) && (condition.m_element != null))
                {
                    condition.ParseURL();
                }
                if (object.Equals(this.m_url, condition.m_url))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #7
0
        public override bool Equals(Object o)
        {
            UrlMembershipCondition that = (o as UrlMembershipCondition);

            if (that != null)
            {
                if (this.m_url == null && this.m_element != null)
                {
                    this.ParseURL();
                }
                if (that.m_url == null && that.m_element != null)
                {
                    that.ParseURL();
                }

                if (Equals(this.m_url, that.m_url))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #8
0
		public void ToXml_Null () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			// no ArgumentNullException here
			SecurityElement se = umc.ToXml (null);
			Assert.IsNotNull (se, "ToXml(null)");
		}
Пример #9
0
		public void FromXml_NoVersion ()
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			SecurityElement se = umc.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			umc.FromXml (w);
		}
Пример #10
0
		public void Url_Empty () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("ftp://www.go-mono.com");
			umc.Url = String.Empty;
		}
Пример #11
0
		public void Url_UnknownProtocol () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("mono://www.go-mono.com");
			Assert.AreEqual ("mono://www.go-mono.com", umc.Url, "Url");
			Assert.AreEqual ("Url - mono://www.go-mono.com", umc.ToString (), "ToString");
		}
Пример #12
0
		public void UrlMembershipCondition_FileUrl () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("file://mono/index.html");
		}
Пример #13
0
		public void UrlMembershipCondition_Null () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition (null);
		}
Пример #14
0
		public void EqualsCaseSensitive_File () 
		{
			UrlMembershipCondition umc1 = new UrlMembershipCondition ("file://MONO");
			UrlMembershipCondition umc2 = new UrlMembershipCondition ("file://mono");
			Assert.IsTrue (umc1.Equals (umc2), "CaseSensitive");
		}
Пример #15
0
		public void EqualsCaseSensitive_Http () 
		{
			UrlMembershipCondition umc1 = new UrlMembershipCondition ("http://www.go-mono.com");
			UrlMembershipCondition umc2 = new UrlMembershipCondition ("http://www.Go-Mono.com");
			Assert.IsTrue (umc1.Equals (umc2), "CaseSensitive");
		}
Пример #16
0
		public void CheckMultipleEvidences () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			Evidence e = new Evidence ();
			e.AddHost (new Url ("http://www.go-mono.org"));	// the bad
			e.AddHost (new Url ("http://www.go-mono.com"));	// the good
			e.AddHost (new Zone (SecurityZone.MyComputer));	// and the ugly (couldn't resist ;)
			Assert.IsTrue (umc.Check (e), "Check(n)");
			// check all Url evidence (i.e. do not stop at the first Url evidence)
		}
Пример #17
0
		public void CheckNegative () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			Evidence e = new Evidence ();
			e.AddHost (new Url ("http://www.go-mono.org"));
			Assert.IsFalse (umc.Check (e), "Check(-)");
		}
Пример #18
0
		public void CheckPositive_Partial () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com/*");
			Evidence e = new Evidence ();
			e.AddHost (new Url ("http://www.go-mono.com/index.html"));
			Assert.IsTrue (umc.Check (e), "Check(+-)");
		}
Пример #19
0
		public void Check () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");

			Evidence e = null;
			Assert.IsFalse (umc.Check (e), "Check(null)");

			e = new Evidence ();
			Assert.IsFalse (umc.Check (e), "Check(empty)");

			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (umc.Check (e), "Check(zone)");

			Url u = new Url ("http://www.go-mono.com");
			e.AddAssembly (u);
			Assert.IsFalse (umc.Check (e), "Check(url-assembly)");
			e.AddHost (u);
			Assert.IsTrue (umc.Check (e), "Check(url-host)");
		}
Пример #20
0
		public void ToXml_PolicyLevel () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			SecurityElement se = umc.ToXml ();
			string s = umc.ToXml ().ToString ();
			// is it accepted for all policy levels ?
			IEnumerator e = SecurityManager.PolicyHierarchy ();
			while (e.MoveNext ()) {
				PolicyLevel pl = e.Current as PolicyLevel;
				UrlMembershipCondition spl = new UrlMembershipCondition ("*");
				spl.FromXml (se, pl);
				Assert.AreEqual (s, spl.ToXml (pl).ToString (), "ToXml(PolicyLevel='" + pl.Label + "')");
			}
			// yes!
		}
Пример #21
0
		public void ToFromXmlRoundTrip () 
		{
			UrlMembershipCondition umc1 = new UrlMembershipCondition ("http://www.go-mono.com");
			SecurityElement se = umc1.ToXml ();

			UrlMembershipCondition umc2 = new UrlMembershipCondition ("*");
			umc2.FromXml (se);

			Assert.AreEqual (umc1.GetHashCode (), umc2.GetHashCode (), "ToFromXmlRoundTrip");
		}
Пример #22
0
		public void EqualsNull () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			Assert.IsFalse (umc.Equals (null), "EqualsNull");
		}
Пример #23
0
		public void UrlMembershipCondition_Empty () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition (String.Empty);
		}
Пример #24
0
		public void FromXml_Null () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			umc.FromXml (null);
		}
Пример #25
0
		public void UrlMembershipCondition_FullUrlWithPort () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com:8080/index.html");
		}
        public IMembershipCondition Copy()
        {
            if (m_url == null && m_element != null)
                ParseURL();

            UrlMembershipCondition mc = new UrlMembershipCondition();
            mc.m_url = new URLString( m_url.ToString() );
            return mc;
        }
Пример #27
0
		public void Url_AllGoMonoUrl () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com/*");
			Assert.AreEqual ("http://www.go-mono.com/*", umc.Url, "Url");
			Assert.AreEqual ("Url - http://www.go-mono.com/*", umc.ToString (), "ToString");

			UrlMembershipCondition umc2 = (UrlMembershipCondition) umc.Copy ();
			Assert.AreEqual (umc.Url, umc2.Url, "Copy.Url");
			Assert.AreEqual (umc.GetHashCode (), umc2.GetHashCode (), "Copy.GetHashCode");

			SecurityElement se = umc2.ToXml ();
			UrlMembershipCondition umc3 = new UrlMembershipCondition ("*");
			umc3.FromXml (se);
			Assert.AreEqual (umc.Url, umc3.Url, "ToXml/FromXml");

			Assert.IsTrue (umc.Equals (umc2), "Equals");
			UrlMembershipCondition umc4 = new UrlMembershipCondition ("http://www.go-mono.com/");
			Assert.IsTrue (umc.Equals (umc4), "Equals-*");
		}
Пример #28
0
		public void Url_RelativePath () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com/path/../newpath/index.html");
			Assert.AreEqual ("http://www.go-mono.com/path/../newpath/index.html", umc.Url, "Url");
			Assert.AreEqual ("Url - http://www.go-mono.com/path/../newpath/index.html", umc.ToString (), "ToString");
		}
Пример #29
0
		public void FromXml_InvalidTag () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			SecurityElement se = umc.ToXml ();
			se.Tag = "IMonoship";
			umc.FromXml (se);
		}
Пример #30
0
		public void Url_Null () 
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("ftp://www.go-mono.com");
			umc.Url = null;
		}
 internal static PermissionSet AddPermissionForUri(PermissionSet originalPermSet, Uri srcUri) 
 {
     PermissionSet newPermSet = originalPermSet; 
     if (srcUri != null) 
     {
         Evidence evidence = new Evidence(); 
         evidence.AddHost(new Url(BindUriHelper.UriToString(srcUri))); // important: the parameter must be a UrL object not a UrI object
         IMembershipCondition membership = new UrlMembershipCondition(BindUriHelper.UriToString(srcUri));
         CodeGroup group = (srcUri.IsFile) ?
             (CodeGroup)new FileCodeGroup(membership, FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery) 
             :(CodeGroup)new NetCodeGroup(membership);
         PolicyStatement policy = group.Resolve(evidence); 
         if (!policy.PermissionSet.IsEmpty()) 
         {
             newPermSet = originalPermSet.Union(policy.PermissionSet); 
         }
     }
     return newPermSet;
 } 
Пример #32
0
		public void FromXml_InvalidClass ()
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			SecurityElement se = umc.ToXml ();
			se.Attributes ["class"] = "Hello world";
			umc.FromXml (se);
		}
Пример #33
0
 internal static string GetDataFormBaseDir()
 {
     string str = config.Configs["DataForm"].GetString("BaseDir", string.Empty);
     if (str.StartsWith("http://") || str.StartsWith("ftp://"))
     {
         IEnumerator enumerator = SecurityManager.PolicyHierarchy();
         enumerator.MoveNext();
         for (PolicyLevel level = enumerator.Current as PolicyLevel; level != null; level = enumerator.Current as PolicyLevel)
         {
             if (level.Label == "Machine")
             {
                 foreach (NamedPermissionSet set in level.NamedPermissionSets)
                 {
                     if (set.Name == "FullTrust")
                     {
                         UrlMembershipCondition membershipCondition = new UrlMembershipCondition(str + "*");
                         PolicyStatement policy = new PolicyStatement(set);
                         UnionCodeGroup group = new UnionCodeGroup(membershipCondition, policy);
                         level.RootCodeGroup.AddChild(group);
                     }
                 }
                 return str;
             }
             enumerator.MoveNext();
         }
         return str;
     }
     return string.Concat(new object[] { "file://", AppDomain.CurrentDomain.BaseDirectory, Path.DirectorySeparatorChar, str });
 }
Пример #34
0
		public void FromXml_NoClass ()
		{
			UrlMembershipCondition umc = new UrlMembershipCondition ("http://www.go-mono.com");
			SecurityElement se = umc.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", se.Attribute ("version"));
			umc.FromXml (w);
			// doesn't even care of the class attribute presence
		}