protected void Button2_Click(object sender, EventArgs e) { IAzManStorage storage = new SqlAzManStorage("data source=(local);Initial Catalog=NetSqlAzManStorage;user id=sa;password="******"Andrea"); UserPermissionCache cache = new UserPermissionCache(storage, "Store Stress Test", "Application0", andrea, true, true); Session["cache"] = cache; }
private void btnACL_Click(object sender, EventArgs e) { try { //string[] users = DirectoryServicesUtils.GetAllDomainUsers(); //IAzManStorage storage = new SqlAzManStorage("data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security = SSPI;"); //IAzManDBUser dbUser1 = storage.GetDBUser(new SqlAzManSID(this.GetBytesFromInt32(1), true)); //IAzManDBUser dbUser2 = storage.GetDBUser(new SqlAzManSID(this.GetBytesFromInt32(2), true)); //AuthorizationType auth1 = storage.CheckAccess("Eidos", "DB Persone", "Accesso", dbUser1, DateTime.Now, false); //AuthorizationType auth2 = storage.CheckAccess("Eidos", "DB Persone", "Accesso", dbUser1, DateTime.Now, false); //string cs = "data source=(local);Initial Catalog=NetSqlAzManStorage;Integrated Security=SSPI"; string cs = "data source=.;Initial Catalog=NetSqlAzManStorage;Integrated Security=SSPI"; var ctx = new[] { new KeyValuePair<string, object>("Value1", "111"), new KeyValuePair<string, object>("Value2", "222") }; IAzManStorage storage = new SqlAzManStorage(cs); //DateTime dt = new DateTime(2009, 05, 01); //AuthorizationType authz = storage.CheckAccess("Eidos", "DB Persone", "Super utente senza dati retributivi", WindowsIdentity.GetCurrent(), dt, false); //authz = upcTest.CheckAccess("Super utente senza dati retributivi", dt); //MessageBox.Show(authz.ToString()); DateTime t1, t2; ////return; t1 = DateTime.Now; StorageCache sc = new StorageCache(cs); sc.BuildStorageCache(); //t2 = DateTime.Now; ////MessageBox.Show((t2 - t1).TotalMilliseconds.ToString()); //t1 = DateTime.Now; //UserPermissionCache uupc = new UserPermissionCache(storage, "Eidos", "DB Persone", WindowsIdentity.GetCurrent(), true, true); t2 = DateTime.Now; //MessageBox.Show((t2 - t1).TotalMilliseconds.ToString()); //return; //t1 = DateTime.Now; //UserPermissionCache upcTest = new UserPermissionCache(storage, "Eidos", "DB Persone", WindowsIdentity.GetCurrent(), true, true, ctx); //t2 = DateTime.Now; //MessageBox.Show((t2 - t1).TotalMilliseconds.ToString()); //t1 = DateTime.Now; //for (int i = 0; i < 1000; i++) //{ // upcTest.CheckAccess("Accesso", DateTime.Now); //} //t2 = DateTime.Now; //MessageBox.Show((t2 - t1).TotalMilliseconds.ToString()); string ssid = WindowsIdentity.GetCurrent().GetUserBinarySSid(); string[] gsid = WindowsIdentity.GetCurrent().GetGroupsBinarySSid(); //t1 = DateTime.Now; //for (int i = 0; i < 1000; i++) //{ // sc.CheckAccess("Eidos", "DB Persone", "Gestore", ssid, gsid, DateTime.Now, false); //} //t2 = DateTime.Now; //MessageBox.Show((t2 - t1).TotalMilliseconds.ToString()); //sr.CacheServiceClient csc = new NetSqlAzMan_WinTest.sr.CacheServiceClient(); //csc.Open(); //t1 = DateTime.Now; ////for (int i = 0; i < 1000; i++) ////{ ////var aauu = csc.CheckAccessForWindowsUsersWithoutAttributesRetrieve("ZZEntDataSvcs", "CommissionFeeTax", "Editor", ssid, gsid, DateTime.Now, false, null); //var aauu = sc.CheckAccess("Eidos", "DB Persone", "Accesso", ssid, gsid, DateTime.Now, false, null); // //csc.GetAuthorizedItemsForWindowsUsers("Eidos", "DB Persone", ssid, gsid, DateTime.Now, null); ////} //t2 = DateTime.Now; ////MessageBox.Show((t2 - t1).TotalMilliseconds.ToString()); //csc.Close(); //t1 = DateTime.Now; //for (int i = 0; i < 1000; i++) //{ // storage.CheckAccess("Eidos", "DB Persone", "Gestore", WindowsIdentity.GetCurrent(), DateTime.Now, false); //} //t2 = DateTime.Now; //MessageBox.Show((t2 - t1).TotalMilliseconds.ToString()); //return; //DateTime dt = DateTime.Now; //foreach (string user in users) //{ // WindowsIdentity win = new WindowsIdentity(user); // sc.CheckAccess("Eidos", "DB Persone", "Gestore", win.GetUserBinarySSid(), win.GetGroupsBinarySSid(), DateTime.Now, false); //} //TimeSpan ts = DateTime.Now.Subtract(dt); //var seconds = ts.TotalSeconds; // //upcTest.CheckAccess("Accesso", DateTime.Now); List<KeyValuePair<string, string>> attributes1; List<KeyValuePair<string, string>> attributes2; List<KeyValuePair<string, string>> attributes3; //int h; foreach (var store in storage.Stores) { foreach (var application in store.Value.Applications) { UserPermissionCache upc = new UserPermissionCache(storage, store.Value.Name, application.Value.Name, WindowsIdentity.GetCurrent(), true, true, ctx); foreach (var item in application.Value.Items) { this.textBox1.Text += String.Format("Store: {0}\tApplication: {1}\tItem: {2}\r\n", store.Key, application.Key, item.Key); AuthorizationType auth1 = sc.CheckAccess(store.Value.Name, application.Value.Name, item.Value.Name, WindowsIdentity.GetCurrent().GetUserBinarySSid(), WindowsIdentity.GetCurrent().GetGroupsBinarySSid(), DateTime.Now, false, out attributes1, ctx); AuthorizationType auth2 = storage.CheckAccess(store.Value.Name, application.Value.Name, item.Value.Name, WindowsIdentity.GetCurrent(), DateTime.Now, false, out attributes2, ctx); AuthorizationType auth3 = upc.CheckAccess(item.Value.Name, DateTime.Now, out attributes3); //if (item.Key == "Method1") // h = 9; this.detectedDifferences(auth1, attributes1, auth2, attributes2); this.detectedDifferences(auth2, attributes2, auth3, attributes3); this.detectedDifferences(auth1, attributes1, auth3, attributes3); } } } MessageBox.Show("Done"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void rbCheckedChanged() { if (this.rbWindowsUser.Checked) { this.txtWindowsUser.Enabled = true; this.txtDBUser.Enabled = false; } else { this.txtDBUser.Enabled = false; this.txtWindowsUser.Enabled = false; } this.txtWindowsUser.Text = String.Empty; this.txtDBUser.Text = String.Empty; this.cache = null; this.wid = null; this.dbuser = null; }
private void checkAccessTest(TreeNode tn) { string sItemType = String.Empty; if (tn.ImageUrl.EndsWith("Role_16x16.gif")) sItemType = "Role"; else if (tn.ImageUrl.EndsWith("Task_16x16.gif")) sItemType = "Task"; else sItemType = "Operation"; AuthorizationType auth = AuthorizationType.Neutral; string sAuth = String.Empty; DateTime chkStart = DateTime.Now; TimeSpan elapsedTime = TimeSpan.Zero; DateTime chkEnd = DateTime.Now; List<KeyValuePair<string, string>> attributes = null; //Cache Build if (this.chkCache.Checked && this.cache == null) { this.WriteDetailMessage("Building UserPermissionCache ..."); if (this.wid != null) { this.cache = new NetSqlAzMan.Cache.UserPermissionCache(this.application.Store.Storage, this.application.Store.Name, this.application.Name, this.wid, true, false); } else if (this.dbuser != null) { this.cache = new NetSqlAzMan.Cache.UserPermissionCache(this.application.Store.Storage, this.application.Store.Name, this.application.Name, this.dbuser, true, false); } chkEnd = DateTime.Now; elapsedTime = (TimeSpan)chkEnd.Subtract(chkStart); this.WriteLineDetailMessage(String.Format("[{0} mls.]\r\n", elapsedTime.TotalMilliseconds)); } else if (this.chkStorageCache.Checked && this.storageCache == null) { this.WriteDetailMessage("Building StorageCache ..."); this.storageCache = new NetSqlAzMan.Cache.StorageCache(this.application.Store.Storage.ConnectionString); this.storageCache.BuildStorageCache(this.application.Store.Name, this.application.Name); chkEnd = DateTime.Now; elapsedTime = (TimeSpan)chkEnd.Subtract(chkStart); this.WriteLineDetailMessage(String.Format("[{0} mls.]\r\n", elapsedTime.TotalMilliseconds)); } chkStart = DateTime.Now; elapsedTime = TimeSpan.Zero; this.WriteDetailMessage(String.Format("{0} {1} '{2}' ... ", "Check Access Test on", sItemType, tn.Text)); try { if (this.wid != null) { if (this.chkCache.Checked) { auth = this.cache.CheckAccess(tn.Text, !String.IsNullOrEmpty(this.dtValidFor.Text) ? Convert.ToDateTime(this.dtValidFor.Text) : DateTime.Now, out attributes); } else if (this.chkStorageCache.Checked) { auth = this.storageCache.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.wid.GetUserBinarySSid(), this.wid.GetGroupsBinarySSid(), !String.IsNullOrEmpty(this.dtValidFor.Text) ? Convert.ToDateTime(this.dtValidFor.Text) : DateTime.Now, false, out attributes); } else { auth = this.application.Store.Storage.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.wid, !String.IsNullOrEmpty(this.dtValidFor.Text) ? Convert.ToDateTime(this.dtValidFor.Text) : DateTime.Now, false, out attributes); } } else if (this.dbuser != null) { if (this.chkCache.Checked) { auth = this.cache.CheckAccess(tn.Text, !String.IsNullOrEmpty(this.dtValidFor.Text) ? Convert.ToDateTime(this.dtValidFor.Text) : DateTime.Now, out attributes); } else if (this.chkStorageCache.Checked) { auth = this.storageCache.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.dbuser.CustomSid.StringValue, !String.IsNullOrEmpty(this.dtValidFor.Text) ? Convert.ToDateTime(this.dtValidFor.Text) : DateTime.Now, false, out attributes); } else { auth = this.application.Store.Storage.CheckAccess(this.application.Store.Name, this.application.Name, tn.Text, this.dbuser, !String.IsNullOrEmpty(this.dtValidFor.Text) ? Convert.ToDateTime(this.dtValidFor.Text) : DateTime.Now, false, out attributes); } } chkEnd = DateTime.Now; elapsedTime = (TimeSpan)chkEnd.Subtract(chkStart); sAuth = "Neutral"; switch (auth) { case AuthorizationType.AllowWithDelegation: sAuth = "Allow with Delegation"; break; case AuthorizationType.Allow: sAuth = "Allow"; break; case AuthorizationType.Deny: sAuth = "Deny"; break; case AuthorizationType.Neutral: sAuth = "Neutral"; break; } tn.ToolTip = sAuth; this.WriteLineDetailMessage(String.Format("{0} [{1} mls.]", sAuth, elapsedTime.TotalMilliseconds)); if (attributes != null && attributes.Count > 0) { this.WriteLineDetailMessage(String.Format(" {0} attribute(s) found:", attributes.Count)); int attributeIndex = 0; foreach (KeyValuePair<string, string> attr in attributes) { this.WriteLineDetailMessage(String.Format(" {0}) Key: {1} Value: {2}", ++attributeIndex, attr.Key, attr.Value)); } } } catch (Exception ex) { sAuth = "Check Access Test Error"; this.WriteLineDetailMessage(String.Format("{0} [{1} mls.]", ex.Message, elapsedTime.TotalMilliseconds)); } tn.Text = String.Format("{0} - ({1})", tn.Text, sAuth.ToUpper()); foreach (TreeNode tnChild in tn.ChildNodes) { this.checkAccessTest(tnChild); } }
protected void chkStorageCache_CheckedChanged(object sender, EventArgs e) { if (this.chkStorageCache.Checked && this.chkCache.Checked) this.chkCache.Checked = false; this.cache = null; }
public ActionResult Login(LoginModel model, string returnUrl) { // Check if the supplied credentials are correct. ViewBag.HasError = false; ViewBag.returnUrl = returnUrl; // Create logger instance to record activities var log = new Logger(); try { if (_userAccountService.Authenticate(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName,true); // Will be refactored var user = _userAccountService.GetUserDetail(model.UserName); user.LogginDate = DateTime.Now; user.NumberOfLogins += 1; // Session["USER_PROFILE"] = user; _userAccountService.UpdateUser(user); // Add user information to session variable to avoid frequent trip to the databas var service = (IUserAccountService)DependencyResolver.Current.GetService(typeof(IUserAccountService)); var userInfo = service.GetUserInfo(model.UserName); Session["USER_INFO"] = userInfo; Session["USER_PROFILE"] = service.GetUserDetail(model.UserName); // Before trying to go and look for user permissions, check if the user is logged in or not //// Load user permissions IAzManStorage storage = new SqlAzManStorage(ConfigurationManager.ConnectionStrings["CatsContext"].ConnectionString); IAzManDBUser dbUser = storage.GetDBUser(user.UserName); // Early Warning user permissions UserPermissionCache earlyWarningPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.EARLY_WARNING, dbUser, true, false); Session[CatsGlobals.EARLY_WARNING_PERMISSIONS] = earlyWarningPermissionCache; //PSNP user permission UserPermissionCache psnpPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.PSNP, dbUser, true, false); Session[CatsGlobals.PSNP_PERMISSIONS] = psnpPermissionCache; // Logistics user permissions UserPermissionCache logisticsPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.LOGISTICS, dbUser, true, false); Session[CatsGlobals.LOGISTICS_PERMISSIONS] = logisticsPermissionCache; // Procurement user permissions UserPermissionCache procurementPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.PROCUREMENT, dbUser, true, false); Session[CatsGlobals.PROCUREMENT_PERMISSIONS] = procurementPermissionCache; // Hub user permissions UserPermissionCache hubPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.HUB, dbUser, true, false); Session[CatsGlobals.HUB_PERMISSIONS] = hubPermissionCache; // Regional user permissions UserPermissionCache regionalPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.REGION, dbUser, true, false); Session[CatsGlobals.REGION_PERMISSIONS] = regionalPermissionCache; // Regional user permissions UserPermissionCache financePermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.FINANCE, dbUser, true, false); Session[CatsGlobals.FINANCE_PERMISSIONS] = financePermissionCache; // Whatever permission we are going to have! _log.Info("Logged in User: "******"Administrator", "Manage User Account"); //service.GetUserPermissions(model.UserName, "CATS", "Finance"); return RedirectToLocal(returnUrl); } } catch (UserNotFoundException unfe) { log.LogAllErrorsMesseges(unfe, _log); ViewBag.HasError = true; ViewBag.Error = unfe.ToString(); ViewBag.ErrorMessage = "Your user name is not registered as a user on CATS. Please contact your system administrator."; } catch (DisabledUserException due) { log.LogAllErrorsMesseges(due, _log); ViewBag.HasError = true; ViewBag.Error = due.ToString(); ViewBag.ErrorMessage = "Your user account is disabled. Please contact your system administrator."; } catch(UnmatchingUsernameAndPasswordException uuape) { log.LogAllErrorsMesseges(uuape, _log); ViewBag.HasError = true; ViewBag.Error = uuape.ToString(); ViewBag.ErrorMessage = "The user name and password you provided do not match. Please try again with a correct combination."; } catch (Exception exception) { log.LogAllErrorsMesseges(exception, _log); ViewBag.HasError = true; ViewBag.Error = exception.ToString(); ViewBag.ErrorMessage = "Login failed. Try logging in with the right user name and password."; ModelState.AddModelError("", exception.Message); } return View(); }
public HubAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Hub); }
public EarlyWarningAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.EarlyWarning); }
public RegionalAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Region); }
public ProcurementAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Procurement); }
public LogisticsAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Logistics); }