⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 应用框架的设计与实现的源代码(SAF) 《应用框架的设计与实现》随书源码
💻 CS
字号:
using System;
using SAF.Authentication;
using System.Threading;
using System.Xml.Serialization;
using System.IO;


namespace TestConsole
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The memo show how to use SAF.Authentication service
		/// to "log on" once and have access to many application without 
		/// relogging again.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			//Note: modify the user login information to match with that of 
			//you computer.

			//create an SAFIdentity type object, modify the parameters to fit your computer's security enviroment
			ADIdentity adIdentity = new ADIdentity("myuser","mypassword","mylocalcomputer","Application1");
			SAFPrincipal sp = new SAFPrincipal(adIdentity);
			//attach the SAFPrincipal to the thread
			Thread.CurrentPrincipal = sp;
			
			//refer to the configuraiton file for more information how how the 
			//users and applications are mapped 
			//check if the current principal is member of Administrators group 
			bool result1 = sp.IsInRole("Administrators");
			string user1 = sp.Identity.Name;
	
			//switch to another application, then check what the original caller means to them membership-wise.
			sp.SetApplication("Application2");
			bool result2 = sp.IsInRole("Administrators");
			string user2 = sp.Identity.Name;

			//switch to another application, then check what the original caller means to them membership-wise.
			sp.SetApplication("Application1");
			bool result3 = sp.IsInRole("Administrators");
			string user3 = sp.Identity.Name;


	
			Console.ReadLine();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -