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


C# PermissionSet.SetPermission方法代码示例

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


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

示例1: CalculatePolicy

 internal PolicyStatement CalculatePolicy(Url url)
 {
     URLString uRLString = url.GetURLString();
     if (string.Compare(uRLString.Scheme, "file", StringComparison.OrdinalIgnoreCase) != 0)
     {
         return null;
     }
     string directoryName = uRLString.GetDirectoryName();
     PermissionSet permSet = new PermissionSet(PermissionState.None);
     permSet.SetPermission(new FileIOPermission(this.m_access, Path.GetFullPath(directoryName)));
     return new PolicyStatement(permSet, PolicyStatementAttribute.Nothing);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:FileCodeGroup.cs

示例2: ProcessMessage


//.........这里部分代码省略.........
                        // The transport sink will catch this and do something here.
                        throw new RemotingException(
                            CoreChannel.GetResourceString("Remoting_Channels_InvalidRequestFormat"));
                    }
                }
            }
            

            try
            {
                String objectUri = null;

                bool bIsCustomErrorEnabled = true;
                object oIsCustomErrorEnabled = requestHeaders["__CustomErrorsEnabled"];
                if (oIsCustomErrorEnabled != null && oIsCustomErrorEnabled is bool){
                    bIsCustomErrorEnabled = (bool)oIsCustomErrorEnabled;
                }
                CallContext.SetData("__CustomErrorsEnabled", bIsCustomErrorEnabled);
              
                if (wkRequestHeaders != null)
                    objectUri = wkRequestHeaders.RequestUri;
                else
                    objectUri = (String)requestHeaders[CommonTransportKeys.RequestUri];              
            
                if (objectUri != lastUri && RemotingServices.GetServerTypeForUri(objectUri) == null)
                    throw new RemotingException(
                        CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished"));
                else
                    lastUri = objectUri;
            
                PermissionSet currentPermissionSet = null;                  
                if (this.TypeFilterLevel != TypeFilterLevel.Full) {                    
                    currentPermissionSet = new PermissionSet(PermissionState.None);                
                    currentPermissionSet.SetPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));                    
                }
                                    
                try {
                    if (currentPermissionSet != null)
                        currentPermissionSet.PermitOnly();
                        
                    // Deserialize Request - Stream to IMessage
                    requestMsg = CoreChannel.DeserializeBinaryRequestMessage(objectUri, requestStream, _strictBinding, this.TypeFilterLevel);                    
                }
                finally {
                    if (currentPermissionSet != null)
                        CodeAccessPermission.RevertPermitOnly();
                }                                    
                requestStream.Close();

                if(requestMsg == null)
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage"));
                }

                // Transparent proxy IMessages are allowed conditionally by AppSettings
                if (RemotingServices.IsTransparentProxy(requestMsg) && !AppSettings.AllowTransparentProxyMessage)
                {
                    // Null request to prevent calling transparent proxy methods in catch below.
                    // Fwlink is provided to explain why it is not supported.  Inner exceptions propagate back to sender.
                    requestMsg = null;
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage"), 
                                                new NotSupportedException(AppSettings.AllowTransparentProxyMessageFwLink));
                }

                // Dispatch Call
                sinkStack.Push(this, null);
开发者ID:salim18,项目名称:DemoProject2,代码行数:67,代码来源:BinaryFormatterSinks.cs

示例3: SetPermission_Unrestricted

		public void SetPermission_Unrestricted ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.Unrestricted);
			PermissionSet ps = new PermissionSet (PermissionState.Unrestricted);
			Assert.AreEqual (0, ps.Count, "Empty");
			Assert.IsTrue (ps.IsUnrestricted (), "State-Unrestricted");

			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			ZoneIdentityPermission zipr = (ZoneIdentityPermission)ps.SetPermission (zip);
			Assert.AreEqual (1, ps.Count, "ZoneIdentityPermission");
			Assert.AreEqual (SecurityZone.MyComputer, zipr.SecurityZone, "SecurityZone");
#if NET_2_0
			// Adding a non unrestricted identity permission now results in 
			// a permission set loosing it's unrestricted status
			Assert.IsTrue (!ps.IsUnrestricted (), "State-Unrestricted-2");
#else
			Assert.IsTrue (ps.IsUnrestricted (), "State-Unrestricted-2");
#endif
			zip = new ZoneIdentityPermission (SecurityZone.Intranet);
			zipr = (ZoneIdentityPermission)ps.SetPermission (zip);
			Assert.AreEqual (1, ps.Count, "ZoneIdentityPermission-2");
			Assert.AreEqual (SecurityZone.Intranet, zipr.SecurityZone, "SecurityZone-2");

			SecurityPermission result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (2, ps.Count, "SecurityPermission");
			Assert.AreEqual (SecurityPermissionFlag.AllFlags, result.Flags, "Flags");
			Assert.IsTrue (!ps.IsUnrestricted (), "State-None");

			sp = new SecurityPermission (SecurityPermissionFlag.ControlAppDomain);
			result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (2, ps.Count, "SecurityPermission-2");
			Assert.AreEqual (SecurityPermissionFlag.ControlAppDomain, result.Flags, "Flags-2");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:33,代码来源:PermissionSetTest.cs

示例4: SetPermission_None

		public void SetPermission_None ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			Assert.AreEqual (0, ps.Count, "Empty");
			Assert.IsTrue (!ps.IsUnrestricted (), "State-None");

			SecurityPermission sp = new SecurityPermission (PermissionState.Unrestricted);
			SecurityPermission result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (1, ps.Count, "SecurityPermission");
			Assert.AreEqual (SecurityPermissionFlag.AllFlags, result.Flags, "Flags");
			Assert.IsTrue (!ps.IsUnrestricted (), "State-None-2");

			sp = new SecurityPermission (SecurityPermissionFlag.ControlAppDomain);
			result = (SecurityPermission)ps.SetPermission (sp);
			Assert.AreEqual (1, ps.Count, "SecurityPermission-2");
			Assert.AreEqual (SecurityPermissionFlag.ControlAppDomain, result.Flags, "Flags");

			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			ZoneIdentityPermission zipr = (ZoneIdentityPermission) ps.SetPermission (zip);
			Assert.AreEqual (2, ps.Count, "ZoneIdentityPermission");
			Assert.AreEqual (SecurityZone.MyComputer, zipr.SecurityZone, "SecurityZone");

			zip = new ZoneIdentityPermission (SecurityZone.Intranet);
			zipr = (ZoneIdentityPermission)ps.SetPermission (zip);
			Assert.AreEqual (2, ps.Count, "ZoneIdentityPermission");
			Assert.AreEqual (SecurityZone.Intranet, zipr.SecurityZone, "SecurityZone");
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:27,代码来源:PermissionSetTest.cs

示例5: SetPermission_Null

		public void SetPermission_Null ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			Assert.IsNull (ps.SetPermission (null));
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:5,代码来源:PermissionSetTest.cs

示例6: NormalizePermissionSet

        private void NormalizePermissionSet()
        {
            // This function guarantees that all the permissions are placed at
            // the proper index within the token based sets.  This becomes necessary
            // since these indices are dynamically allocated based on usage order.
        
            PermissionSet permSetTemp = new PermissionSet(false);
            
            permSetTemp.m_Unrestricted = this.m_Unrestricted;

            // Move all the normal permissions to the new permission set

            if (this.m_permSet != null)
            {
                for (int i = m_permSet.GetStartingIndex(); i <= this.m_permSet.GetMaxUsedIndex(); ++i)
                {
                    Object obj = this.m_permSet.GetItem(i);
                    IPermission perm = obj as IPermission;
#if FEATURE_CAS_POLICY
                    ISecurityElementFactory elem = obj as ISecurityElementFactory;

                    if (elem != null)
                        perm = CreatePerm( elem );
#endif // FEATURE_CAS_POLICY
                    if (perm != null)
                        permSetTemp.SetPermission( perm );
                }
            }
    
            this.m_permSet = permSetTemp.m_permSet;
        }
开发者ID:l1183479157,项目名称:coreclr,代码行数:31,代码来源:PermissionSet.cs

示例7: DecodeSerializedEvidence

        private void DecodeSerializedEvidence( Evidence evidence,
                                               byte[] serializedEvidence )
        {
            MemoryStream ms = new MemoryStream( serializedEvidence );
            BinaryFormatter formatter = new BinaryFormatter();
                
            Evidence asmEvidence = null;
                
            PermissionSet permSet = new PermissionSet( false );
            permSet.SetPermission( new SecurityPermission( SecurityPermissionFlag.SerializationFormatter ) );
            permSet.PermitOnly();
            permSet.Assert();

            try
            {
                asmEvidence = (Evidence)formatter.Deserialize( ms );
            }
            catch (Exception)
            {
            }
                
            if (asmEvidence != null)
            {
                // Any evidence from the serialized input must:
                // 1. be placed in the assembly list since it is unverifiable.
                // 2. not be a built in class used as evidence (e.g. Zone, Site, URL, etc.)
                    
                IEnumerator enumerator = asmEvidence.GetAssemblyEnumerator();
                    
                while (enumerator.MoveNext())
                {
                    Object obj = enumerator.Current;

                    if (!(obj is Zone || obj is Site || obj is Url || obj is StrongName || obj is PermissionRequestEvidence))
                        evidence.AddAssembly( obj );
                }
            }
        }       
开发者ID:ArildF,项目名称:masters,代码行数:38,代码来源:assembly.cs

示例8: ProcessMessage


//.........这里部分代码省略.........
                    throw new RemotingException(
                        CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished"));

                if (_protocol == Protocol.Http)
                {
                    String userAgent = (String)requestHeaders["User-Agent"];
                    if (userAgent != null)
                    {                       
                        if (userAgent.IndexOf("MS .NET Remoting") == -1)
                        {
                            // user agent string did not contain ".NET Remoting", so it is someone else
                            bClientIsClr = false;
                        }
                    }
                    else
                    {
                        bClientIsClr = false;
                    }
                }

                bool bIsCustomErrorEnabled = true;
                object oIsCustomErrorEnabled = requestHeaders["__CustomErrorsEnabled"];
                if (oIsCustomErrorEnabled != null && oIsCustomErrorEnabled is bool){
                    bIsCustomErrorEnabled = (bool)oIsCustomErrorEnabled;
                }
                CallContext.SetData("__CustomErrorsEnabled", bIsCustomErrorEnabled);
                
                String soapActionToVerify;
                Header[] h = GetChannelHeaders(requestHeaders, out soapActionToVerify);

                PermissionSet currentPermissionSet = null;
                if (this.TypeFilterLevel != TypeFilterLevel.Full) {
                    currentPermissionSet = new PermissionSet(PermissionState.None);                
                    currentPermissionSet.SetPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));                    
                }
                                    
                try {
                    if (currentPermissionSet != null) 
                        currentPermissionSet.PermitOnly();                                                                    

                    // Deserialize Request - Stream to IMessage                                        
                    requestMsg = CoreChannel.DeserializeSoapRequestMessage(requestStream, h, _strictBinding, this.TypeFilterLevel);
                }
                finally {
                    if (currentPermissionSet != null)
                        CodeAccessPermission.RevertPermitOnly();
                }
                
                requestStream.Close();

                if(requestMsg == null)
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage"));
                }

                // verify soap action if necessary
                if ((soapActionToVerify != null) &&
                    (!SoapServices.IsSoapActionValidForMethodBase(
                        soapActionToVerify, ((IMethodMessage)requestMsg).MethodBase)))
                {
                    throw new RemotingException(
                        String.Format(
                            CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Soap_InvalidSoapAction"),
                            soapActionToVerify)
                        );
                }                
开发者ID:JianwenSun,项目名称:cc,代码行数:67,代码来源:SoapFormatterSinks.cs

示例9: NormalizePermissionSet

 private void NormalizePermissionSet()
 {
     PermissionSet set = new PermissionSet(false) {
         m_Unrestricted = this.m_Unrestricted
     };
     if (this.m_permSet != null)
     {
         for (int i = this.m_permSet.GetStartingIndex(); i <= this.m_permSet.GetMaxUsedIndex(); i++)
         {
             object item = this.m_permSet.GetItem(i);
             IPermission perm = item as IPermission;
             ISecurityElementFactory factory = item as ISecurityElementFactory;
             if (factory != null)
             {
                 perm = this.CreatePerm(factory);
             }
             if (perm != null)
             {
                 set.SetPermission(perm);
             }
         }
     }
     this.m_permSet = set.m_permSet;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:24,代码来源:PermissionSet.cs

示例10: NormalizePermissionSet

        private void NormalizePermissionSet()
        {
            // This function guarantees that all the permissions are placed at
            // the proper index within the token based sets.  This becomes necessary
            // since these indices are dynamically allocated based on usage order.
        
            PermissionSet permSetTemp = new PermissionSet(false);
            
            permSetTemp.m_Unrestricted = this.m_Unrestricted;

            // Move all the normal permissions to the new permission set

            if (this.m_normalPermSet != null)
            {
                for (int i = 0; i <= this.m_normalPermSet.GetMaxUsedIndex(); ++i)
                {
                    IPermission perm = (IPermission)this.m_normalPermSet.GetItem(i);
                    if (perm != null)
                    {
                        permSetTemp.SetPermission( perm );
                    }
                }
            }

            // Move all the unrestricted permissions to the new permission set
            
            if (this.m_unrestrictedPermSet != null)
            {
                for (int i = 0; i <= this.m_unrestrictedPermSet.GetMaxUsedIndex(); ++i)
                {
                    IPermission perm = (IPermission)this.m_unrestrictedPermSet.GetItem(i);
                    if (perm != null)
                    {
                        permSetTemp.SetPermission( perm );
                    }
                }
            }
    
            // Copy the new permission sets info back to the original set
            
            this.m_normalPermSet = permSetTemp.m_normalPermSet;
            this.m_unrestrictedPermSet = permSetTemp.m_unrestrictedPermSet;
        }
开发者ID:ArildF,项目名称:masters,代码行数:43,代码来源:permissionset.cs

示例11: ProcessMessage


//.........这里部分代码省略.........
                    uRI = (string) requestHeaders["__RequestUri"];
                }
                if (RemotingServices.GetServerTypeForUri(uRI) == null)
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_ChnlSink_UriNotPublished"));
                }
                if (this._protocol == Protocol.Http)
                {
                    string str6 = (string) requestHeaders["User-Agent"];
                    if (str6 != null)
                    {
                        if (str6.IndexOf("MS .NET Remoting") == -1)
                        {
                            bClientIsClr = false;
                        }
                    }
                    else
                    {
                        bClientIsClr = false;
                    }
                }
                bool data = true;
                object obj2 = requestHeaders["__CustomErrorsEnabled"];
                if ((obj2 != null) && (obj2 is bool))
                {
                    data = (bool) obj2;
                }
                CallContext.SetData("__CustomErrorsEnabled", data);
                Header[] channelHeaders = this.GetChannelHeaders(requestHeaders, out str7);
                PermissionSet set = null;
                if (this.TypeFilterLevel != System.Runtime.Serialization.Formatters.TypeFilterLevel.Full)
                {
                    set = new PermissionSet(PermissionState.None);
                    set.SetPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));
                }
                try
                {
                    if (set != null)
                    {
                        set.PermitOnly();
                    }
                    requestMsg = CoreChannel.DeserializeSoapRequestMessage(requestStream, channelHeaders, this._strictBinding, this.TypeFilterLevel);
                }
                finally
                {
                    if (set != null)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
                requestStream.Close();
                if (requestMsg == null)
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_DeserializeMessage"));
                }
                if ((str7 != null) && !SoapServices.IsSoapActionValidForMethodBase(str7, ((IMethodMessage) requestMsg).MethodBase))
                {
                    throw new RemotingException(string.Format(CultureInfo.CurrentCulture, CoreChannel.GetResourceString("Remoting_Soap_InvalidSoapAction"), new object[] { str7 }));
                }
                sinkStack.Push(this, null);
                complete = this._nextSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
                if (responseStream != null)
                {
                    throw new RemotingException(CoreChannel.GetResourceString("Remoting_ChnlSink_WantNullResponseStream"));
                }
                switch (complete)
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:67,代码来源:SoapServerFormatterSink.cs

示例12: DecodeSerializedEvidence

 private static void DecodeSerializedEvidence(System.Security.Policy.Evidence evidence, byte[] serializedEvidence)
 {
     BinaryFormatter formatter = new BinaryFormatter();
     System.Security.Policy.Evidence evidence2 = null;
     PermissionSet set = new PermissionSet(false);
     set.SetPermission(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));
     set.PermitOnly();
     set.Assert();
     try
     {
         using (MemoryStream stream = new MemoryStream(serializedEvidence))
         {
             evidence2 = (System.Security.Policy.Evidence) formatter.Deserialize(stream);
         }
     }
     catch
     {
     }
     if (evidence2 != null)
     {
         IEnumerator assemblyEnumerator = evidence2.GetAssemblyEnumerator();
         while (assemblyEnumerator.MoveNext())
         {
             object current = assemblyEnumerator.Current;
             evidence.AddAssembly(current);
         }
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:28,代码来源:Assembly.cs

示例13: DecodeSerializedEvidence

        private static void DecodeSerializedEvidence( Evidence evidence,
                                               byte[] serializedEvidence )
        {
            BinaryFormatter formatter = new BinaryFormatter();
                
            Evidence asmEvidence = null;
                
            PermissionSet permSet = new PermissionSet( false );
            permSet.SetPermission( new SecurityPermission( SecurityPermissionFlag.SerializationFormatter ) );
            permSet.PermitOnly();
            permSet.Assert();

            try {
                using(MemoryStream ms = new MemoryStream( serializedEvidence ))
                    asmEvidence = (Evidence)formatter.Deserialize( ms );
            }
            catch
            {
            }
                
            if (asmEvidence != null)
            {
                IEnumerator enumerator = asmEvidence.GetAssemblyEnumerator();
                    
                while (enumerator.MoveNext())
                {
                    Object obj = enumerator.Current;
                    evidence.AddAssembly( obj );
                }
            }
        }       
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:31,代码来源:assembly.cs

示例14: SetPermission_None

		public void SetPermission_None ()
		{
			PermissionSet ps = new PermissionSet (PermissionState.None);
			AssertEquals ("Empty", 0, ps.Count);
			Assert ("State-None", !ps.IsUnrestricted ());

			SecurityPermission sp = new SecurityPermission (PermissionState.Unrestricted);
			SecurityPermission result = (SecurityPermission)ps.SetPermission (sp);
			AssertEquals ("SecurityPermission", 1, ps.Count);
			AssertEquals ("Flags", SecurityPermissionFlag.AllFlags, result.Flags);
			Assert ("State-None-2", !ps.IsUnrestricted ());

			sp = new SecurityPermission (SecurityPermissionFlag.ControlAppDomain);
			result = (SecurityPermission)ps.SetPermission (sp);
			AssertEquals ("SecurityPermission-2", 1, ps.Count);
			AssertEquals ("Flags", SecurityPermissionFlag.ControlAppDomain, result.Flags);

			ZoneIdentityPermission zip = new ZoneIdentityPermission (SecurityZone.MyComputer);
			ZoneIdentityPermission zipr = (ZoneIdentityPermission) ps.SetPermission (zip);
			AssertEquals ("ZoneIdentityPermission", 2, ps.Count);
			AssertEquals ("SecurityZone", SecurityZone.MyComputer, zipr.SecurityZone);

			zip = new ZoneIdentityPermission (SecurityZone.Intranet);
			zipr = (ZoneIdentityPermission)ps.SetPermission (zip);
			AssertEquals ("ZoneIdentityPermission", 2, ps.Count);
			AssertEquals ("SecurityZone", SecurityZone.Intranet, zipr.SecurityZone);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:PermissionSetTest.cs

示例15: CalculatePolicy

        private PolicyStatement CalculatePolicy( Url url )
        {
            URLString urlString = url.GetURLString();

            if (String.Compare( urlString.Scheme, "file", true, CultureInfo.InvariantCulture) != 0)
                return null;

            String directory = urlString.GetDirectoryName();
            
            PermissionSet permSet = new PermissionSet( PermissionState.None );
            permSet.SetPermission( new FileIOPermission( m_access, directory ) );

            return new PolicyStatement( permSet, PolicyStatementAttribute.Nothing );
        }
开发者ID:ArildF,项目名称:masters,代码行数:14,代码来源:filecodegroup.cs


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