/* * public bool SetAuthSessionInWeb(string username, string password) { * var bl = BLLFactory.Create<IBaseUserBL>(); * var user = bl.GetUserInWeb(username, password); * if (null == user) { * return false; * } * ConfigAuthSession(user); * return true; * } * * * public bool SetAuthSessionInWap(string username, string password) { * var bl = BLLFactory.Create<IBaseUserBL>(); * var user = bl.GetUserInWap(username, password); * if (null == user) { * return false; * } * ConfigAuthSession(user); * return true; * }*/ public bool SetAuthSession(string username, string password, WeatherClientType clientType, string[] loginOnlyIfRole = null, string[] extrRoles = null) { var bl = BLLFactory.Create <IBaseUserBL>(); var user = bl.GetUserInWeb(username, password); if (null == user) { return(false); } ConfigAuthSession(user, clientType); var session = SessionFactory.Create <IBLSessionPersisiter>(); if (loginOnlyIfRole != null) { var identity = new WeatherIdentity(session.UserID); if (loginOnlyIfRole.All(role => !this.UserInRole(identity, role))) { RemoveSession(); return(false); } } //string type = UserLog.LoginClientTypeWap; //switch (clientType) { // case WeatherClientType.Wap: // type = UserLog.LoginClientTypeWap; // break; // case WeatherClientType.Web: // type = UserLog.LoginClientTypeWeb; // break; // case WeatherClientType.iPhone: // type = UserLog.LoginClientTypeiPhone; // break; // case WeatherClientType.Android: // type = UserLog.LoginClientTypeAndroid; // break; //} if (extrRoles != null) { session.Roles.AddAll(extrRoles); } //Bus.ServiceBus.Publish(new Bus.Messages.LoginMsg() { // EmpID = (int)session.BaseEmployee.ID, // Time = Util.RPCNow, // ClientType = type, //}); return(true); }
public bool UserInRole(WeatherIdentity identity, string role) { if (null == role) { return(false); } if (null == identity.Roles) { return(false); } // built-in Role: UserType // one passport if (role == WeatherLib.Security.WeatherRole.BetaUser) { return(true); } var session = SessionFactory.Create <IBLSessionPersisiter>(); // built-in: BindStore: storeID //if(role.StartsWith(WeatherRole.BindStorePrefix)) { // if(role == WeatherRole.BindAnyStore) { // return BLLFactory.Create<IBizStoreBL>().GetBindStores(session.BaseEmployee.ID).Any() ; // } else { // var storeID = decimal.Parse(role.Substring(WeatherRole.BindStorePrefix.Length)); // return BLLFactory.Create<IBizStoreBL>().IsBindStoreByCached(session.BaseEmployee.ID, storeID); // } //} // built-in: InStore: storeID //if (role.StartsWith(WeatherRole.InStorePrefix)) { // var storeID = decimal.Parse(role.Substring(WeatherRole.InStorePrefix.Length)); // return BLLFactory.Create<IReportVstSummaryBL>().IsInStore(storeID, session.BaseEmployee.ID, Util.RPCNow.ToDateString()); //} //// built-in Role: BetaUser //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.BetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.BetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} //// built-in Role: PGBetaUser //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.PGBetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.PGBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} //// built-in Role: PGMBetaUser //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.PGMBetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.PGMBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} //// built-in Role: KPIBetaUser //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.KPIBetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.KPIBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} //// built-in Role: PGOBetaUser //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.JasonBetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.JasonBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.KPISellInOutBetaUser) //{ // return (null != session.BaseEmployee && WeatherRole.KPISellInOutBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode) ); //} //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.KPIKABetaUser) //{ // return (null != session.BaseEmployee && WeatherRole.KPIKABetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} ////VIP //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.VIPBetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.VIPBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.ReportBetaUser) //{ // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.ReportBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} ////FOC //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.FOCSettingUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.FOCBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} ////CRM Customer //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.CRMCustomerBetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.CRMCustomerEmpCode.Contains(session.BaseEmployee.EmpCode)); //} ////PGM Customer Report Beta User //if (Configuration.Flag_EnableBetaUser && role == WeatherRole.PGMCustomerBetaUser) { // return Configuration.IsDevMode || // (null != session.BaseEmployee && WeatherRole.PGMCustomerBetaUserEmpCode.Contains(session.BaseEmployee.EmpCode)); //} //// built-in: 532数据上报 //if (role.StartsWith(WeatherRole.Role532DSR)) //{ // return BLLFactory.Create<IBiz532EmpStoreBL>().GetStoreByEmpID(session.BaseEmployee.ID) != null; //} //// built-in: 532客户数据上报 //if(role.StartsWith(WeatherRole.RoleCityManagment)) { // return BLLFactory.Create<IBiz532EmpAccountBL>().GetEmpAccountByEmp(session.BaseEmployee.ID).Count != 0; //} //// built-in: TBBS客户数据上报 //if (role.StartsWith(WeatherRole.RoleTBBSAccount)) //{ // return BLLFactory.Create<IBizTBBSEmpAccountBL>().GetEmpAccountByEmp(session.BaseEmployee.ID).Count != 0; //} return(identity.Roles.Contains(role)); }
//public TSICPrincipal(TSICIdentity identity) { // this.identity = identity; //} public WeatherPrincipal(WeatherIdentity identity, WeatherAuthorizationService AuthorizationService) { // TODO: Complete member initialization this.identity = identity; this.AuthorizationService = AuthorizationService; }