private void btn_save_Click(object sender, EventArgs e) { btn_run.Enabled = false; btn_save.Enabled = false; if (newTable != null && newTable.Rows.Count > 0) { StringBuilder sql = new StringBuilder(); foreach (DataRow row in newTable.Rows) { Users user = new Users(); user.UserName = row["Username"].ToString(); user.Salt = Guid.NewGuid().ToString().Split('-')[0]; user.Password = EncryTool.StrongEncrypt(user.Salt, row["password"].ToString()); user.IsValid = true; sql.AppendFormat("INSERT INTO dbo.Users (UserName, Password, Salt, IsValid,Company) VALUES ('{0}', '{1}', '{2}', 1, {3});", user.UserName, user.Password, user.Salt, companyId); if (sql.Length > 5000) { SsoHelper.ExecuteCommand(sql.ToString(), CommandType.Text, null); sql = new StringBuilder(); } } SsoHelper.ExecuteCommand(sql.ToString(), CommandType.Text, null); MessageBox.Show("保存完成"); } else { MessageBox.Show("没有数据"); } btn_run.Enabled = true; btn_save.Enabled = true; }
public override void Run() { System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; Console.WriteLine("\n\n#### Example: Login to vCenter server with " + "external Platform Services Controller"); VapiAuthenticationHelper vapiAuthHelper = new VapiAuthenticationHelper(); SetupSslTrustForServer(); Console.WriteLine("\nStep 1: Connect to the lookup service on the " + "Platform Services Controller node."); LookupServiceHelper lookupServiceHelper = new LookupServiceHelper( LookupServiceUrl); Console.WriteLine("\nStep 2: Discover the Single Sign-On service " + "URL from lookup service."); String ssoUrl = lookupServiceHelper.FindSsoUrl(); Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and" + " retrieve the SAML bearer token."); SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl, UserName, Password); Console.WriteLine("\nStep 4. Login to vAPI services using the " + "SAML bearer token."); StubConfiguration sessionStubConfig = vapiAuthHelper.LoginBySamlBearerToken(Server, samlBearerToken); Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI " + "services."); Console.WriteLine("\nListing all tags on the vCenter Server ..."); Tag taggingService = vapiAuthHelper.StubFactory.CreateStub <Tag>(sessionStubConfig); List <string> tagList = taggingService.List(); if (!tagList.Any()) { Console.WriteLine("\nNo tags found !"); } else { Console.WriteLine("\nTag Name\tTag Description"); foreach (string tagId in tagList) { Console.WriteLine( taggingService.Get(tagId).GetName() + "\t" + taggingService.Get(tagId).GetDescription()); } } vapiAuthHelper.Logout(); }
public override void Run() { System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; Console.WriteLine("\n\n#### Example: Login to vCenter server with " + "embedded Platform Services Controller"); VapiAuthenticationHelper vapiAuthHelper = new VapiAuthenticationHelper(); /* * Since the platform services controller is embedded, the sso * server is the same as the vcenter server. */ String ssoUrl = "https://" + Server + SSO_PATH; SetupSslTrustForServer(); Console.WriteLine("\nStep 1: Connect to the Single Sign-On URL " + "and retrieve the SAML bearer token."); SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl, UserName, Password); Console.WriteLine("\nStep 2. Login to vAPI services using the " + "SAML bearer token."); StubConfiguration sessionStubConfig = vapiAuthHelper.LoginBySamlBearerToken(Server, samlBearerToken); Console.WriteLine("\nStep 3: Perform certain tasks using the vAPI " + "services."); Console.WriteLine("\nListing all tags on the vCenter Server ..."); Tag taggingService = vapiAuthHelper.StubFactory.CreateStub <Tag>(sessionStubConfig); List <string> tagList = taggingService.List(); if (!tagList.Any()) { Console.WriteLine("\nNo tags found !"); } else { Console.WriteLine("\nTag Name\tTag Description"); foreach (string tagId in tagList) { Console.WriteLine( taggingService.Get(tagId).GetName() + "\t" + taggingService.Get(tagId).GetDescription()); } } vapiAuthHelper.Logout(); }
public object validatetoken(string token) { if (string.IsNullOrEmpty(token) == false) { AuthResult ar = SsoHelper.ValidateToken(token); if (string.IsNullOrEmpty(ar.ErrorMsg)) { return new { flag = true, username = ar.User.UserName, token = ar.token } } ; return(new { flag = false, username = "" }); } return(new { flag = false, username = "" }); }
public override void OnActionExecuting(HttpActionContext actionContext) { var stopWatch = new Stopwatch(); actionContext.Request.Properties[Key] = stopWatch; stopWatch.Start(); WebApiGlobal.ShowMsg("开始执行:" + actionContext.Request.RequestUri.LocalPath); if (actionContext.Request.RequestUri.AbsolutePath.ToLower().IndexOf("/Login/submit".ToLower()) == -1 && WebApiGlobal.IsToken == true) { try { string token = null; string[] qs = actionContext.Request.RequestUri.Query.ToLower().Split(new char[] { '?', '&' }); foreach (var s in qs) { string[] kv = s.Split(new char[] { '=' }); if (kv.Length == 2 && kv[0] == "token") { token = kv[1]; break; } } if ((token != null)) { AuthResult result = SsoHelper.ValidateToken(token); if (!string.IsNullOrEmpty(result.ErrorMsg)) { throw new Exception(result.ErrorMsg); } actionContext.Request.Properties[tokenKey] = result.User; } else { throw new Exception("token is empty"); } } catch (Exception e) { WebApiGlobal.ShowMsg("执行失败:token failed to " + actionContext.Request.RequestUri.LocalPath); throw new Exception("token failed !" + e.Message); } } base.OnActionExecuting(actionContext); }
public ActionResult Login(string returnUrl) { ViewBag.ReturnUrl = returnUrl; SsoClient ssoClient = new SsoClient(); if (!ssoClient.IsLogined) { return(Redirect(SsoHelper.SSOLoginUrl)); } if (SsoHelper.HasReturnUrl()) { return(Redirect(SsoHelper.ReturnUrl)); } return(View()); }
public override void Run() { System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; Console.WriteLine("\n\n#### Example: Login to vCenter server with " + "external Platform Services Controller"); VapiAuthenticationHelper vapiAuthHelper = new VapiAuthenticationHelper(); SetupSslTrustForServer(); Console.WriteLine("\nStep 1: Connect to the lookup service on the " + "Platform Services Controller node."); LookupServiceHelper lookupServiceHelper = new LookupServiceHelper( LookupServiceUrl); Console.WriteLine("\nStep 2: Discover the Single Sign-On service " + "URL from lookup service."); String ssoUrl = lookupServiceHelper.FindSsoUrl(); Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and" + " retrieve the SAML bearer token."); SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl, UserName, Password); Console.WriteLine("\nStep 4. Login to vAPI services using the " + "SAML bearer token."); StubConfiguration sessionStubConfig = vapiAuthHelper.LoginBySamlBearerToken(Server, samlBearerToken); Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI " + "services."); Datacenter datacenterService = vapiAuthHelper.StubFactory.CreateStub <Datacenter>( sessionStubConfig); List <DatacenterTypes.Summary> dcList = datacenterService.List(new DatacenterTypes.FilterSpec()); Console.WriteLine("\nList of datacenters on the vcenter server:"); foreach (DatacenterTypes.Summary dcSummary in dcList) { Console.WriteLine(dcSummary); } vapiAuthHelper.Logout(); }
public override void OnActionExecuting(HttpActionContext actionContext) { if (WebApiFrame.WebApiGlobal.IsToken == true) { //登陆之外的请求验证token if (actionContext.Request.RequestUri.AbsolutePath.ToLower().IndexOf("/efwplusApi/coresys/login/userlogin".ToLower()) == -1) { string token = null; string[] qs = actionContext.Request.RequestUri.Query.ToLower().Split(new char[] { '?', '&' }); foreach (var s in qs) { string[] kv = s.Split(new char[] { '=' }); if (kv.Length == 2 && kv[0] == "token") { token = kv[1]; break; } } if (token == null) { throw new Exception("no token"); } AuthResult result = SsoHelper.ValidateToken(token); if (result.ErrorMsg != null) { throw new Exception(result.ErrorMsg); } SysLoginRight loginInfo = new SysLoginRight(); loginInfo.EmpId = result.User.EmpId; //loginInfo.UserId =; loginInfo.EmpName = result.User.UserName; loginInfo.DeptId = result.User.DeptId; loginInfo.DeptName = result.User.DeptName; loginInfo.WorkId = result.User.WorkId; loginInfo.WorkName = result.User.WorkName; loginInfo.IsAdmin = result.User.IsAdmin; loginInfo.token = Guid.Parse(result.token); actionContext.Request.Properties[Key] = loginInfo; } } }
public override void Run() { System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; Console.WriteLine("\n\n#### Example: Login to vCenter server with " + "embedded Platform Services Controller"); VapiAuthenticationHelper vapiAuthHelper = new VapiAuthenticationHelper(); /* * Since the platform services controller is embedded, the sso * server is the same as the vcenter server. */ String ssoUrl = "https://" + Server + SSO_PATH; SetupSslTrustForServer(); Console.WriteLine("\nStep 1: Connect to the Single Sign-On URL " + "and retrieve the SAML bearer token."); SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl, UserName, Password); Console.WriteLine("\nStep 2. Login to vAPI services using the " + "SAML bearer token."); StubConfiguration sessionStubConfig = vapiAuthHelper.LoginBySamlBearerToken(Server, samlBearerToken); Console.WriteLine("\nStep 3: Perform certain tasks using the vAPI " + "services."); Datacenter datacenterService = vapiAuthHelper.StubFactory.CreateStub <Datacenter>( sessionStubConfig); List <DatacenterTypes.Summary> dcList = datacenterService.List(new DatacenterTypes.FilterSpec()); Console.WriteLine("\nList of datacenters on the vcenter server:"); foreach (DatacenterTypes.Summary dcSummary in dcList) { Console.WriteLine(dcSummary); } vapiAuthHelper.Logout(); }
public static void Main() { Func <string, Dictionary <string, string>, string> _funcExecCmd = ExecuteCmd; Action <string> _actionReceiveData = ShowMsg; normalIPC = new NormalIPCManager(IPCType.efwplusWebAPI, _funcExecCmd, _actionReceiveData); IsToken = ConfigurationSettings.AppSettings["istoken"] == "true" ? true : false; FileStore = ConfigurationSettings.AppSettings["FileStore"]; string url = ConfigurationSettings.AppSettings["WebApiUri"]; webapiHost = new WebApiSelfHosting(url); webapiHost.StartHost(); SsoHelper.Start(); ShowMsg("WebAPI服务已启动"); }
public LoginResponse UserLogin([FromBody] LoginRequest loginreq) { LoginResponse loginres = new LoginResponse(); try { Action <ClientRequestData> requestAction = ((ClientRequestData request) => { request.Iscompressjson = false; request.Isencryptionjson = false; request.Serializetype = SerializeType.Newtonsoft; request.AddData(loginreq.usercode); request.AddData(loginreq.password); }); ServiceResponseData response = InvokeWcfService(loginreq.wcfpluginname, loginreq.wcfcontroller, loginreq.wcfmethod, requestAction); loginres.otherdata = JsonConvert.DeserializeObject(response.GetJsonData()); AuthResult authres = SsoHelper.ValidateUserId(loginreq.usercode); if (authres.ErrorMsg == string.Empty) { loginres.flag = true; loginres.msg = string.Empty; loginres.token = authres.token; loginres.usercode = authres.User.UserId; loginres.username = authres.User.UserName; loginres.deptname = authres.User.DeptName; loginres.workname = authres.User.WorkName; } else { throw new Exception(authres.ErrorMsg); } } catch (Exception e) { loginres.flag = false; loginres.msg = "登录失败:" + e.Message; } return(loginres); }
//向根节点发送数据请求 public static string RootMNodeProcessRequest(string key, string jsonpara) { if (WcfGlobal.IsRootMNode) { switch (key)//扩展更多 { case "sso_signin": case "sso_signout": case "sso_useractivity": return(SsoHelper.ForwardData(key, jsonpara)); case "adapter_getscript": return(Utility.AdapterScriptHelper.ForwardData(key, jsonpara)); } return(null); } else { return(SuperClient.superClientLink.RootRequest(key, jsonpara)); } }
public object submit([FromBody] simpleUser siuser) { DBInit();//数据库初始化 string token; MongoHelper <User> helperUser = new MongoHelper <User>("MonitorPlatform"); User user = helperUser.FindAll(x => x.usercode == siuser.usercode).First(); if (user != null) { //验证密码 if (user.pwd == DESEncryptor.DesEncrypt(siuser.password)) { SsoHelper.SignIn(new UserInfo { UserCode = siuser.usercode, UserName = user.username, CreateDate = DateTime.Now }, out token); return(new { flag = true, username = user.username, token = token }); } } return(new { flag = false, username = "", token = "" }); }
public override void OnActionExecuting(HttpActionContext actionContext) { if (EFWCoreLib.WcfFrame.ServerController.WcfServerManage.IsDebug == false) { //登陆之外的请求验证token if (actionContext.Request.RequestUri.AbsolutePath.ToLower().IndexOf("/efwplusApi/coresys/login/userlogin".ToLower()) == -1) { string token = null; string[] qs = actionContext.Request.RequestUri.Query.ToLower().Split(new char[] { '?', '&' }); foreach (var s in qs) { string[] kv = s.Split(new char[] { '=' }); if (kv.Length == 2 && kv[0] == "token") { token = kv[1]; break; } } if (token == null) { throw new Exception("no token"); } AuthResult result = SsoHelper.ValidateToken(token); if (result.ErrorMsg != null) { throw new Exception(result.ErrorMsg); } SysLoginRight loginInfo = new SysLoginRight(); loginInfo.UserId = Convert.ToInt32(result.User.UserId); loginInfo.EmpName = result.User.UserName; actionContext.Request.Properties[Key] = loginInfo; } } }
//每次请求的身份验证,分布式情况下验证麻烦 private static bool IsAuth(string pname, string cname, string methodname, string token) { ModulePlugin mp; WcfControllerAttributeInfo cattr = AppPluginManage.GetPluginWcfControllerAttributeInfo(pname, cname, out mp); if (cattr == null) { throw new Exception("插件中没有此控制器名"); } WcfMethodAttributeInfo mattr = cattr.MethodList.Find(x => x.methodName == methodname); if (mattr == null) { throw new Exception("控制器中没有此方法名"); } if (mattr.IsAuthentication) { if (token == null) { throw new Exception("no token"); } AuthResult result = SsoHelper.ValidateToken(token); if (result.ErrorMsg != null) { throw new Exception(result.ErrorMsg); } SysLoginRight loginInfo = new SysLoginRight(); loginInfo.UserId = Convert.ToInt32(result.User.UserId); loginInfo.EmpName = result.User.UserName; //clientinfo.LoginRight = loginInfo; } return(true); }
public ServiceResponseData UserLogin() { string usercode = requestData.GetData <string>(0); string password = requestData.GetData <string>(1); User user = NewObject <User>(); bool islogin = user.UserLogin(usercode, password); if (islogin) { BaseUser EbaseUser = user.GetUser(usercode); SysLoginRight right = new SysLoginRight(); right.UserId = EbaseUser.UserId; right.EmpId = EbaseUser.EmpId; right.WorkId = EbaseUser.WorkId; Dept dept = NewObject <Dept>(); BaseDept EbaseDept = dept.GetDefaultDept(EbaseUser.EmpId); if (EbaseDept != null) { right.DeptId = EbaseDept.DeptId; right.DeptName = EbaseDept.Name; } BaseEmployee EbaseEmp = (BaseEmployee)NewObject <BaseEmployee>().getmodel(EbaseUser.EmpId); right.EmpName = EbaseEmp.Name; BaseWorkers EbaseWork = (BaseWorkers)NewObject <BaseWorkers>().getmodel(EbaseUser.WorkId); right.WorkName = EbaseWork.WorkName; if (EbaseWork.DelFlag == 0) { string regkey = EbaseWork.RegKey; DESEncryptor des = new DESEncryptor(); des.InputString = regkey; des.DesDecrypt(); string[] ret = (des.OutString == null ? "" : des.OutString).Split(new char[] { '|' }); if (ret.Length == 2 && ret[0] == EbaseWork.WorkName && Convert.ToDateTime(ret[1]) > DateTime.Now) { //ClientInfo.LoginRight = right;//缓存登录用户信息 //单点登录注册 Guid token = Guid.Empty; SsoHelper.SignIn(usercode, new UserInfo() { UserId = usercode, UserName = right.EmpName, DeptName = right.DeptName, WorkName = right.WorkName }, out token); responseData.AddData(right.EmpName); responseData.AddData(right.DeptName); responseData.AddData(right.WorkName); responseData.AddData(NewObject <Module>().GetModuleList(right.UserId).OrderBy(x => x.SortId).ToList()); responseData.AddData(NewObject <Menu>().GetMenuList(right.UserId)); responseData.AddData(NewObject <Dept>().GetHaveDept(right.EmpId)); responseData.AddData(right); return(responseData); } else { throw new Exception("登录用户的当前机构注册码不正确!"); } } else { throw new Exception("登录用户的当前机构还未启用!"); } } else { throw new Exception("输入的用户名密码不正确!"); } }