The Labs \ Source Viewer \ SSCLI \ System.Security.Policy \ UnionCodeGroup

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. // UnionCodeGroup.cs
  16. //
  17. // Representation for code groups used for the policy mechanism
  18. //
  19. namespace System.Security.Policy
  20. {
  21.    
  22.     using System;
  23.     using System.Security.Util;
  24.     using System.Security;
  25.     using System.Collections;
  26.    
  27.     [Serializable()]
  28.     [System.Runtime.InteropServices.ComVisible(true)]
  29.     public sealed class UnionCodeGroup : CodeGroup, IUnionSemanticCodeGroup
  30.     {
  31.         internal UnionCodeGroup() : base()
  32.         {
  33.         }
  34.        
  35.         internal UnionCodeGroup(IMembershipCondition membershipCondition, PermissionSet permSet) : base(membershipCondition, permSet)
  36.         {
  37.         }
  38.        
  39.         public UnionCodeGroup(IMembershipCondition membershipCondition, PolicyStatement policy) : base(membershipCondition, policy)
  40.         {
  41.         }
  42.        
  43.        
  44.         public override PolicyStatement Resolve(Evidence evidence)
  45.         {
  46.             if (evidence == null)
  47.                 throw new ArgumentNullException("evidence");
  48.            
  49.             if (this.MembershipCondition.Check(evidence)) {
  50.                 PolicyStatement thisPolicy = this.PolicyStatement;
  51.                
  52.                 IEnumerator enumerator = this.Children.GetEnumerator();
  53.                
  54.                 while (enumerator.MoveNext()) {
  55.                     PolicyStatement childPolicy = ((CodeGroup)enumerator.Current).Resolve(evidence);
  56.                    
  57.                     if (childPolicy != null) {
  58.                         if (((thisPolicy.Attributes & childPolicy.Attributes) & PolicyStatementAttribute.Exclusive) == PolicyStatementAttribute.Exclusive) {
  59.                             throw new PolicyException(Environment.GetResourceString("Policy_MultipleExclusive"));
  60.                         }
  61.                        
  62.                         thisPolicy.GetPermissionSetNoCopy().InplaceUnion(childPolicy.GetPermissionSetNoCopy());
  63.                         thisPolicy.Attributes = thisPolicy.Attributes | childPolicy.Attributes;
  64.                     }
  65.                 }
  66.                
  67.                 return thisPolicy;
  68.             }
  69.             else {
  70.                 return null;
  71.             }
  72.         }
  73.        
  74.         /// <internalonly/>
  75.         PolicyStatement IUnionSemanticCodeGroup.InternalResolve(Evidence evidence)
  76.         {
  77.             if (evidence == null)
  78.                 throw new ArgumentNullException("evidence");
  79.            
  80.             if (this.MembershipCondition.Check(evidence)) {
  81.                 return this.PolicyStatement;
  82.             }
  83.             else {
  84.                 return null;
  85.             }
  86.         }
  87.        
  88.         public override CodeGroup ResolveMatchingCodeGroups(Evidence evidence)
  89.         {
  90.             if (evidence == null)
  91.                 throw new ArgumentNullException("evidence");
  92.            
  93.             if (this.MembershipCondition.Check(evidence)) {
  94.                 CodeGroup retGroup = this.Copy();
  95.                
  96.                 retGroup.Children = new ArrayList();
  97.                
  98.                 IEnumerator enumerator = this.Children.GetEnumerator();
  99.                
  100.                 while (enumerator.MoveNext()) {
  101.                     CodeGroup matchingGroups = ((CodeGroup)enumerator.Current).ResolveMatchingCodeGroups(evidence);
  102.                    
  103.                     // If the child has a policy, we are done.
  104.                    
  105.                     if (matchingGroups != null) {
  106.                         retGroup.AddChild(matchingGroups);
  107.                     }
  108.                 }
  109.                
  110.                 return retGroup;
  111.                
  112.             }
  113.             else {
  114.                 return null;
  115.             }
  116.         }
  117.        
  118.        
  119.         public override CodeGroup Copy()
  120.         {
  121.             UnionCodeGroup group = new UnionCodeGroup();
  122.            
  123.             group.MembershipCondition = this.MembershipCondition;
  124.             group.PolicyStatement = this.PolicyStatement;
  125.             group.Name = this.Name;
  126.             group.Description = this.Description;
  127.            
  128.             IEnumerator enumerator = this.Children.GetEnumerator();
  129.            
  130.             while (enumerator.MoveNext()) {
  131.                 group.AddChild((CodeGroup)enumerator.Current);
  132.             }
  133.            
  134.            
  135.             return group;
  136.         }
  137.        
  138.         public override string MergeLogic {
  139.             get { return Environment.GetResourceString("MergeLogic_Union"); }
  140.         }
  141.        
  142.         internal override string GetTypeName()
  143.         {
  144.             return "System.Security.Policy.UnionCodeGroup";
  145.         }
  146.        
  147.     }
  148.    
  149. }

Developer Fusion