コード例 #1
0
ファイル: APTCA3.cs プロジェクト: dbremner/smokey
        // S1006/ImperativeSecurity
        public static void Work()
        {
            NamedPermissionSet permissions = new NamedPermissionSet("Custom");

            permissions.Demand();

            SecureClass.RevertDocument();
        }
コード例 #2
0
        private static Boolean IsRunningUnderFullTrust()
        {
            Boolean isRunningUnderFullTrust = true;

            try
            {
                NamedPermissionSet permissionSet = new NamedPermissionSet("FullTrust");
                permissionSet.Demand();
            }
            catch (SecurityException)
            {
                isRunningUnderFullTrust = false;
            }

            return(isRunningUnderFullTrust);
        }
コード例 #3
0
        public static void Access()
        {
            // This security check fails if the caller
            // does not have full trust.
            NamedPermissionSet pset = new NamedPermissionSet("FullTrust");

            // This try-catch block shows the caller's permissions.
            // Correct code would either not catch the exception,
            // or would rethrow it.
            try
            {
                pset.Demand();
            }
            catch (SecurityException e)
            {
                Console.WriteLine("Demand for full trust:{0}", e.Message);
            }
            // Call the type that requires full trust.
            // Violates rule AptcaMethodsShouldOnlyCallAptcaMethods.
            ClassRequiringFullTrust.DoWork();
        }