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


C# PermissionSet.Demand方法代码示例

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


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

示例1: Main

    public static void Main(string[] args)
    {
        try
        {
            // Create a new, empty permission set so we don't mistakenly grant some permission we don't want
            PermissionSet permissionSet = new PermissionSet(PermissionState.None);
            // Set the permissions that you will allow, in this case we only want to allow execution of code
            permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
            // Make sure we have the permissions currently
            permissionSet.Demand();

            // Create the security policy level for this application domain
            PolicyLevel policyLevel = PolicyLevel.CreateAppDomainLevel();
            // Give the policy level's root code group a new policy statement based on the new permission set.
            policyLevel.RootCodeGroup.PolicyStatement = new PolicyStatement(permissionSet);

            CSScript.GlobalSettings.AddSearchDir(Environment.CurrentDirectory);

            File.Copy("Danger.cs", "Danger1.cs", true);
            var script = new AsmHelper(CSScript.Load("Danger.cs"));

            // Update the application domain's policy now
            AppDomain.CurrentDomain.SetAppDomainPolicy(policyLevel);

            var script1 = new AsmHelper(CSScript.Load("Danger1.cs"));

            Console.WriteLine();
            Console.WriteLine("Access local file from host application assembly...");
            using (FileStream f = File.Open("somefile.txt", FileMode.OpenOrCreate)) //OK because executing assembly was loaded before the new policy set
                Console.WriteLine("  Ok");
            Console.WriteLine();

            Console.WriteLine("Access local file from Script assembly (before security policy set)...");
            script.Invoke("*.SayHello"); //OK because executing assembly was loaded before the new policy set
            Console.WriteLine();

            Console.WriteLine("Access local file from Script assembly (after security policy set)...\n");
            script1.Invoke("*.SayHello"); //ERROR because executing assembly was loaded after the new policy set

            Console.WriteLine("The end...");
        }
        catch (Exception e)
        {
            Console.WriteLine();
            Console.WriteLine(e.Message);
            Console.WriteLine();
        }
    }
开发者ID:Diullei,项目名称:Storm,代码行数:48,代码来源:Host.cs

示例2: PermissionSetCallMethods

 public static void PermissionSetCallMethods()
 {
     PermissionSet ps = new PermissionSet(new PermissionState());
     ps.Assert();
     bool containspermissions = ps.ContainsNonCodeAccessPermissions();
     PermissionSet ps2 = ps.Copy();
     ps.CopyTo(new int[1], 0);
     ps.Demand();
     ps.Equals(ps2);
     System.Collections.IEnumerator ie = ps.GetEnumerator();
     int hash = ps.GetHashCode();
     PermissionSet ps3 = ps.Intersect(ps2);
     bool isempty = ps.IsEmpty();
     bool issubsetof = ps.IsSubsetOf(ps2);
     bool isunrestricted = ps.IsUnrestricted();
     string s = ps.ToString();
     PermissionSet ps4 = ps.Union(ps2);
     SecurityElement se = new SecurityElement("");
     ps.FromXml(se);
     se = ps.ToXml();
 }
开发者ID:Corillian,项目名称:corefx,代码行数:21,代码来源:PermissionSetTests.cs

示例3: Build

        public bool Build (X509Certificate2 certificate) {
            lock (m_syncRoot) {
                if (certificate == null || certificate.CertContext.IsInvalid)
                    throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidContextHandle), "certificate");

                // Chain building opens and enumerates the root store to see if the root of the chain is trusted.
                StorePermission sp = new StorePermission(StorePermissionFlags.OpenStore | StorePermissionFlags.EnumerateCertificates);
                sp.Demand();

                X509ChainPolicy chainPolicy = this.ChainPolicy;
                if (chainPolicy.RevocationMode == X509RevocationMode.Online) {
                    if (certificate.Extensions[CAPI.szOID_CRL_DIST_POINTS] != null ||
                        certificate.Extensions[CAPI.szOID_AUTHORITY_INFO_ACCESS] != null) {
                        // If there is a CDP or AIA extension, we demand unrestricted network access and store add permission
                        // since CAPI can download certificates into the CA store from the network.
                        PermissionSet ps = new PermissionSet(PermissionState.None);
                        ps.AddPermission(new WebPermission(PermissionState.Unrestricted));
                        ps.AddPermission(new StorePermission(StorePermissionFlags.AddToStore));
                        ps.Demand();
                    }
                }

                Reset();
                int hr = BuildChain(m_useMachineContext ? new IntPtr(CAPI.HCCE_LOCAL_MACHINE) : new IntPtr(CAPI.HCCE_CURRENT_USER),
                                    certificate.CertContext,
                                    chainPolicy.ExtraStore,
                                    chainPolicy.ApplicationPolicy,
                                    chainPolicy.CertificatePolicy,
                                    chainPolicy.RevocationMode,
                                    chainPolicy.RevocationFlag,
                                    chainPolicy.VerificationTime,
                                    chainPolicy.UrlRetrievalTimeout,
                                    ref m_safeCertChainHandle);

                if (hr != CAPI.S_OK)
                    return false;

                // Init.
                Init();

                // Verify the chain using the specified policy.
                CAPI.CERT_CHAIN_POLICY_PARA PolicyPara = new CAPI.CERT_CHAIN_POLICY_PARA(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_PARA)));
                CAPI.CERT_CHAIN_POLICY_STATUS PolicyStatus = new CAPI.CERT_CHAIN_POLICY_STATUS(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_STATUS)));

                PolicyPara.dwFlags = (uint) chainPolicy.VerificationFlags;

                if (!CAPI.CertVerifyCertificateChainPolicy(new IntPtr(CAPI.CERT_CHAIN_POLICY_BASE),
                                                           m_safeCertChainHandle,
                                                           ref PolicyPara,
                                                           ref PolicyStatus))
                    // The API failed.
                    throw new CryptographicException(Marshal.GetLastWin32Error());

                CAPI.SetLastError(PolicyStatus.dwError);
                return (PolicyStatus.dwError == 0);
            }
        }
开发者ID:stormleoxia,项目名称:referencesource,代码行数:57,代码来源:x509chain.cs

示例4: SendKeyboardInput

    private static void SendKeyboardInput (Key key, bool press) {
        PermissionSet permissions = new PermissionSet (PermissionState.Unrestricted);
        permissions.Demand ();

        NativeMethods.INPUT ki = new NativeMethods.INPUT ();
        ki.type = NativeMethods.InputKeyboard;
        ki.union.keyboardInput.wVk = (short)KeyInterop.VirtualKeyFromKey (key);
        ki.union.keyboardInput.wScan = (short)NativeMethods.MapVirtualKey (ki.union.keyboardInput.wVk, 0);

        int dwFlags = 0;

        if (ki.union.keyboardInput.wScan > 0) {
            dwFlags |= NativeMethods.KeyeventfScancode;
        }

        if (!press) {
            dwFlags |= NativeMethods.KeyeventfKeyup;
        }

        ki.union.keyboardInput.dwFlags = dwFlags;

        if (ExtendedKeys.Contains (key)) {
            ki.union.keyboardInput.dwFlags |= NativeMethods.KeyeventfExtendedkey;
        }

        ki.union.keyboardInput.time = 0;
        ki.union.keyboardInput.dwExtraInfo = new IntPtr (0);

        if (NativeMethods.SendInput (1, ref ki, Marshal.SizeOf (ki)) == 0) {
            throw new Win32Exception (Marshal.GetLastWin32Error ());
        }
    }
开发者ID:pandaeyes,项目名称:EmulatesWin,代码行数:32,代码来源:NativeMethods.cs

示例5: SendMouseInput

    private static void SendMouseInput (int x, int y, int data, NativeMethods.SendMouseInputFlags flags) {
        PermissionSet permissions = new PermissionSet (PermissionState.Unrestricted);
        permissions.Demand ();

        int intflags = (int)flags;

        if ((intflags & (int)NativeMethods.SendMouseInputFlags.Absolute) != 0) {
            // Absolute position requires normalized coordinates.
            NormalizeCoordinates (ref x, ref y);
            intflags |= NativeMethods.MouseeventfVirtualdesk;
        }

        NativeMethods.INPUT mi = new NativeMethods.INPUT ();
        mi.type = NativeMethods.InputMouse;
        mi.union.mouseInput.dx = x;
        mi.union.mouseInput.dy = y;
        mi.union.mouseInput.mouseData = data;
        mi.union.mouseInput.dwFlags = intflags;
        mi.union.mouseInput.time = 0;
        mi.union.mouseInput.dwExtraInfo = new IntPtr (0);

        if (NativeMethods.SendInput (1, ref mi, Marshal.SizeOf (mi)) == 0) {
            throw new Win32Exception (Marshal.GetLastWin32Error ());
        }
    }
开发者ID:pandaeyes,项目名称:EmulatesWin,代码行数:25,代码来源:NativeMethods.cs


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