Beispiel #1
0
        internal static bool CanUseQuickCache(CodeGroup group)
        {
            ArrayList arrayList = new ArrayList();

            arrayList.Add((object)group);
            for (int index = 0; index < arrayList.Count; ++index)
            {
                group = (CodeGroup)arrayList[index];
                if (!(group is IUnionSemanticCodeGroup) || !PolicyManager.TestPolicyStatement(group.PolicyStatement))
                {
                    return(false);
                }
                IMembershipCondition membershipCondition = group.MembershipCondition;
                if (membershipCondition != null && !(membershipCondition is IConstantMembershipCondition))
                {
                    return(false);
                }
                IList children = group.Children;
                if (children != null && children.Count > 0)
                {
                    foreach (object obj in (IEnumerable)children)
                    {
                        arrayList.Add(obj);
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
        private static void RemovePolicy(string path, string name)
        {
            //Get a reference to the User level "All Code" group.
            PolicyLevel polLevel = GetPolicy(_user);

            if (polLevel != null)
            {
                UnionCodeGroup allCodeCG =
                    (UnionCodeGroup)polLevel.RootCodeGroup;

                //Determine the resolved membership condition for the
                //specified path.
                string resolvedPath =
                    new UrlMembershipCondition(path).ToString();

                //Locate a code group with the same name, the same resolved
                //path, and FullTrust; if found, remove the child group.
                IEnumerator cgs = allCodeCG.Children.GetEnumerator();
                while (cgs.MoveNext())
                {
                    CodeGroup cg = (CodeGroup)cgs.Current;
                    if (cg.Name == name)
                    {
                        if (cg.MembershipCondition.ToString() == resolvedPath &&
                            allCodeCG.PermissionSetName == _fullTrust)
                        {
                            allCodeCG.RemoveChild(cg);
                            SecurityManager.SavePolicy();
                            break;
                        }
                    }
                }
            }
        }
Beispiel #3
0
    //<Snippet13>
    // Demonstrate the use of ResolvePolicy for the supplied evidence and a specified policy level.
    private static void CheckEvidence(PolicyLevel pLevel, Evidence evidence)
    {
        // Display the code groups to which the evidence belongs.
        Console.WriteLine("\tResolvePolicy for the given evidence: ");
        IEnumerator codeGroup = evidence.GetEnumerator();

        while (codeGroup.MoveNext())
        {
            Console.WriteLine("\t\t" + ((CodeGroup)codeGroup.Current).Name);
        }
        Console.WriteLine("The current evidence belongs to the following root CodeGroup:");
        // pLevel is the current PolicyLevel, evidence is the Evidence to be resolved.
        CodeGroup cg1 = pLevel.ResolveMatchingCodeGroups(evidence);

        Console.WriteLine(pLevel.Label + " Level");
        Console.WriteLine("\tRoot CodeGroup = " + cg1.Name);

        // Show how Resolve is used to determine the set of permissions that
        // the security system grants to code, based on the evidence.

        // Show the granted permissions.
        Console.WriteLine("\nCurrent permissions granted:");
        PolicyStatement pState = pLevel.Resolve(evidence);

        Console.WriteLine(pState.ToXml().ToString());

        return;
    }
Beispiel #4
0
        }// RemoveChildCodegroup

        internal override void SecurityPolicyChanged(bool fShowDialog)
        {
            if (!m_fIAmDeleted)
            {
                // We need to catch this policy change in the event that our display name
                // has changed
                if (m_cg.Name == null || m_cg.Name.Length == 0)
                {
                    m_sDisplayName = CResourceStore.GetString("CSingleCodeGroup:NoName");
                }
                else
                {
                    m_sDisplayName = m_cg.Name;
                }

                // We need to remove this node from the policy tree, then replace it
                // with the updated Codegroup
                if (Security.GetRootCodeGroupNode(m_pl) == this)
                {
                    // This is the easy case... we'll just replace the root code
                    m_pl.RootCodeGroup = m_cg;
                }
                else
                {
                    // We need to do a big deal update
                    Security.UpdateCodegroup(m_pl, this);
                }
                m_cgOld = m_cg.Copy();
                RefreshResultView();
            }
            base.SecurityPolicyChanged(fShowDialog);
        } // SecurityPolicyChanged
        }// GetRootCodeGroupNode

        //-------------------------------------------------
        // CreateChildren
        //
        // This function will create all the codegroup nodes
        // for this policy level
        //-------------------------------------------------
        internal override void CreateChildren()
        {
            SuperCodeGroupArrayList al;

            Security.ListifyCodeGroup(m_pl.RootCodeGroup.Copy(), null, out al);


            // Now run through all the others and put them in too
            for (int i = 0; i < al.Count; i++)
            {
                CNode parentNode;
                // If this is the root codegroup, it has a different parent
                if (i == 0)
                {
                    parentNode = this;
                }
                else
                {
                    parentNode = (CNode)(al[al[i].nParent].o);
                }

                CodeGroup cg        = al[i].cg;
                CNode     childNode = new CSingleCodeGroup(ref m_pl, ref cg, ReadOnly);
                int       iCookie   = CNodeManager.AddNode(ref childNode);
                parentNode.AddChild(iCookie);

                // Now set this codegroup's node
                al[i].o = childNode;
            }
        } // CreateChildren
        }// onDoubleClick

        private CodeGroup GetCGUsingPermissionSet(CodeGroup cg)
        {
            // See if we should even check this
            if (cg == null)
            {
                return(null);
            }

            // See if this code group uses the permission set
            if (cg.PermissionSetName != null)
            {
                if (cg.PermissionSetName.Equals(m_psetWrapper.PSet.Name))
                {
                    return(cg);
                }
            }

            // Run through this code group's children and see if they use this
            // permission set

            IEnumerator enumCodeGroups = cg.Children.GetEnumerator();

            while (enumCodeGroups.MoveNext())
            {
                cg = (CodeGroup)enumCodeGroups.Current;
                CodeGroup cgUsing = GetCGUsingPermissionSet(cg);
                if (cgUsing != null)
                {
                    return(cgUsing);
                }
            }

            // Nobody here is using this permission set
            return(null);
        }// GetCGUsingPermissionSet
        // Token: 0x06001D76 RID: 7542 RVA: 0x00066A5C File Offset: 0x00064C5C
        internal static bool CanUseQuickCache(CodeGroup group)
        {
            ArrayList arrayList = new ArrayList();

            arrayList.Add(group);
            for (int i = 0; i < arrayList.Count; i++)
            {
                group = (CodeGroup)arrayList[i];
                IUnionSemanticCodeGroup unionSemanticCodeGroup = group as IUnionSemanticCodeGroup;
                if (unionSemanticCodeGroup == null)
                {
                    return(false);
                }
                if (!PolicyManager.TestPolicyStatement(group.PolicyStatement))
                {
                    return(false);
                }
                IMembershipCondition membershipCondition = group.MembershipCondition;
                if (membershipCondition != null && !(membershipCondition is IConstantMembershipCondition))
                {
                    return(false);
                }
                IList children = group.Children;
                if (children != null && children.Count > 0)
                {
                    foreach (object value in children)
                    {
                        arrayList.Add(value);
                    }
                }
            }
            return(true);
        }
        public void Remove(string Id)
        {
            CodeGroup p = context.CodeGroups.Find(Id);

            context.CodeGroups.Remove(p);
            context.SaveChanges();
        }
        public async Task <IActionResult> Edit(int id, [Bind("Code_grp,Code_nm,Sort_no,Use_yn,Memo1,Memo2,Input_dt,Update_dt,Input_id,Update_id")] CodeGroup codeGroup)
        {
            codeGroup.Update_dt = DateTime.Now;
            codeGroup.Update_id = User.FindFirst(ClaimTypes.Name).Value;

            if (id != codeGroup.Code_grp)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(codeGroup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CodeGroupExists(codeGroup.Code_grp))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(codeGroup));
        }
Beispiel #10
0
        // -ag label|name membership psetname flag
        // -addgroup label|name membership psetname flag
        static bool AddCodeGroup(string[] args, ref int i)
        {
            string name = args [++i];

            PolicyLevel pl     = null;
            CodeGroup   parent = null;
            CodeGroup   cg     = FindCodeGroup(name, ref parent, ref pl);

            if ((pl == null) || (parent == null) || (cg == null))
            {
                return(false);
            }

            UnionCodeGroup child = new UnionCodeGroup(
                new AllMembershipCondition(),
                new PolicyStatement(new PermissionSet(PermissionState.Unrestricted)));

            if (!ProcessCodeGroup(child, args, ref i))
            {
                return(false);
            }

            cg.AddChild(child);
            SecurityManager.SavePolicyLevel(pl);
            Console.WriteLine("CodeGroup '{0}' added in {1} policy level.",
                              cg.Name, pl.Label);
            return(true);
        }
Beispiel #11
0
            public async Task <GetCodesByCodeGroupGuidVm> Handle(GetCodesByCodeGroupGuidQuery request, CancellationToken cancellationToken)
            {
                CodeGroup codeGroup = await _context.CodeGroup
                                      .SingleOrDefaultAsync(x => x.CodeGroupGuid == request.CodeGroupGuid && !x.IsDelete, cancellationToken);

                if (codeGroup == null)
                {
                    return new GetCodesByCodeGroupGuidVm()
                           {
                               Message = "کد وارد شده نامعتبر است",
                               State   = (int)CodeType.CodeGroupNotFound
                           }
                }
                ;

                List <GetCodesByCodeGroupGuidDto> codes = await _context.Code
                                                          .Where(x => x.CodeGroupId == codeGroup.CodeGroupId && !x.IsDelete)
                                                          .OrderBy(x => x.DisplayName)
                                                          .ProjectTo <GetCodesByCodeGroupGuidDto>(_mapper.ConfigurationProvider)
                                                          .ToListAsync(cancellationToken);

                return(new GetCodesByCodeGroupGuidVm()
                {
                    Message = "عملیات موفق آمیز",
                    State = (int)CodeType.Success,
                    Codes = codes
                });
            }
        }
Beispiel #12
0
        internal CSingleCodeGroup(ref PolicyLevel pl, ref CodeGroup cg, bool fReadOnly)
        {
            ReadOnly       = fReadOnly;
            m_sGuid        = "E1768EA0-51D6-42ea-BA97-C9BC7F4C5CC0";
            m_sHelpSection = "";

            if (cg.Name != null && cg.Name.Length > 0)
            {
                m_sDisplayName = cg.Name;
            }
            else
            {
                m_sDisplayName = CResourceStore.GetString("CSingleCodeGroup:NoName");
            }

            m_aPropSheetPage = null;

            if (cg is UnionCodeGroup)
            {
                m_hIcon    = CResourceStore.GetHIcon("singlecodegroup_ico");
                m_oResults = new CSingleCodeGroupTaskPad(this, cg);
            }
            else
            {
                m_hIcon    = CResourceStore.GetHIcon("customcodegroup_ico");
                m_oResults = new CNonUnionCGTaskPad(this, cg);
            }

            m_cg          = cg;
            m_cgOld       = m_cg.Copy();
            m_pl          = pl;
            m_fIAmDeleted = false;
        }// CSingleCodeGroup
Beispiel #13
0
        // Actions

        static void ShowCodeGroup(CodeGroup cg, string prefix)
        {
            Console.WriteLine("{0}. {1}: {2}", prefix, cg.MembershipCondition, cg.PermissionSetName);
            for (int i = 0; i < cg.Children.Count; i++)
            {
                ShowCodeGroup((CodeGroup)cg.Children [i], "  " + prefix + "." + (i + 1));
            }
        }
Beispiel #14
0
 static void ShowDescription(CodeGroup cg, string prefix)
 {
     Console.WriteLine("{0}. {1}: {2}", prefix, cg.Name, cg.Description);
     for (int i = 0; i < cg.Children.Count; i++)
     {
         ShowDescription((CodeGroup)cg.Children [i], "  " + prefix + "." + (i + 1));
     }
 }
 internal static PolicyStatement ResolveCodeGroup(CodeGroup codeGroup, Evidence evidence)
 {
     if (codeGroup.GetType().Assembly != typeof(UnionCodeGroup).Assembly)
     {
         evidence.MarkAllEvidenceAsUsed();
     }
     return(codeGroup.Resolve(evidence));
 }
Beispiel #16
0
        public static void UnionCodeGroupCallMethods()
        {
            UnionCodeGroup  ucg = new UnionCodeGroup(new GacMembershipCondition(), new PolicyStatement(new PermissionSet(new PermissionState())));
            CodeGroup       cg  = ucg.Copy();
            PolicyStatement ps  = ucg.Resolve(new Evidence());

            cg = ucg.ResolveMatchingCodeGroups(new Evidence());
        }
        // Demonstrate the use of ResolvePolicy.
        private static void CheckEvidence(Evidence evidence)
        {
            // Display the code groups to which the evidence belongs.
            Console.WriteLine("ResolvePolicy for the given evidence.");
            Console.WriteLine("Current evidence belongs to the following code groups:");
            IEnumerator policyEnumerator = SecurityManager.PolicyHierarchy();

            while (policyEnumerator.MoveNext())
            {
                PolicyLevel currentLevel = (PolicyLevel)policyEnumerator.Current;
                CodeGroup   cg1          = currentLevel.ResolveMatchingCodeGroups(evidence);
                Console.WriteLine(currentLevel.Label + " Level");
                Console.WriteLine("\tCodeGroup = " + cg1.Name);
                Console.WriteLine("StoreLocation = " + currentLevel.StoreLocation);
                IEnumerator cgE1 = cg1.Children.GetEnumerator();
                while (cgE1.MoveNext())
                {
                    Console.WriteLine("\t\tGroup = " + ((CodeGroup)cgE1.Current).Name);
                }
            }

            // Show how ResolvePolicy is used to determine the set of permissions that would be granted
            // by the security system to code, based on the evidence and the permission sets requested.
            // The permission sets require Execute permission; allow optional Read access permission
            // to C:\temp; and deny the code permission to control security policy.
            Console.WriteLine("\nCreate permission sets requiring Execute permission, requesting optional " +
                              "\nRead permission for 'C:\\temp', and dening permission to control policy.");
            PermissionSet requiredSet = new PermissionSet(PermissionState.None);

            requiredSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));

            PermissionSet optionalSet = new PermissionSet(PermissionState.None);

            optionalSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read, new string[] { @"c:\temp" }));

            PermissionSet deniedSet = new PermissionSet(PermissionState.None);

            deniedSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlPolicy));

            // Show the granted permissions.
            Console.WriteLine("\nCurrent permissions granted:");

            PermissionSet permsDenied = null;

            foreach (IPermission perm in SecurityManager.ResolvePolicy(evidence, requiredSet, optionalSet, deniedSet, out permsDenied))
            {
                Console.WriteLine(perm.ToXml().ToString());
            }

            // Show the denied permissions.
            Console.WriteLine("Current permissions denied:");
            foreach (IPermission perm in permsDenied)
            {
                Console.WriteLine(perm.ToXml().ToString());
            }

            return;
        }
Beispiel #18
0
        public void RemoveGroupIfExists(CodeGroup parentGroup, String name)
        {
            CodeGroup childGroup;

            while ((childGroup = GetChildGroup(parentGroup, name)) != null)
            {
                parentGroup.RemoveChild(childGroup);
            }
        }
Beispiel #19
0
        public void ResolveMatchingCodeGroups_OneLevel()
        {
            UnionCodeGroup level1 = new UnionCodeGroup(new AllMembershipCondition(), new PolicyStatement(new PermissionSet(PermissionState.None)));
            CodeGroup      match  = level1.ResolveMatchingCodeGroups(new Evidence());

            Assert.IsNotNull(match, "Match");
            Assert.IsTrue(match.Equals(level1, false), "Equals(false)");
            Assert.IsTrue(match.Equals(level1, true), "Equals(true)");
        }
Beispiel #20
0
        public static void FirstMatchCodeGroupCallMethods()
        {
#pragma warning disable 618
            FirstMatchCodeGroup fmcg = new FirstMatchCodeGroup(new GacMembershipCondition(), new PolicyStatement(new PermissionSet(new PermissionState())));
#pragma warning restore 618
            CodeGroup       cg = fmcg.Copy();
            PolicyStatement ps = fmcg.Resolve(new Evidence());
            cg = fmcg.ResolveMatchingCodeGroups(new Evidence());
        }
Beispiel #21
0
        public void ResolveMatchingCodeGroups_OneLevel()
        {
            FileCodeGroup level1 = new FileCodeGroup(new AllMembershipCondition(), FileIOPermissionAccess.AllAccess);
            CodeGroup     match  = level1.ResolveMatchingCodeGroups(new Evidence());

            Assert.IsNotNull(match, "Match");
            Assert.IsTrue(match.Equals(level1, false), "Equals(false)");
            Assert.IsTrue(match.Equals(level1, true), "Equals(true)");
        }
Beispiel #22
0
        static void ShowResolveGroup(PolicyLevel pl, Evidence e)
        {
            Console.WriteLine("{0}Level: {1}{0}", Environment.NewLine, pl.Label);
            CodeGroup cg = pl.ResolveMatchingCodeGroups(e);

            Console.WriteLine("Code Groups:{0}", Environment.NewLine);
            ShowCodeGroup(cg, "1");
            Console.WriteLine();
        }
        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);
        }
        public void CreateGroup(CodeGroup groups)
        {
            groups.UpdateDt = DateTime.Now;
            groups.CreateDt = DateTime.Now;
            groups.CreateId = System.Web.HttpContext.Current.User.Identity.GetUserId();
            groups.UpdateId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            context.CodeGroups.Add(groups);
            context.SaveChanges();
        }
Beispiel #25
0
        public static void FileCodeGroupCallMethods()
        {
            FileCodeGroup   fcg    = new FileCodeGroup(new GacMembershipCondition(), new FileIOPermissionAccess());
            CodeGroup       cg     = fcg.Copy();
            bool            equals = fcg.Equals(new object());
            int             hash   = fcg.GetHashCode();
            PolicyStatement ps     = fcg.Resolve(new Evidence());

            cg = fcg.ResolveMatchingCodeGroups(new Evidence());
        }
Beispiel #26
0
        public override int GetHashCode()
        {
            int result = 17;

            result = 31 * result + Code.GetHashCode();
            result = 31 * result + CodeGroup.GetHashCode();
            result = 31 * result + Description.GetHashCode();

            return(result);
        }
Beispiel #27
0
    // Retrieve the resolved code group based on the Evidence from
    // the executing assembly found in the specified code group.
    private static FileCodeGroup ResolveGroupToEvidence(
        FileCodeGroup fileCodeGroup)
    {
        // Resolve matching code groups to the executing assembly.
        Assembly  assembly  = typeof(Members).Assembly;
        Evidence  evidence  = assembly.Evidence;
        CodeGroup codeGroup =
            fileCodeGroup.ResolveMatchingCodeGroups(evidence);

        return((FileCodeGroup)codeGroup);
    }
Beispiel #28
0
        public void ResolveMatchingCodeGroups_Empty()
        {
            PolicyLevel pl     = PolicyLevel.CreateAppDomainLevel();
            CodeGroup   result = pl.ResolveMatchingCodeGroups(new Evidence());

            Assert.IsNotNull(result, "CodeGroup");
            Assert.AreEqual(String.Empty, result.AttributeString, "AttributeString");
            Assert.AreEqual(0, result.Children.Count, "Count");
            Assert.AreEqual("Union", result.MergeLogic, "MergeLogic");
            Assert.IsTrue(result.PolicyStatement.PermissionSet.IsUnrestricted(), "IsUnrestricted");
        }
#pragma warning disable 618
        internal static PolicyStatement ResolveCodeGroup(CodeGroup codeGroup, Evidence evidence)
        {
            // Custom code groups won't know how to mark the evidence they're using, so we need to
            // be pessimistic and mark it all as used if we encounter a code group from outside of mscorlib.
            if (codeGroup.GetType().Assembly != typeof(UnionCodeGroup).Assembly)
            {
                evidence.MarkAllEvidenceAsUsed();
            }

            return(codeGroup.Resolve(evidence));
        }
Beispiel #30
0
 private CodeGroup GetChildGroup(CodeGroup parentGroup, String name)
 {
     for (int i = 0; i < parentGroup.Children.Count; i++)
     {
         CodeGroup group = (CodeGroup)parentGroup.Children[i];
         if (String.Equals(group.Name, name))
         {
             return(group);
         }
     }
     return(null);
 }
	public void AddChild(CodeGroup group) {}
	public bool Equals(CodeGroup cg, bool compareChildren) {}
	public void RemoveChild(CodeGroup group) {}