/** * Parse the parameters from an OAuth Authorization or WWW-Authenticate * header. The realm is included as a parameter. If the given header doesn't * start with "OAuth ", return an empty list. */ public static List <OAuth.Parameter> decodeAuthorization(String authorization) { List <OAuth.Parameter> into = new List <OAuth.Parameter>(); if (authorization != null) { Match m = AUTHORIZATION.Match(authorization); if (m.Success) { if (m.Groups[1].Value.Equals(AUTH_SCHEME)) { foreach (String nvp in Regex.Split(m.Groups[2].Value, "\\s*,\\s*")) { m = NVP.Match(nvp); if (m.Success) { String name = Rfc3986.Decode(m.Groups[1].Value); String value = Rfc3986.Decode(m.Groups[2].Value); into.Add(new OAuth.Parameter(name, value)); } } } } } return(into); }
public virtual void testDeleteAuthorization() { // create global auth Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL); basePerms.Resource = AUTHORIZATION; basePerms.ResourceId = ANY; basePerms.addPermission(ALL); basePerms.removePermission(DELETE); // revoke delete authorizationService.saveAuthorization(basePerms); // turn on authorization processEngineConfiguration.AuthorizationEnabled = true; identityService.AuthenticatedUserId = jonny2; try { // try to delete authorization authorizationService.deleteAuthorization(basePerms.Id); fail("exception expected"); } catch (AuthorizationException e) { assertEquals(1, e.MissingAuthorizations.Count); MissingAuthorization info = e.MissingAuthorizations[0]; assertEquals(jonny2, e.UserId); assertExceptionInfo(DELETE.Name, AUTHORIZATION.resourceName(), basePerms.Id, info); } }
//构造函数 public T_RpcClient(AUTHORIZATION auth, String var_host, int var_port, int var_timeout) { this._auth = auth; this.m_host = var_host; this.m_port = var_port; this.m_timeout = var_timeout; if (!Init()) { throw new Exception("服务器连接失败!"); } }
public virtual void testCreateAuthorization() { // add base permission which allows nobody to create authorizations Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL); basePerms.Resource = AUTHORIZATION; basePerms.ResourceId = ANY; basePerms.addPermission(ALL); // add all then remove 'create' basePerms.removePermission(CREATE); authorizationService.saveAuthorization(basePerms); // now enable authorizations: processEngineConfiguration.AuthorizationEnabled = true; identityService.AuthenticatedUserId = jonny2; try { // we cannot create another authorization authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL); fail("exception expected"); } catch (AuthorizationException e) { assertEquals(1, e.MissingAuthorizations.Count); MissingAuthorization info = e.MissingAuthorizations[0]; assertEquals(jonny2, e.UserId); assertExceptionInfo(CREATE.Name, AUTHORIZATION.resourceName(), null, info); } // circumvent auth check to get new transient object Authorization authorization = new AuthorizationEntity(AUTH_TYPE_REVOKE); authorization.UserId = "someUserId"; authorization.Resource = Resources.APPLICATION; try { authorizationService.saveAuthorization(authorization); fail("exception expected"); } catch (AuthorizationException e) { assertEquals(1, e.MissingAuthorizations.Count); MissingAuthorization info = e.MissingAuthorizations[0]; assertEquals(jonny2, e.UserId); assertExceptionInfo(CREATE.Name, AUTHORIZATION.resourceName(), null, info); } }
public virtual void testUserUpdateAuthorizations() { // create global auth Authorization basePerms = authorizationService.createNewAuthorization(AUTH_TYPE_GLOBAL); basePerms.Resource = AUTHORIZATION; basePerms.ResourceId = ANY; basePerms.addPermission(ALL); basePerms.removePermission(UPDATE); // revoke update authorizationService.saveAuthorization(basePerms); // turn on authorization processEngineConfiguration.AuthorizationEnabled = true; identityService.AuthenticatedUserId = jonny2; // fetch authhorization basePerms = authorizationService.createAuthorizationQuery().singleResult(); // make some change to the perms basePerms.addPermission(ALL); try { authorizationService.saveAuthorization(basePerms); fail("exception expected"); } catch (AuthorizationException e) { assertEquals(1, e.MissingAuthorizations.Count); MissingAuthorization info = e.MissingAuthorizations[0]; assertEquals(jonny2, e.UserId); assertExceptionInfo(UPDATE.Name, AUTHORIZATION.resourceName(), basePerms.Id, info); } // but we can create a new auth Authorization newAuth = authorizationService.createNewAuthorization(AUTH_TYPE_GRANT); newAuth.UserId = "jonny2"; newAuth.Resource = AUTHORIZATION; newAuth.ResourceId = ANY; newAuth.addPermission(ALL); authorizationService.saveAuthorization(newAuth); }
public B_BaseDataSync(AUTHORIZATION auth, String var_host, int var_port, int var_timeout, string dbConstring) { _auth = auth; _dbConnString = dbConstring; _rpcClient = new T_RpcClient(_auth, var_host, var_port, var_timeout); }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { WinSleepCtr.PreventScreenSave(); WinSleepCtr.PreventSleep(true); //*******************端口连接部分 T_ReadConfig.ReadConfig(); //读取配置文件 T_ReadConfig.GetPIN(); //获取PIN码 AUTHORIZATION auth = new AUTHORIZATION(); auth.ClientId = M_Configuration.CLIENTID; //终端号 auth.Token = M_Configuration.TOKEN; //ConfigurationManager.AppSettings["Token"].ToString();//授权码 Client = new T_RpcClient(auth, M_Configuration.HOST, M_Configuration.PORT, M_Configuration.TIMEOUT); //StateClient = new T_RpcClient(auth, M_Configuration.HOST, M_Configuration.PORT, M_Configuration.TIMEOUT); // HeartClient = new T_RpcClient(auth, M_Configuration.HOST, M_Configuration.PORT, M_Configuration.TIMEOUT);//心跳 //票种名称 M_Configuration.RunState = 0;//自助售票运行状态 0表示正常 M_Configuration.TicketID_AName = T_SellTicketRecord.GetTicketTypeName(M_Configuration.TicketTypeID_1); M_Configuration.TicketID_BName = T_SellTicketRecord.GetTicketTypeName(M_Configuration.TicketTypeID_2); #region//暂时不用 ////获取票种信息 //try //{ // M_TicketTypeList.listTicketType = Client.TicketTypeSyncRpc(T_Date.ConvertDataTimeToLong(DateTime.Now)); //} //catch (Exception ex) //{ // _log.Error(typeof(MainWindow), ex); //} ////获取售售期信息 //try //{ // M_PeriodList.listPeriod = Client.SalePeriodSyncRpc(T_Date.ConvertDataTimeToLong(DateTime.Now)); //} //catch (Exception ex) //{ // _log.Error(typeof(MainWindow), ex); //} #endregion ////启动数据同步线程 _DataSyncThread = new Thread(new ThreadStart(_theadDeal.DataSyncThread)); _DataSyncThread.Name = "DataSyncThread"; _DataSyncThread.IsBackground = true; _DataSyncThread.Start(); _DataSyncThread.Priority = ThreadPriority.BelowNormal; Thread.Sleep(10); if (_DataSyncThread.IsAlive) { _log.Info("数据同步工作线程启动成功。"); } ////*******************端口连接部分 //强制回收线程 TGCThread = new T_GCThread(); GCThread = new Thread(new ThreadStart(TGCThread.DoWork)); GCThread.IsBackground = true; GCThread.Start(); if (GCThread.IsAlive) { _log.Error("强制回收线程启动成功!"); } string strSAM = M_Configuration.Samreadername; string strRFID = M_Configuration.RfidReadername; string strPIN = M_Configuration.Pin; try { rfidReaderTest = TicketHandlerAdapter.getRfidTicketHandler(Convert.ToInt32(M_Configuration.CLIENTID), strRFID, strSAM, Encoding.ASCII.GetBytes(strPIN)); } catch { // MessageBox.Show("初始化失败,请确认读卡器选择正确!"); } this.totaltimeout = int.Parse(ConfigHelper.GetConfigValue("window", "totaltimeout"));//操作最长时间 this.InitControlSize(); base.WindowState = WindowState.Maximized; base.WindowStyle = WindowStyle.None; base.ResizeMode = ResizeMode.NoResize; base.Left = 0.0; base.Top = 0.0; this.notice = new NoticePage(ConfigHelper.GetConfigValue("window", "notice"), double.Parse(ConfigHelper.GetConfigValue("window", "noticefontsize"))); this.topFrame.Content = this.notice; //this.videopage = new VideoPage(this); //this.topFrame.Content = this.videopage; this.imagepage = new ImageShowPage(this); this.middleFrame.Content = this.imagepage; pageTest = new FirstPage(this); this.operationpage = pageTest;//new FirstPage(this); this.mainFrame.Content = this.operationpage; //bool flag = SystemInfo.GetAllNetInfo() != null; //if (flag) //{ // this.MacStr = SystemInfo.GetAllNetInfo()[0].PhysAddr; //} this.countdowntimer = new DispatcherTimer(); this.countdowntimer.Interval = new TimeSpan(0, 0, 0, 1, 0); this.countdowntimer.Tick += new EventHandler(this.timer_Tick); this.countdowntimer.Start(); } catch (Exception ex) { _log.Error("服务器连接失败!"); _log.Error(typeof(MainWindow), ex); MessageBox.Show("服务器连接失败!", T_SellTicketRecord.str_Apption, MessageBoxButton.OK, MessageBoxImage.Information); base.Close(); } }
/// <summary> /// 数据同步工作线程方法(基础信息下载) /// </summary> public void DataSyncThread() { int cnt = 0; SQLiteConnection sqliteConn = new SQLiteConnection(SQLiteHelper.LocalDbConnectionString); B_BaseDataSync dataSync; try { AUTHORIZATION auth = new AUTHORIZATION(); auth.ClientId = M_Configuration.CLIENTID; //终端号 auth.Token = M_Configuration.TOKEN; //授权码 string serverAddr = ConfigurationManager.AppSettings["ServerAddress"]; int serverPort = int.Parse(ConfigurationManager.AppSettings["ServerPort"]); int syncTimeOut = int.Parse(ConfigurationManager.AppSettings["SyncTimeOut"]); dataSync = new B_BaseDataSync( auth, serverAddr, serverPort, syncTimeOut, SQLiteHelper.LocalDbConnectionString ); } catch (Exception ex) { _log.Error("初始化数据同步线程错误!", ex); return; } while (!_bStopDataSync) { try { if (cnt == 0) { // 下载基础数据(票种信息、检票规则、黑名单、员工信息) // 每6分钟同步一次基础信息 dataSync.StartSyncInProcess(); // 修改客户端日期时间 if (!dataSync.SetSystemDT()) { this._log.Info("更新服务器时间失败!"); } } if (cnt % 10 == 0) { // 报告运行状态,每1分钟 //B_SellTicketUpData.ejectTicketStatSync_RPC(SaleClient, M_Configuration.RunState); dataSync.ejectTicketStatSync_RPC(M_Configuration.RunState); // 修改客户端日期时间 if (!dataSync.SetSystemDT()) { this._log.Info("更新服务器时间失败!"); } } cnt = (cnt + 1) % 60; } catch (Exception ex) { this._log.Error("数据同步异常!", ex); } Thread.Sleep(6000); } }
public HttpResponseMessage CreateAcessRight(ObservableCollection <UserAccessModel> _UserAccessModel) { try { bool conn = false; conn = db.Database.Exists(); if (!conn) { ConnectionTools.changeToLocalDB(db); conn = db.Database.Exists(); } if (conn) { AUTHORIZATION Acc = new AUTHORIZATION(); long Eid = Convert.ToInt64(_UserAccessModel.ElementAt(0).User_Id); var Access = (from m in db.AUTHORIZATIONs where m.User_Id == Eid select m).FirstOrDefault(); if (Access == null) { foreach (var item in _UserAccessModel) { Acc.ACTION_CREATE = item.ACTION_CREATE; Acc.ACTION_DELETE = item.ACTION_DELETE; Acc.ACTION_VIEW = item.ACTION_VIEW; Acc.APPROVE = item.APPROVE; Acc.Company_Id = item.Company_Id; Acc.EDIT = item.EDIT; Acc.EXPT_TO_EXCEL = item.EXPT_TO_EXCEL; Acc.IMORT_TO_EXCEL = item.IMORT_TO_EXCEL; Acc.MAILBACK = item.MAILBACK; Acc.MESSAGE = item.MESSAGE; Acc.MODULE_ID = item.MODULE_ID; Acc.NOTIFICATION = item.NOTIFICATION; Acc.ROLE_ID = item.ROLE_ID; Acc.User_Id = item.User_Id; Acc.VERIFICATION = item.VERIFICATION; //Acc.MODIFIED_DATE = _UserAccessModel.; db.AUTHORIZATIONs.Add(Acc); db.SaveChanges(); } } else { foreach (var item in _UserAccessModel) { var AccessModule = (from m in db.AUTHORIZATIONs where m.User_Id == Eid && m.MODULE_ID == item.MODULE_ID select m).FirstOrDefault(); AccessModule.ACTION_CREATE = item.ACTION_CREATE; AccessModule.ACTION_DELETE = item.ACTION_DELETE; AccessModule.ACTION_VIEW = item.ACTION_VIEW; AccessModule.APPROVE = item.APPROVE; AccessModule.Company_Id = item.Company_Id; AccessModule.EDIT = item.EDIT; AccessModule.EXPT_TO_EXCEL = item.EXPT_TO_EXCEL; AccessModule.IMORT_TO_EXCEL = item.IMORT_TO_EXCEL; AccessModule.MAILBACK = item.MAILBACK; AccessModule.MESSAGE = item.MESSAGE; //AccessModule.MODULE_ID = item.MODULE_ID; AccessModule.NOTIFICATION = item.NOTIFICATION; // AccessModule.ROLE_ID = item.ROLE_ID; // AccessModule.User_Id = item.User_Id; AccessModule.VERIFICATION = item.VERIFICATION; //Acc.MODIFIED_DATE = _UserAccessModel.; //db.AUTHORIZATIONs.Add(Acc); db.SaveChanges(); } } return(Request.CreateResponse(HttpStatusCode.OK, "Success")); } else { return(Request.CreateResponse(HttpStatusCode.ExpectationFailed)); } } catch (Exception ex) { throw; } finally { ConnectionTools.ChangeToRemoteDB(db); } }