public virtual void Setup() { var sp = new FileIOPermission(PermissionState.Unrestricted); sp.Assert(); string prefix; if (Environment.CurrentDirectory.EndsWith("target")) { prefix = "../../"; } else { prefix = "../../../"; } sp.Deny(); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); BridgeSetup setup=new BridgeSetup (false){Verbose = true, Debug = true}; setup.IgnoreJavaHome = true; setup.AddJVMOption("-Xmx512m"); setup.AddClassPath(prefix + "jni4net.j/target/classes"); setup.AddClassPath(prefix + "jni4net.tested.j/target/classes"); setup.AddClassPath(prefix + "jni4net.test.j/target/test-classes"); //setup.JavaHome = @"c:\Program Files (x86)\Java\ibm_sdk60"; env = Bridge.CreateJVM(setup); Bridge.RegisterAssembly(typeof(TestBase).Assembly); Bridge.RegisterAssembly(typeof(JavaInstanceFields).Assembly); }
static void Main(string[] args) { CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.AllAccess,@"c:\"); permission.Deny(); UntrustworthyClass.Method(); CodeAccessPermission.RevertDeny(); }
static void Main(string[] args) { CodeAccessPermission permission = new FileIOPermission(FileIOPermissionAccess.Append,@"c:\audit.txt"); permission.Deny(); AuditClass.Save("some data to audit"); CodeAccessPermission.RevertDeny(); }
private object RunInternal(MethodOverloads methodOverloads, object[] rawParams) { // TODO: Security FileIOPermission phoenixLauncherFile = new FileIOPermission(FileIOPermissionAccess.AllAccess, System.IO.Path.Combine(Core.Directory, "PhoenixLauncher.xml")); phoenixLauncherFile.Deny(); // First create ParameterData array ParameterData[] parameters = new ParameterData[rawParams.Length]; for (int i = 0; i < rawParams.Length; i++) { parameters[i] = new ParameterData(rawParams[i]); } // Get valid overloads (array is never empty) Method[] methods = methodOverloads.FindOverloads(parameters); Exception exception = null; foreach (Method m in methods) { ExecutionInfo info = new ExecutionInfo(m); ExecutionAttribute[] execAttributes = (ExecutionAttribute[])m.MethodInfo.GetCustomAttributes(typeof(ExecutionAttribute), false); try { // Call all Execution attributes for (int i = 0; i < execAttributes.Length; i++) { execAttributes[i].Starting(m); } // Add execution to running list lock (syncRoot) { if (runningExecutions.Count >= Executions.MaxExecutions) { throw new RuntimeException("Executions limit exceeded."); } RuntimeCore.AddAssemblyObject(info, this); runningExecutions.Add(info); try { // Raise Started event executionStarted.Invoke(this, new ExecutionsChangedEventArgs(info)); } catch (Exception e) { Core.ShowMessageBoxAsync("Unhandled exception in Executions.ExecutionStarted event handler.\r\nMessage: " + e.Message, "Warning"); } } // Init thread-dependent classes if (!threadInitialized) { ScriptErrorException.ThreadInit(); WorldData.World.ThreadInit(); Journal.ThreadInit(); threadInitialized = true; } // Invoke try { return m.Invoke(parameters); } catch (System.Reflection.TargetInvocationException e) { // Im interested only in exception thrown by code throw e.InnerException; } } catch (ParameterException e) { exception = e; } catch (ExecutionBlockedException e) { exception = e; } finally { // Remove execution from running list lock (syncRoot) { runningExecutions.Remove(info); RuntimeCore.RemoveAssemblyObject(info); try { // Raise Finished event executionFinished.Invoke(this, new ExecutionsChangedEventArgs(info)); } catch (Exception e) { Core.ShowMessageBoxAsync("Unhandled exception in Executions.ExecutionFinished event handler.\r\nMessage: " + e.Message, "Warning"); } } // Call all Execution attributes for (int i = 0; i < execAttributes.Length; i++) { execAttributes[i].Finished(m); } } } if (exception != null) { throw exception; } else { throw new InternalErrorException(); } }
public void FileIOPermission() { FileIOPermission f = new FileIOPermission(PermissionState.Unrestricted); f.Deny(); try { IStateName2 proxy = (IStateName2)XmlRpcProxyGen.Create(typeof(IStateName2)); } finally { CodeAccessPermission.RevertDeny(); } }
public static void Log3(string text) { CodeAccessPermission p = new FileIOPermission(PermissionState.Unrestricted); p.Deny(); }