GetNamedPermissionSet() public method

public GetNamedPermissionSet ( string name ) : NamedPermissionSet
name string
return NamedPermissionSet
コード例 #1
0
        /// <summary>Reconstructs a security object with a given state and policy level from an XML encoding.</summary>
        /// <param name="e">The XML encoding to use to reconstruct the security object. </param>
        /// <param name="level">The policy level within which the code group exists. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="e" /> parameter is null. </exception>
        public void FromXml(SecurityElement e, PolicyLevel level)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            string        text = e.Attribute("PermissionSetName");
            PermissionSet permissionSet;

            if (text != null && level != null)
            {
                permissionSet = level.GetNamedPermissionSet(text);
            }
            else
            {
                SecurityElement securityElement = e.SearchForChildByTag("PermissionSet");
                if (securityElement != null)
                {
                    Type type = Type.GetType(securityElement.Attribute("class"));
                    permissionSet = (PermissionSet)Activator.CreateInstance(type, true);
                    permissionSet.FromXml(securityElement);
                }
                else
                {
                    permissionSet = new PermissionSet(new PermissionSet(PermissionState.None));
                }
            }
            this.m_policy = new PolicyStatement(permissionSet);
            this.m_children.Clear();
            if (e.Children != null && e.Children.Count > 0)
            {
                foreach (object obj in e.Children)
                {
                    SecurityElement securityElement2 = (SecurityElement)obj;
                    if (securityElement2.Tag == "CodeGroup")
                    {
                        this.AddChild(CodeGroup.CreateFromXml(securityElement2, level));
                    }
                }
            }
            this.m_membershipCondition = null;
            SecurityElement securityElement3 = e.SearchForChildByTag("IMembershipCondition");

            if (securityElement3 != null)
            {
                string text2 = securityElement3.Attribute("class");
                Type   type2 = Type.GetType(text2);
                if (type2 == null)
                {
                    type2 = Type.GetType("System.Security.Policy." + text2);
                }
                this.m_membershipCondition = (IMembershipCondition)Activator.CreateInstance(type2, true);
                this.m_membershipCondition.FromXml(securityElement3, level);
            }
            this.m_name        = e.Attribute("Name");
            this.m_description = e.Attribute("Description");
            this.ParseXml(e, level);
        }
コード例 #2
0
        internal SecurityElement ToXml(PolicyLevel level, bool useInternal)
        {
            SecurityElement e = new SecurityElement("PolicyStatement");

            e.AddAttribute("version", "1");
            if (m_attributes != PolicyStatementAttribute.Nothing)
            {
                e.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), m_attributes));
            }

            lock (this)
            {
                if (m_permSet != null)
                {
                    if (m_permSet is NamedPermissionSet)
                    {
                        // If the named permission set exists in the parent level of this
                        // policy struct, then just save the name of the permission set.
                        // Otherwise, serialize it like normal.

                        NamedPermissionSet namedPermSet = (NamedPermissionSet)m_permSet;
                        if (level != null && level.GetNamedPermissionSet(namedPermSet.Name) != null)
                        {
                            e.AddAttribute("PermissionSetName", namedPermSet.Name);
                        }
                        else
                        {
                            if (useInternal)
                            {
                                e.AddChild(namedPermSet.InternalToXml());
                            }
                            else
                            {
                                e.AddChild(namedPermSet.ToXml());
                            }
                        }
                    }
                    else
                    {
                        if (useInternal)
                        {
                            e.AddChild(m_permSet.InternalToXml());
                        }
                        else
                        {
                            e.AddChild(m_permSet.ToXml());
                        }
                    }
                }
            }

            return(e);
        }
コード例 #3
0
ファイル: CodeGroup.cs プロジェクト: ForNeVeR/pnet
        public SecurityElement ToXml(PolicyLevel level)
        {
            SecurityElement element;

            element = new SecurityElement("CodeGroup");
            element.AddAttribute
                ("class",
                SecurityElement.Escape(GetType().AssemblyQualifiedName));
            element.AddAttribute("version", "1");
            element.AddChild(membershipCondition.ToXml(level));
            if (policy != null)
            {
                PermissionSet permSet = policy.PermissionSetNoCopy;
                if (permSet is NamedPermissionSet && level != null &&
                    level.GetNamedPermissionSet
                        (((NamedPermissionSet)permSet).Name) != null)
                {
                    element.AddAttribute
                        ("PermissionSetName",
                        ((NamedPermissionSet)permSet).Name);
                }
                else if (!permSet.IsEmpty())
                {
                    element.AddChild(permSet.ToXml());
                }
                if (policy.Attributes != PolicyStatementAttribute.Nothing)
                {
                    element.AddAttribute
                        ("Attributes", policy.Attributes.ToString());
                }
                foreach (CodeGroup group in Children)
                {
                    element.AddChild(group.ToXml(level));
                }
            }
            if (name != null)
            {
                element.AddAttribute("Name", SecurityElement.Escape(name));
            }
            if (description != null)
            {
                element.AddAttribute
                    ("Description", SecurityElement.Escape(description));
            }
            CreateXml(element, level);
            return(element);
        }
コード例 #4
0
        // Token: 0x06002A0B RID: 10763 RVA: 0x0009C32C File Offset: 0x0009A52C
        internal SecurityElement ToXml(PolicyLevel level, bool useInternal)
        {
            SecurityElement securityElement = new SecurityElement("PolicyStatement");

            securityElement.AddAttribute("version", "1");
            if (this.m_attributes != PolicyStatementAttribute.Nothing)
            {
                securityElement.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), this.m_attributes));
            }
            lock (this)
            {
                if (this.m_permSet != null)
                {
                    if (this.m_permSet is NamedPermissionSet)
                    {
                        NamedPermissionSet namedPermissionSet = (NamedPermissionSet)this.m_permSet;
                        if (level != null && level.GetNamedPermissionSet(namedPermissionSet.Name) != null)
                        {
                            securityElement.AddAttribute("PermissionSetName", namedPermissionSet.Name);
                        }
                        else if (useInternal)
                        {
                            securityElement.AddChild(namedPermissionSet.InternalToXml());
                        }
                        else
                        {
                            securityElement.AddChild(namedPermissionSet.ToXml());
                        }
                    }
                    else if (useInternal)
                    {
                        securityElement.AddChild(this.m_permSet.InternalToXml());
                    }
                    else
                    {
                        securityElement.AddChild(this.m_permSet.ToXml());
                    }
                }
            }
            return(securityElement);
        }
コード例 #5
0
ファイル: caspol.cs プロジェクト: ArildF/masters
 static NamedPermissionSet GetPermissionSet( PolicyLevel level, String name )
 {
     NamedPermissionSet permSet = level.GetNamedPermissionSet( name );
     if (permSet == null)
     {
         throw new ArgumentException( String.Format( manager.GetString( "Error_UnknownPermissionSet" ), name ) );
     }
     return permSet;
 }
コード例 #6
0
        public void FromXml(SecurityElement e, PolicyLevel level)
        {
            if (null == e)
            {
                throw new ArgumentNullException("e");
            }

            PermissionSet ps       = null;
            string        psetname = e.Attribute("PermissionSetName");

            if ((psetname != null) && (level != null))
            {
                ps = level.GetNamedPermissionSet(psetname);
            }
            else
            {
                SecurityElement pset = e.SearchForChildByTag("PermissionSet");
                if (pset != null)
                {
                    Type classType = Type.GetType(pset.Attribute("class"));
                    ps = (PermissionSet)Activator.CreateInstance(classType, true);
                    ps.FromXml(pset);
                }
                else
                {
                    ps = new PermissionSet(new PermissionSet(PermissionState.None));
                }
            }
            m_policy = new PolicyStatement(ps);

            m_children.Clear();
            if ((e.Children != null) && (e.Children.Count > 0))
            {
                foreach (SecurityElement se in e.Children)
                {
                    if (se.Tag == "CodeGroup")
                    {
                        this.AddChild(CodeGroup.CreateFromXml(se, level));
                    }
                }
            }

            m_membershipCondition = null;
            SecurityElement mc = e.SearchForChildByTag("IMembershipCondition");

            if (mc != null)
            {
                string className = mc.Attribute("class");
                Type   classType = Type.GetType(className);
                if (classType == null)
                {
                    classType = Type.GetType("System.Security.Policy." + className);
                }
                m_membershipCondition = (IMembershipCondition)Activator.CreateInstance(classType, true);
                m_membershipCondition.FromXml(mc, level);
            }

            m_name        = e.Attribute("Name");
            m_description = e.Attribute("Description");

            // seems like we might need this to Resolve() in subclasses
            m_level = level;

            ParseXml(e, level);
        }
 internal SecurityElement ToXml(PolicyLevel level, bool useInternal)
 {
     SecurityElement element = new SecurityElement("PolicyStatement");
     element.AddAttribute("version", "1");
     if (this.m_attributes != PolicyStatementAttribute.Nothing)
     {
         element.AddAttribute("Attributes", XMLUtil.BitFieldEnumToString(typeof(PolicyStatementAttribute), this.m_attributes));
     }
     lock (this)
     {
         if (this.m_permSet == null)
         {
             return element;
         }
         if (this.m_permSet is NamedPermissionSet)
         {
             NamedPermissionSet permSet = (NamedPermissionSet) this.m_permSet;
             if ((level != null) && (level.GetNamedPermissionSet(permSet.Name) != null))
             {
                 element.AddAttribute("PermissionSetName", permSet.Name);
                 return element;
             }
             if (useInternal)
             {
                 element.AddChild(permSet.InternalToXml());
                 return element;
             }
             element.AddChild(permSet.ToXml());
             return element;
         }
         if (useInternal)
         {
             element.AddChild(this.m_permSet.InternalToXml());
             return element;
         }
         element.AddChild(this.m_permSet.ToXml());
     }
     return element;
 }
コード例 #8
0
 internal SecurityElement ToXml( PolicyLevel level, bool useInternal )
 {
     SecurityElement e = new SecurityElement( "PolicyStatement" );
     e.AddAttribute( "version", "1" );
     if (m_attributes != PolicyStatementAttribute.Nothing)
         e.AddAttribute( "Attributes", XMLUtil.BitFieldEnumToString( typeof( PolicyStatementAttribute ), m_attributes ) );            
     
     lock (this)
     {
         if (m_permSet != null)
         {
             if (m_permSet is NamedPermissionSet)
             {
                 // If the named permission set exists in the parent level of this
                 // policy struct, then just save the name of the permission set.
                 // Otherwise, serialize it like normal.
         
                 NamedPermissionSet namedPermSet = (NamedPermissionSet)m_permSet;
                 if (level != null && level.GetNamedPermissionSet( namedPermSet.Name ) != null)
                 {
                     e.AddAttribute( "PermissionSetName", namedPermSet.Name );
                 }
                 else
                 {
                     if (useInternal)
                         e.AddChild( namedPermSet.InternalToXml() );
                     else
                         e.AddChild( namedPermSet.ToXml() );
                 }
             }
             else
             {
                 if (useInternal)
                     e.AddChild( m_permSet.InternalToXml() );
                 else
                     e.AddChild( m_permSet.ToXml() );
             }
         }
     }
     
     return e;
 }
コード例 #9
0
 private static NamedPermissionSet CreateLocalIntranetSet() {
     PolicyLevel level = new PolicyLevel(System.Security.PolicyLevelType.User);
     return level.GetNamedPermissionSet("LocalIntranet");
 }
コード例 #10
0
ファイル: policylevel.cs プロジェクト: ArildF/masters
 internal static NamedPermissionSet CreateLocalIntranetSet()
 {
     PolicyLevel level = new PolicyLevel( "Temp" );
     
     return level.GetNamedPermissionSet( "LocalIntranet" );
 }            
コード例 #11
0
	public SecurityElement ToXml(PolicyLevel level)
			{
				SecurityElement element;
				element = new SecurityElement("CodeGroup");
				element.AddAttribute
					("class",
					 SecurityElement.Escape(GetType().AssemblyQualifiedName));
				element.AddAttribute("version", "1");
				element.AddChild(membershipCondition.ToXml(level));
				if(policy != null)
				{
					PermissionSet permSet = policy.PermissionSetNoCopy;
					if(permSet is NamedPermissionSet && level != null &&
					   level.GetNamedPermissionSet
					   		(((NamedPermissionSet)permSet).Name) != null)
					{
						element.AddAttribute
							("PermissionSetName",
							 ((NamedPermissionSet)permSet).Name);
					}
					else if(!permSet.IsEmpty())
					{
						element.AddChild(permSet.ToXml());
					}
					if(policy.Attributes != PolicyStatementAttribute.Nothing)
					{
						element.AddAttribute
							("Attributes", policy.Attributes.ToString());
					}
					foreach(CodeGroup group in Children)
					{
						element.AddChild(group.ToXml(level));
					}
				}
				if(name != null)
				{
					element.AddAttribute("Name", SecurityElement.Escape(name));
				}
				if(description != null)
				{
					element.AddAttribute
						("Description", SecurityElement.Escape(description));
				}
				CreateXml(element, level);
				return element;
			}
コード例 #12
0
ファイル: PluginManager.cs プロジェクト: truonghinh/TnX
 static void MakePluginCodeGroup(PolicyLevel level, CodeGroup root, String url)
 {
     // Create a membership condition for our path
       IMembershipCondition membership =
      new UrlMembershipCondition(url);
       // Get the internet permissiion set
       PermissionSet permissions =
      level.GetNamedPermissionSet("Internet");
       permissions.GetType(); // Again, no nulls allowed
       // Create a policy statement from the permissions and condition
       PolicyStatement statement = new PolicyStatement(permissions,
      PolicyStatementAttribute.Exclusive |
      PolicyStatementAttribute.LevelFinal);
       // New code group
       UnionCodeGroup group = new UnionCodeGroup(membership, statement);
       group.Description=String.Format(
      "Code group that restricts permissions on "+
      "assemblies in {0}, to support secure loading of plugins. "+
      "This group was added by application: {1}", url,
      Assembly.GetEntryAssembly().CodeBase);
       group.Name = GenerateCodeGroupName(url);
       root.AddChild(group);
       SecurityManager.SavePolicyLevel(level);
 }
コード例 #13
0
ファイル: CodeGroup.cs プロジェクト: KonajuGames/SharpLang
		public void FromXml (SecurityElement e, PolicyLevel level)
		{
			if (null == e)
				throw new ArgumentNullException("e");

			PermissionSet ps = null;
			string psetname = e.Attribute ("PermissionSetName");
			if ((psetname != null) && (level != null)) {
				ps = level.GetNamedPermissionSet (psetname);
			}
			else {
				SecurityElement pset = e.SearchForChildByTag ("PermissionSet");
				if (pset != null) {
					Type classType = Type.GetType (pset.Attribute ("class"));
					ps = (PermissionSet) Activator.CreateInstance (classType, true);
					ps.FromXml (pset);
				}
				else {
					ps = new PermissionSet (new PermissionSet (PermissionState.None));
				}
			}
			m_policy = new PolicyStatement (ps);

			m_children.Clear ();
			if ((e.Children != null) && (e.Children.Count > 0)) {
				foreach (SecurityElement se in e.Children) {
					if (se.Tag == "CodeGroup") {
						this.AddChild (CodeGroup.CreateFromXml (se, level));
					}
				}
			}
			
			m_membershipCondition = null;
			SecurityElement mc = e.SearchForChildByTag ("IMembershipCondition");
			if (mc != null) {
				string className = mc.Attribute ("class");
				Type classType = Type.GetType (className);
				if (classType == null)
					classType = Type.GetType ("System.Security.Policy." + className);
				m_membershipCondition = (IMembershipCondition) Activator.CreateInstance (classType, true);
				m_membershipCondition.FromXml (mc, level);
			}

			m_name = e.Attribute("Name");
			m_description = e.Attribute("Description");

			// seems like we might need this to Resolve() in subclasses
			//m_level = level;

			ParseXml (e, level);
		}
コード例 #14
0
ファイル: HttpRuntime.cs プロジェクト: consumentor/Server
 private void SetTrustParameters(TrustSection trustSection, SecurityPolicySection securityPolicySection, PolicyLevel policyLevel)
 {
   this._trustLevel = trustSection.Level;
   if (!(this._trustLevel != "Full"))
     return;
   this._namedPermissionSet = policyLevel.GetNamedPermissionSet(trustSection.PermissionSetName);
   this._policyLevel = policyLevel;
   this._hostSecurityPolicyResolverType = trustSection.HostSecurityPolicyResolverType;
   this._fcm.StartMonitoringFile(securityPolicySection.TrustLevels[trustSection.Level].PolicyFileExpanded, new FileChangeEventHandler(this.OnSecurityPolicyFileChange));
 }