System.Security.PermissionTokenFactory.BuiltInGetToken C# (CSharp) Method

BuiltInGetToken() private method

private BuiltInGetToken ( int index, IPermission perm, Type cls ) : PermissionToken
index int
perm IPermission
cls System.Type
return PermissionToken
        internal PermissionToken BuiltInGetToken( int index, IPermission perm, Type cls )
        {
            PermissionToken token = m_builtIn[index];

            if (token == null)
            {
                lock (this)
                {
                    token = m_builtIn[index];

                    if (token == null)
                    {
                        PermissionTokenType permType = PermissionTokenType.DontKnow;

                        if (perm != null)
                        {
                            if(CodeAccessSecurityEngine.DoesFullTrustMeanFullTrust() || perm is IUnrestrictedPermission)
                                permType = PermissionTokenType.IUnrestricted;
                            else
                                permType = PermissionTokenType.Normal;
                        }
                        else if (cls != null)
                        {
                            if(CodeAccessSecurityEngine.DoesFullTrustMeanFullTrust() || cls.GetInterface( "System.Security.Permissions.IUnrestrictedPermission" ) != null)
                                permType = PermissionTokenType.IUnrestricted;
                            else
                                permType = PermissionTokenType.Normal;
                        }

                        token = new PermissionToken( index, permType | PermissionTokenType.BuiltIn, null );
                        m_builtIn[index] = token;
                        PermissionToken.s_tokenSet.SetItem( token.m_index, token );
                    }
                }
            }

            if ((token.m_type & PermissionTokenType.DontKnow) != 0)
            {
                    token.m_type = PermissionTokenType.BuiltIn;

                    if (perm != null)
                    {
                        if(CodeAccessSecurityEngine.DoesFullTrustMeanFullTrust() || perm is IUnrestrictedPermission)
                            token.m_type |= PermissionTokenType.IUnrestricted;
                        else
                            token.m_type |= PermissionTokenType.Normal;
                    }
                    else if (cls != null)
                    {
                        if(CodeAccessSecurityEngine.DoesFullTrustMeanFullTrust() || cls.GetInterface( "System.Security.Permissions.IUnrestrictedPermission" ) != null)
                            token.m_type |= PermissionTokenType.IUnrestricted;
                        else
                            token.m_type |= PermissionTokenType.Normal;
                    }
                    else
                        token.m_type |= PermissionTokenType.DontKnow;
            }

            return token;
        }
    }

Usage Example

Example #1
0
        [System.Security.SecurityCritical]  // auto-generated
        public static PermissionToken GetToken(Type cls)
        {
            if (cls == null)
            {
                return(null);
            }

#if FEATURE_CAS_POLICY
            if (cls.GetInterface("System.Security.Permissions.IBuiltInPermission") != null)
            {
                if (s_reflectPerm == null)
                {
                    s_reflectPerm = new ReflectionPermission(PermissionState.Unrestricted);
                }
                s_reflectPerm.Assert();
                MethodInfo method = cls.GetMethod("GetTokenIndex", BindingFlags.Static | BindingFlags.NonPublic);
                Contract.Assert(method != null, "IBuiltInPermission types should have a static method called 'GetTokenIndex'");

                // GetTokenIndex needs to be invoked without any security checks, since doing a security check
                // will involve a ReflectionTargetDemand which creates a CompressedStack and attempts to get the
                // token.
                RuntimeMethodInfo getTokenIndex = method as RuntimeMethodInfo;
                Contract.Assert(getTokenIndex != null, "method is not a RuntimeMethodInfo");
                int token = (int)getTokenIndex.UnsafeInvoke(null, BindingFlags.Default, null, null, null);
                return(s_theTokenFactory.BuiltInGetToken(token, null, cls));
            }
            else
#endif // FEATURE_CAS_POLICY
            {
                return(s_theTokenFactory.GetToken(cls, null));
            }
        }
All Usage Examples Of System.Security.PermissionTokenFactory::BuiltInGetToken