当前位置: 首页>>代码示例>>C#>>正文


C# PermissionSet.GetPermission方法代码示例

本文整理汇总了C#中System.Security.PermissionSet.GetPermission方法的典型用法代码示例。如果您正苦于以下问题:C# PermissionSet.GetPermission方法的具体用法?C# PermissionSet.GetPermission怎么用?C# PermissionSet.GetPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.PermissionSet的用法示例。


在下文中一共展示了PermissionSet.GetPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckAssert

 private static bool CheckAssert(PermissionSet pSet, CodeAccessPermission demand, PermissionToken permToken)
 {
     if (pSet != null)
     {
         pSet.CheckDecoded(demand, permToken);
         CodeAccessPermission asserted = (CodeAccessPermission) pSet.GetPermission(demand);
         try
         {
             if (pSet.IsUnrestricted() || demand.CheckAssert(asserted))
             {
                 return false;
             }
         }
         catch (ArgumentException)
         {
         }
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:PermissionSetTriple.cs

示例2: GetPermission_Null

		public void GetPermission_Null ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			Assert.IsNull (ps.GetPermission (null), "Empty");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:5,代码来源:PermissionSetTest.cs

示例3: GetPermission_Unrestricted

		public void GetPermission_Unrestricted ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
			Assert.IsNull (ps.GetPermission (typeof (SecurityPermission)), "Empty");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:5,代码来源:PermissionSetTest.cs

示例4: CheckHelper

        [System.Security.SecurityCritical]  // auto-generated
#pragma warning disable 618
        internal static bool CheckHelper(PermissionSet grantedSet,
#pragma warning restore 618
                                        PermissionSet refusedSet,
                                        CodeAccessPermission demand, 
                                        PermissionToken permToken,
                                        RuntimeMethodHandleInternal rmh,
                                        Object assemblyOrString,
                                        SecurityAction action,
                                        bool throwException)
        {
            // We should never get here with a null demand
            Contract.Assert(demand != null, "Should not reach here with a null demand");
            
#if _DEBUG && FEATURE_CAS_POLICY
            if (debug)
            {
                DEBUG_OUT("Granted: ");
                DEBUG_OUT(grantedSet.ToXml().ToString());
                DEBUG_OUT("Refused: ");
                DEBUG_OUT(refusedSet != null ? refusedSet.ToXml().ToString() : "<null>");
                DEBUG_OUT("Demanded: ");
                DEBUG_OUT(demand.ToString());
            }
#endif // _DEBUG && FEATURE_CAS_POLICY

            if (permToken == null)
                permToken = PermissionToken.GetToken(demand);

            if (grantedSet != null)
                grantedSet.CheckDecoded(permToken.m_index);
            if (refusedSet != null)
                refusedSet.CheckDecoded(permToken.m_index);

            // If PermissionSet is null, then module does not have Permissions... Fail check.

            bool bThreadSecurity = SecurityManager._SetThreadSecurity(false);

            try
            {
                if (grantedSet == null)
                {
                    if (throwException)
                        ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                    else
                        return false;
                }
                
                else if (!grantedSet.IsUnrestricted())
                {
                    // If we aren't unrestricted, there is a refused set, or our permission is not of the unrestricted
                    // variety, we need to do the proper callback.

                    Contract.Assert(demand != null,"demand != null");

                    // Find the permission of matching type in the permission set.

                    CodeAccessPermission grantedPerm = 
                                (CodeAccessPermission)grantedSet.GetPermission(permToken);

                    // Make sure the demand has been granted
                    if (!demand.CheckDemand( grantedPerm ))
                    {
                        if (throwException)
                            ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                        else
                            return false;
                    }
                }

                // Make the sure the permission is not refused.

                if (refusedSet != null)
                {
                    CodeAccessPermission refusedPerm = 
                        (CodeAccessPermission)refusedSet.GetPermission(permToken);
                    if (refusedPerm != null)
                    {
                        if (!refusedPerm.CheckDeny(demand))
                        {
        #if _DEBUG
                            if (debug)
                                DEBUG_OUT( "Permission found in refused set" );
        #endif
                                if (throwException)
                                    ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                                else
                                    return false;

                        }
                    }

                    if (refusedSet.IsUnrestricted())
                    {
                        if (throwException)
                            ThrowSecurityException(assemblyOrString, grantedSet, refusedSet, rmh, action, demand, demand);
                        else
                            return false;
                    }
//.........这里部分代码省略.........
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:codeaccesssecurityengine.cs

示例5: GetPermission

        /// <include file='doc\IsolatedStorageFile.uex' path='docs/doc[@for="IsolatedStorageFile.GetPermission"]/*' />
        protected override IsolatedStoragePermission GetPermission(
                PermissionSet ps)
        {
            if (ps == null)
                return null;
            else if (ps.IsUnrestricted())
                return new IsolatedStorageFilePermission(
                        PermissionState.Unrestricted);

            return (IsolatedStoragePermission) ps.
                    GetPermission(typeof(IsolatedStorageFilePermission));
        }
开发者ID:ArildF,项目名称:masters,代码行数:13,代码来源:isolatedstoragefile.cs

示例6: GetSpecialFlags

        internal static int GetSpecialFlags (PermissionSet grantSet, PermissionSet deniedSet) {
            if ((grantSet != null && grantSet.IsUnrestricted()) && (deniedSet == null || deniedSet.IsEmpty())) {
                return -1;
            }
            else {
                SecurityPermission securityPermission = null;
#pragma warning disable 618
                SecurityPermissionFlag securityPermissionFlags = SecurityPermissionFlag.NoFlags;
#pragma warning restore 618
                ReflectionPermission reflectionPermission = null;
                ReflectionPermissionFlag reflectionPermissionFlags = ReflectionPermissionFlag.NoFlags;

                CodeAccessPermission[] specialPermissions = new CodeAccessPermission[6];
                if (grantSet != null) {
                    if (grantSet.IsUnrestricted()) {
                        securityPermissionFlags = SecurityPermissionFlag.AllFlags;
                        reflectionPermissionFlags = ReflectionPermission.AllFlagsAndMore;
                        for (int i = 0; i < specialPermissions.Length; i++) {
                            specialPermissions[i] = s_UnrestrictedSpecialPermissionMap[i];
                        }
                    }
                    else {
                        securityPermission = grantSet.GetPermission(BuiltInPermissionIndex.SecurityPermissionIndex) as SecurityPermission;
                        if (securityPermission != null)
                            securityPermissionFlags = securityPermission.Flags;
                        reflectionPermission = grantSet.GetPermission(BuiltInPermissionIndex.ReflectionPermissionIndex) as ReflectionPermission;
                        if (reflectionPermission != null)
                            reflectionPermissionFlags = reflectionPermission.Flags;
                        for (int i = 0; i < specialPermissions.Length; i++) {
                            specialPermissions[i] = grantSet.GetPermission(s_BuiltInPermissionIndexMap[i][0]) as CodeAccessPermission;
                        }
                    }
                }

                if (deniedSet != null) {
                    if (deniedSet.IsUnrestricted()) {
                        securityPermissionFlags = SecurityPermissionFlag.NoFlags;
                        reflectionPermissionFlags = ReflectionPermissionFlag.NoFlags;
                        for (int i = 0; i < s_BuiltInPermissionIndexMap.Length; i++) {
                            specialPermissions[i] = null;
                        }
                    }
                    else {
                        securityPermission = deniedSet.GetPermission(BuiltInPermissionIndex.SecurityPermissionIndex) as SecurityPermission;
                        if (securityPermission != null)
                            securityPermissionFlags &= ~securityPermission.Flags;
                        reflectionPermission = deniedSet.GetPermission(BuiltInPermissionIndex.ReflectionPermissionIndex) as ReflectionPermission;
                        if (reflectionPermission != null)
                            reflectionPermissionFlags &= ~reflectionPermission.Flags;
                        for (int i = 0; i < s_BuiltInPermissionIndexMap.Length; i++) {
                            CodeAccessPermission deniedSpecialPermission = deniedSet.GetPermission(s_BuiltInPermissionIndexMap[i][0]) as CodeAccessPermission;
                            if (deniedSpecialPermission != null && !deniedSpecialPermission.IsSubsetOf(null))
                                specialPermissions[i] = null; // we don't care about the exact value here.
                        }
                    }
                }
                int flags = MapToSpecialFlags(securityPermissionFlags, reflectionPermissionFlags);
                if (flags != -1) {
                    for (int i = 0; i < specialPermissions.Length; i++) {
                        if (specialPermissions[i] != null && ((IUnrestrictedPermission) specialPermissions[i]).IsUnrestricted())
                            flags |= (1 << (int) s_BuiltInPermissionIndexMap[i][1]);
                    }
                }
                return flags;
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:66,代码来源:SecurityManager.cs

示例7: CheckAssert

        [System.Security.SecurityCritical]  // auto-generated
        static bool CheckAssert(PermissionSet pSet, CodeAccessPermission demand, PermissionToken permToken)
        {
            if (pSet != null)
            {
                pSet.CheckDecoded(demand, permToken);

                CodeAccessPermission perm = (CodeAccessPermission)pSet.GetPermission(demand);
            
                // If the assert set does contain the demanded permission, halt the stackwalk

                try
                {
                    if (pSet.IsUnrestricted() || demand.CheckAssert(perm))
                    {
                        return SecurityRuntime.StackHalt;
                    }
                }
                catch (ArgumentException)
                {
                }
            }
            return SecurityRuntime.StackContinue;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:24,代码来源:permissionsettriple.cs

示例8: CheckDeny

 internal bool CheckDeny(PermissionSet deniedSet, out IPermission firstPermThatFailed)
 {
     firstPermThatFailed = null;
     if (((deniedSet != null) && !deniedSet.FastIsEmpty()) && !this.FastIsEmpty())
     {
         if (this.m_Unrestricted && deniedSet.m_Unrestricted)
         {
             return false;
         }
         PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(this);
         while (internal2.MoveNext())
         {
             CodeAccessPermission current = internal2.Current as CodeAccessPermission;
             if ((current != null) && !current.IsSubsetOf(null))
             {
                 if (deniedSet.m_Unrestricted)
                 {
                     firstPermThatFailed = current;
                     return false;
                 }
                 CodeAccessPermission permission = (CodeAccessPermission) deniedSet.GetPermission(internal2.GetCurrentIndex());
                 if (!current.CheckDeny(permission))
                 {
                     firstPermThatFailed = current;
                     return false;
                 }
             }
         }
         if (this.m_Unrestricted)
         {
             PermissionSetEnumeratorInternal internal3 = new PermissionSetEnumeratorInternal(deniedSet);
             while (internal3.MoveNext())
             {
                 if (internal3.Current is IPermission)
                 {
                     return false;
                 }
             }
         }
     }
     return true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:42,代码来源:PermissionSet.cs

示例9: GetPermission

		protected override IsolatedStoragePermission GetPermission (PermissionSet ps)
		{
			if (ps == null)
				return null;
			return (IsolatedStoragePermission) ps.GetPermission (typeof (IsolatedStorageFilePermission));
		}
开发者ID:runefs,项目名称:Marvin,代码行数:6,代码来源:IsolatedStorageFile.cs

示例10: RemoveAssertedPermissionSet

 internal static void RemoveAssertedPermissionSet(PermissionSet demandSet, PermissionSet assertSet, out PermissionSet alteredDemandSet)
 {
     alteredDemandSet = null;
     PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(demandSet);
     while (internal2.MoveNext())
     {
         CodeAccessPermission current = (CodeAccessPermission) internal2.Current;
         int currentIndex = internal2.GetCurrentIndex();
         if (current != null)
         {
             CodeAccessPermission permission = (CodeAccessPermission) assertSet.GetPermission(currentIndex);
             try
             {
                 if (current.CheckAssert(permission))
                 {
                     if (alteredDemandSet == null)
                     {
                         alteredDemandSet = demandSet.Copy();
                     }
                     alteredDemandSet.RemovePermission(currentIndex);
                 }
                 continue;
             }
             catch (ArgumentException)
             {
                 continue;
             }
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:PermissionSet.cs

示例11: RemoveRefusedPermissionSet

 internal static PermissionSet RemoveRefusedPermissionSet(PermissionSet assertSet, PermissionSet refusedSet, out bool bFailedToCompress)
 {
     PermissionSet set = null;
     bFailedToCompress = false;
     if (assertSet == null)
     {
         return null;
     }
     if (refusedSet != null)
     {
         if (refusedSet.IsUnrestricted())
         {
             return null;
         }
         PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(refusedSet);
         while (internal2.MoveNext())
         {
             CodeAccessPermission current = (CodeAccessPermission) internal2.Current;
             int currentIndex = internal2.GetCurrentIndex();
             if (current != null)
             {
                 CodeAccessPermission permission = (CodeAccessPermission) assertSet.GetPermission(currentIndex);
                 try
                 {
                     if (current.Intersect(permission) == null)
                     {
                         continue;
                     }
                     if (current.Equals(permission))
                     {
                         if (set == null)
                         {
                             set = assertSet.Copy();
                         }
                         set.RemovePermission(currentIndex);
                         continue;
                     }
                     bFailedToCompress = true;
                     return assertSet;
                 }
                 catch (ArgumentException)
                 {
                     if (set == null)
                     {
                         set = assertSet.Copy();
                     }
                     set.RemovePermission(currentIndex);
                     continue;
                 }
             }
         }
     }
     if (set != null)
     {
         return set;
     }
     return assertSet;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:58,代码来源:PermissionSet.cs

示例12: IsSubsetOfHelper

        internal bool IsSubsetOfHelper(PermissionSet target, IsSubsetOfType type, out IPermission firstPermThatFailed, bool ignoreNonCas)
        {
            firstPermThatFailed = null;
            if ((target == null) || target.FastIsEmpty())
            {
                if (this.IsEmpty())
                {
                    return true;
                }
                firstPermThatFailed = this.GetFirstPerm();
                return false;
            }
            if (this.IsUnrestricted() && !target.IsUnrestricted())
            {
                return false;
            }
            if (this.m_permSet != null)
            {
                target.CheckSet();
                for (int i = this.m_permSet.GetStartingIndex(); i <= this.m_permSet.GetMaxUsedIndex(); i++)
                {
                    IPermission permission = this.GetPermission(i);
                    if ((permission != null) && !permission.IsSubsetOf(null))
                    {
                        IPermission permission2 = target.GetPermission(i);
                        if (!target.m_Unrestricted)
                        {
                            CodeAccessPermission permission3 = permission as CodeAccessPermission;
                            if (permission3 == null)
                            {
                                if (!ignoreNonCas && !permission.IsSubsetOf(permission2))
                                {
                                    firstPermThatFailed = permission;
                                    return false;
                                }
                                continue;
                            }
                            firstPermThatFailed = permission;
                            switch (type)
                            {
                                case IsSubsetOfType.Normal:
                                    if (permission.IsSubsetOf(permission2))
                                    {
                                        break;
                                    }
                                    return false;

                                case IsSubsetOfType.CheckDemand:
                                    if (permission3.CheckDemand((CodeAccessPermission) permission2))
                                    {
                                        break;
                                    }
                                    return false;

                                case IsSubsetOfType.CheckPermitOnly:
                                    if (permission3.CheckPermitOnly((CodeAccessPermission) permission2))
                                    {
                                        break;
                                    }
                                    return false;

                                case IsSubsetOfType.CheckAssertion:
                                    if (permission3.CheckAssert((CodeAccessPermission) permission2))
                                    {
                                        break;
                                    }
                                    return false;
                            }
                            firstPermThatFailed = null;
                        }
                    }
                }
            }
            return true;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:75,代码来源:PermissionSet.cs

示例13: IsIntersectingAssertedPermissions

 internal static bool IsIntersectingAssertedPermissions(PermissionSet assertSet1, PermissionSet assertSet2)
 {
     bool flag = false;
     if ((assertSet1 != null) && (assertSet2 != null))
     {
         PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(assertSet2);
         while (internal2.MoveNext())
         {
             CodeAccessPermission current = (CodeAccessPermission) internal2.Current;
             int currentIndex = internal2.GetCurrentIndex();
             if (current != null)
             {
                 CodeAccessPermission permission = (CodeAccessPermission) assertSet1.GetPermission(currentIndex);
                 try
                 {
                     if ((permission != null) && !permission.Equals(current))
                     {
                         flag = true;
                     }
                     continue;
                 }
                 catch (ArgumentException)
                 {
                     flag = true;
                     continue;
                 }
             }
         }
     }
     return flag;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:31,代码来源:PermissionSet.cs

示例14: GetSpecialFlags

 internal static int GetSpecialFlags(PermissionSet grantSet, PermissionSet deniedSet)
 {
     if (((grantSet != null) && grantSet.IsUnrestricted()) && ((deniedSet == null) || deniedSet.IsEmpty()))
     {
         return -1;
     }
     SecurityPermission permission = null;
     SecurityPermissionFlag noFlags = SecurityPermissionFlag.NoFlags;
     ReflectionPermission permission2 = null;
     ReflectionPermissionFlag reflectionPermissionFlags = ReflectionPermissionFlag.NoFlags;
     CodeAccessPermission[] permissionArray = new CodeAccessPermission[6];
     if (grantSet != null)
     {
         if (grantSet.IsUnrestricted())
         {
             noFlags = SecurityPermissionFlag.AllFlags;
             reflectionPermissionFlags = ReflectionPermissionFlag.RestrictedMemberAccess | ReflectionPermissionFlag.AllFlags;
             for (int i = 0; i < permissionArray.Length; i++)
             {
                 permissionArray[i] = s_UnrestrictedSpecialPermissionMap[i];
             }
         }
         else
         {
             permission = grantSet.GetPermission(6) as SecurityPermission;
             if (permission != null)
             {
                 noFlags = permission.Flags;
             }
             permission2 = grantSet.GetPermission(4) as ReflectionPermission;
             if (permission2 != null)
             {
                 reflectionPermissionFlags = permission2.Flags;
             }
             for (int j = 0; j < permissionArray.Length; j++)
             {
                 permissionArray[j] = grantSet.GetPermission(s_BuiltInPermissionIndexMap[j][0]) as CodeAccessPermission;
             }
         }
     }
     if (deniedSet != null)
     {
         if (deniedSet.IsUnrestricted())
         {
             noFlags = SecurityPermissionFlag.NoFlags;
             reflectionPermissionFlags = ReflectionPermissionFlag.NoFlags;
             for (int k = 0; k < s_BuiltInPermissionIndexMap.Length; k++)
             {
                 permissionArray[k] = null;
             }
         }
         else
         {
             permission = deniedSet.GetPermission(6) as SecurityPermission;
             if (permission != null)
             {
                 noFlags &= ~permission.Flags;
             }
             permission2 = deniedSet.GetPermission(4) as ReflectionPermission;
             if (permission2 != null)
             {
                 reflectionPermissionFlags &= ~permission2.Flags;
             }
             for (int m = 0; m < s_BuiltInPermissionIndexMap.Length; m++)
             {
                 CodeAccessPermission permission3 = deniedSet.GetPermission(s_BuiltInPermissionIndexMap[m][0]) as CodeAccessPermission;
                 if ((permission3 != null) && !permission3.IsSubsetOf(null))
                 {
                     permissionArray[m] = null;
                 }
             }
         }
     }
     int num5 = MapToSpecialFlags(noFlags, reflectionPermissionFlags);
     if (num5 != -1)
     {
         for (int n = 0; n < permissionArray.Length; n++)
         {
             if ((permissionArray[n] != null) && ((IUnrestrictedPermission) permissionArray[n]).IsUnrestricted())
             {
                 num5 |= ((int) 1) << s_BuiltInPermissionIndexMap[n][1];
             }
         }
     }
     return num5;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:86,代码来源:SecurityManager.cs

示例15: InternalIntersect

		internal void InternalIntersect (PermissionSet intersect, PermissionSet a, PermissionSet b, bool unrestricted)
		{
			foreach (IPermission p in b.list) {
				// for every type in both list
				IPermission i = a.GetPermission (p.GetType ());
				if (i != null) {
					// add intersection for this type
					intersect.AddPermission (p.Intersect (i));
				}
				// unrestricted is possible for indentity permissions
				else if (unrestricted) {
					intersect.AddPermission (p);
				}
				// or reject!
			}
		}
开发者ID:zxlin25,项目名称:mono,代码行数:16,代码来源:PermissionSet.cs


注:本文中的System.Security.PermissionSet.GetPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。