// S1006/ImperativeSecurity public static void Work() { NamedPermissionSet permissions = new NamedPermissionSet("Custom"); permissions.Demand(); SecureClass.RevertDocument(); }
private static Boolean IsRunningUnderFullTrust() { Boolean isRunningUnderFullTrust = true; try { NamedPermissionSet permissionSet = new NamedPermissionSet("FullTrust"); permissionSet.Demand(); } catch (SecurityException) { isRunningUnderFullTrust = false; } return(isRunningUnderFullTrust); }
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(); }