ToString() public method

public ToString ( ) : string
return string
Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("\nWindows Identity");
            WindowsIdentity identity = WindowsIdentity.GetCurrent();
            Console.WriteLine("Authentication Type: " + identity.AuthenticationType);
            Console.WriteLine("Name: " + identity.Name);
            Console.WriteLine("Is System: " + identity.IsSystem);
            Console.WriteLine("Is Authenticated: " + identity.IsAuthenticated);
            Console.WriteLine("Owner Value: " + identity.Owner.Value);
            Console.WriteLine("User Value: " + identity.User.Value);
            Console.WriteLine("Token: " + identity.Token.ToString());
            Console.WriteLine("Groups:");
            IdentityReferenceCollection groups = identity.Groups;
            foreach (IdentityReference ir in groups)
            {
                Console.WriteLine(" - Value: " + ir.Value);
            }

            
            Console.WriteLine("\nWindows Principal");
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
            Console.WriteLine("Identity Name: " + principal.Identity.Name);

            Console.WriteLine("\nUser Roles: ");
            Console.WriteLine("Administrator: " + principal.IsInRole(WindowsBuiltInRole.Administrator));
            Console.WriteLine("Power User: "******"User: "******"ToString: " + pp.ToString());
                pp.Demand();
                Console.WriteLine("Success!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            try
            {
                SuperDuperMethod();
            }
            catch (Exception e)
            {
                Console.WriteLine("Super Duper method threw a far out exception: " + e.ToString());
            }
        }
		public void IntersectNullRole ()
		{
			PrincipalPermission p1 = new PrincipalPermission ("user", "role");
			PrincipalPermission p2 = new PrincipalPermission ("user", null);
			PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (p2);
			AssertEquals ("p1 N p2 == p1", p1.ToString (), p3.ToString ());
			p3 = (PrincipalPermission) p2.Intersect (p1);
			AssertEquals ("p2 N p1 == p1", p1.ToString (), p3.ToString ());
		}
		public void FromXml () 
		{
			PrincipalPermission p = new PrincipalPermission (PermissionState.None);
			SecurityElement se = p.ToXml ();
			AssertNotNull ("ToXml()", se);

			PrincipalPermission p2 = (PrincipalPermission) p.Copy ();
			p2.FromXml (se);
			AssertEquals ("FromXml-Copy", p.ToString (), p2.ToString ());

			string className = (string) se.Attributes ["class"];
			string version = (string) se.Attributes ["version"];

			SecurityElement se2 = new SecurityElement (se.Tag);
			se2.AddAttribute ("class", className);
			se2.AddAttribute ("version", version);
			p2.FromXml (se2);

			SecurityElement sec = new SecurityElement ("Identity");
			sec.AddAttribute ("Authenticated", "true");
			se2.AddChild (sec);
			p2.FromXml (se2);
			Assert ("FromXml-Unrestricted", p2.IsUnrestricted ());
		}
Esempio n. 4
0
		public void IntersectNullName ()
		{
			PrincipalPermission p1 = new PrincipalPermission ("user", "role");
			PrincipalPermission p2 = new PrincipalPermission (null, "role");
			PrincipalPermission p3 = (PrincipalPermission) p1.Intersect (p2);
			Assert.AreEqual (p1.ToString (), p3.ToString (), "p1 N p2 == p1");
			p3 = (PrincipalPermission) p2.Intersect (p1);
			Assert.AreEqual (p1.ToString (), p3.ToString (), "p2 N p1 == p1");
		}