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


C# GenericPrincipal.IsInRole方法代码示例

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


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

示例1: IsInRole_CaseInsensitive

		public void IsInRole_CaseInsensitive ()
		{
			GenericIdentity gi = new GenericIdentity ("user");
			GenericPrincipal gp = new GenericPrincipal (gi, new string[2] { "mono", "hackers" });
			Assert.IsTrue (gp.IsInRole ("MoNo"), "MoNo");
			Assert.IsTrue (gp.IsInRole ("hAcKeRs"), "hAcKeRs");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:GenericPrincipalTest.cs

示例2: IsInRole

		public void IsInRole () 
		{
			GenericIdentity gi = new GenericIdentity ("user");
			string[] roles = new string [5];
			roles [0] = "role 1";
			GenericPrincipal gp = new GenericPrincipal (gi, roles);
			roles [1] = "role 2";
			Assert.IsTrue (gp.IsInRole ("role 1"), "IsInRole (role added before constructor)");
			Assert.IsFalse (gp.IsInRole ("role 2"), "IsInRole (role added after constructor)");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:10,代码来源:GenericPrincipalTest.cs

示例3: Main

		static void Main(string[] args)
		{
			/*
			IEnumerator enumerator = SecurityManager.PolicyHierarchy();
			IEnumerable enumerable = (IEnumerable)enumerator;
			Console.WriteLine("Didn't crash and burn like I expected.");
			*/

			// Create a generic identity.
			GenericIdentity myIdentity = new GenericIdentity("MyIdentity");

			// Create a generic principal.
			string[] myRoles = { "Manager", "Teller" };
			GenericPrincipal myPrincipal = new GenericPrincipal(myIdentity, myRoles);

			// Attach
			Thread.CurrentPrincipal = myPrincipal;

			// Print values to the console.
			string name = Thread.CurrentPrincipal.Identity.Name;
			bool auth = myPrincipal.Identity.IsAuthenticated;
			bool isInRole = myPrincipal.IsInRole("Manager");

			Console.WriteLine("The name is: " + name);
			Console.WriteLine("IsAuthenticated: " + auth);
			Console.WriteLine("Is this a Manager?: " + isInRole);
		}
开发者ID:oblivious,项目名称:Oblivious,代码行数:27,代码来源:Program.cs

示例4: NullRoles

		public void NullRoles () 
		{
			GenericIdentity gi = new GenericIdentity ("user");
			GenericPrincipal gp = new GenericPrincipal (gi, null);
			Assert.AreEqual ("user", gp.Identity.Name, "Identity");
			Assert.IsFalse (gp.IsInRole ("role 1"), "NoRole.IsInRole(x)");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:GenericPrincipalTest.cs

示例5: NullRoles

		public void NullRoles () 
		{
			GenericIdentity gi = new GenericIdentity ("user");
			GenericPrincipal gp = new GenericPrincipal (gi, null);
			AssertEquals ("Identity", "user", gp.Identity.Name);
			Assert ("NoRole.IsInRole(x)", !gp.IsInRole ("role 1"));
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:GenericPrincipalTest.cs

示例6: SerializationRoundtrip

		public void SerializationRoundtrip ()
		{
			GenericIdentity gi = new GenericIdentity ("mono", "dna");
			GenericPrincipal gp = new GenericPrincipal (gi, new string[2] { "monkey", "hackers" });
			BinaryFormatter bf = new BinaryFormatter ();
			MemoryStream ms = new MemoryStream ();
			bf.Serialize (ms, gp);

			//Console.WriteLine (BitConverter.ToString (ms.ToArray ()));

			ms.Position = 0;
			GenericPrincipal clone = (GenericPrincipal) bf.Deserialize (ms);
			Assert.AreEqual (gp.Identity.Name, clone.Identity.Name, "Name");
			Assert.AreEqual (gp.Identity.AuthenticationType, clone.Identity.AuthenticationType, "AuthenticationType");
			Assert.AreEqual (gp.Identity.IsAuthenticated, clone.Identity.IsAuthenticated, "IsAuthenticated");
			Assert.IsTrue (gp.IsInRole ("monkey"), "IsInRole-monkey");
			Assert.IsTrue (gp.IsInRole ("hackers"), "IsInRole-hackers");
			Assert.IsFalse (gp.IsInRole ("donkey"), "IsInRole-donkey");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:19,代码来源:GenericPrincipalTest.cs

示例7: AuthenticateAsync

 public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
 {
     await Task.Run(() =>
     {
         IPrincipal incomingPrincipal = context.ActionContext.RequestContext.Principal;
         Debug.WriteLine(String.Format("Incoming principal in custom auth filter AuthenticateAsync method is authenticated: {0}", incomingPrincipal.Identity.IsAuthenticated));
         IPrincipal genericPrincipal = new GenericPrincipal(new GenericIdentity("Andras", "CustomIdentification"), new string[] { "Admin", "PowerUser" });
         Debug.WriteLine(String.Format(genericPrincipal.IsInRole("Admin").ToString()));
         context.Principal = genericPrincipal;
     });
 }
开发者ID:alwayswannasmile0903,项目名称:MusicStore,代码行数:11,代码来源:CustomAuthenticationFilterAttribute.cs

示例8: call_protectedByDemandWithNoAuthentication_with_no_roles

 	public string call_protectedByDemandWithNoAuthentication_with_no_roles()
 	{
 		try
 		{    			    			
 			var principal = new GenericPrincipal(new GenericIdentity(""), new string[] {""});
 			Assert.That(principal.Identity.IsAuthenticated.isFalse(), "IsAuthenticated should be false");
 			Assert.That(principal.IsInRole("Admin").isFalse(), "IsInRole(\"Admin\") should be false");
 			
 			System.Threading.Thread.CurrentPrincipal = principal;
 			protectedByDemandWithNoAuthentication();
 							 		
 			return "Note: the Demand for Role=\"Admin\" was not enforced";
 		}
 		catch(Exception ex)
 		{
 			Assert.That(ex is System.Security.SecurityException, "Was expecting a SecurityException object, and had: {0}".format(ex.Message));
 			return "got expected security exception";
 		}    		
 	}
开发者ID:CallMeSteve,项目名称:O2.Platform.Scripts,代码行数:19,代码来源:CheckBehaviourOfSecurityActionDemands.cs

示例9: call_protectedByDemandWithNoAuthentication_with_admin_role

    	public string call_protectedByDemandWithNoAuthentication_with_admin_role()
    	{
    		try
    		{
    			var principal = new GenericPrincipal(new GenericIdentity("a name"), new string[] {"Admin"});    			
    			Assert.That(principal.Identity.IsAuthenticated.isTrue(), "IsAuthenticated should be false");
    			Assert.That(principal.IsInRole("Admin").isTrue(), "IsInRole(\"Admin\") should be true");
    			
    			System.Threading.Thread.CurrentPrincipal = principal;
    			var value = protectedByDemandWithNoAuthentication();
    			
    			return "Note: the fact that IsAuthenticateds is true also makes no difference";
    		}
    		catch(Exception ex)
    		{
    			Assert.Fail("a security excption was not expected");    			
				return "fail";
    		}    		
    	}
开发者ID:CallMeSteve,项目名称:O2.Platform.Scripts,代码行数:19,代码来源:CheckBehaviourOfSecurityActionDemands.cs

示例10: determineRolesButton_Click

        private void determineRolesButton_Click(object sender, System.EventArgs e)
        {
            if (this.identity != null)
            {
                this.Cursor = Cursors.WaitCursor;

                this.rolesResultsTextBox.Text = "";
                this.rolesResultsTextBox.Update();

                string[] roles = Roles.GetRolesForUser(this.identity.Name);
                IPrincipal principal = new GenericPrincipal(this.identity, roles);

                if (principal != null)
                {
                    this.DisplayRolesResults(string.Format(Properties.Resources.CheckingRolesMessage, principal.Identity.Name));

                    this.DisplayRolesResults(string.Format(Properties.Resources.UserRoleMessage, role1, Convert.ToString(principal.IsInRole(role1))));
                    this.DisplayRolesResults(string.Format(Properties.Resources.UserRoleMessage, role2, Convert.ToString(principal.IsInRole(role2))));
                    this.DisplayRolesResults(string.Format(Properties.Resources.UserRoleMessage, role3, Convert.ToString(principal.IsInRole(role3))));
                    this.DisplayRolesResults(string.Format(Properties.Resources.UserRoleMessage, role4, Convert.ToString(principal.IsInRole(role4))));
                }

                this.Cursor = Cursors.Arrow;
            }
            else
            {
                this.DisplayRolesResults(Properties.Resources.NullIdentityMessage);
            }
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:29,代码来源:QuickStartForm.cs


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