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; }
protected void chkStorageCache_CheckedChanged(object sender, EventArgs e) { if (this.chkStorageCache.Checked && this.chkCache.Checked) { this.chkCache.Checked = false; } this.cache = null; }
protected void Button3_Click(object sender, EventArgs e) { UserPermissionCache cache = (UserPermissionCache)(Session["cache"]); System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <string, string> > attrs; AuthorizationType a = cache.CheckAccess("Operation0", DateTime.Now, out attrs); this.TextBox1.Text = a.ToString(); }
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; }
public static UserPermissionCache GetUserPermissionCache(CatsGlobals.Applications application) { UserPermissionCache permissionsCache = null; switch (application) { case CatsGlobals.Applications.EarlyWarning: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.EARLY_WARNING_PERMISSIONS]; break; case CatsGlobals.Applications.PSNP: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.PSNP_PERMISSIONS]; break; case CatsGlobals.Applications.Logistics: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.LOGISTICS_PERMISSIONS]; break; case CatsGlobals.Applications.Procurement: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.PROCUREMENT_PERMISSIONS]; break; case CatsGlobals.Applications.Finance: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.FINANCE_PERMISSIONS]; break; case CatsGlobals.Applications.Hub: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.HUB_PERMISSIONS]; break; case CatsGlobals.Applications.Administration: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.ADMINISTRATION_PERMISSIONS]; break; case CatsGlobals.Applications.Region: permissionsCache = (UserPermissionCache)HttpContext.Current.Session[CatsGlobals.REGION_PERMISSIONS]; break; } return(permissionsCache); }
private void CheckNodeAccess(TreeNode tn) { var tag = (ItemType)tn.Tag; string sItemType = String.Empty; switch (tag) { case ItemType.Role: sItemType = "Role"; break; case ItemType.Task: sItemType = "Task"; break; case ItemType.Operation: sItemType = "Operation"; break; } 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 (chkUserPermisisonCache.Checked && _UserPermissionCache == null) { txtDetails.Text += "Building UserPermissionCache ... " + Environment.NewLine; _UserPermissionCache = new UserPermissionCache(_Storage, _Store.Name, _Application.Name, _DbUser, true, false); chkEnd = DateTime.Now; elapsedTime = (TimeSpan)chkEnd.Subtract(chkStart); txtDetails.Text += String.Format("[{0} mls.]\r\n", elapsedTime.TotalMilliseconds) + Environment.NewLine; } else if (chkStorageCache.Checked && _StorageCache == null) { txtDetails.Text += "Building StorageCache ... " + Environment.NewLine; _StorageCache = new StorageCache(_Storage.ConnectionString); _StorageCache.BuildStorageCache(_Store.Name, _Application.Name); chkEnd = DateTime.Now; elapsedTime = (TimeSpan)chkEnd.Subtract(chkStart); txtDetails.Text += String.Format("[{0} mls.]\r\n", elapsedTime.TotalMilliseconds) + Environment.NewLine; } chkStart = DateTime.Now; elapsedTime = TimeSpan.Zero; txtDetails.Text += String.Format("{0} {1} '{2}' ... ", "Check Access Test on", sItemType, tn.Text); try { if (chkUserPermisisonCache.Checked) { auth = _UserPermissionCache.CheckAccess( tn.Text, !String.IsNullOrEmpty(txtValidFor.Text) ? Convert.ToDateTime(txtValidFor.Text) : DateTime.Now, out attributes); } else if (this.chkStorageCache.Checked) { auth = _StorageCache.CheckAccess( _Store.Name, _Application.Name, tn.Text, _DbUser.CustomSid.StringValue, !String.IsNullOrEmpty(txtValidFor.Text) ? Convert.ToDateTime(txtValidFor.Text) : DateTime.Now, false, out attributes); } else { auth = _Storage.CheckAccess( _Store.Name, _Application.Name, tn.Text, _DbUser, !String.IsNullOrEmpty(txtValidFor.Text) ? Convert.ToDateTime(txtValidFor.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; txtDetails.Text += String.Format("{0} [{1} mls.]", sAuth, elapsedTime.TotalMilliseconds) + Environment.NewLine; if (attributes != null && attributes.Count > 0) { txtDetails.Text += String.Format(" {0} attribute(s) found:", attributes.Count) + Environment.NewLine; int attributeIndex = 0; foreach (KeyValuePair <string, string> attr in attributes) { txtDetails.Text += String.Format(" {0}) Key: {1} Value: {2}", ++attributeIndex, attr.Key, attr.Value) + Environment.NewLine; } } } catch (Exception ex) { sAuth = "Check Access Test Error"; txtDetails.Text += String.Format("{0} [{1} mls.]", ex.Message, elapsedTime.TotalMilliseconds) + Environment.NewLine; } tn.Text = String.Format("{0} - ({1})", tn.Text, sAuth.ToUpper()); foreach (TreeNode tnChild in tn.Nodes) { CheckNodeAccess(tnChild); } }
public User() { _userPermissionCache = new UserPermissionCache(); }
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); } }
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 LogisticsAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Logistics); }
public PSNPAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.PSNP); }
public EarlyWarningAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.EarlyWarning); }
public RegionalAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Region); }
public ProcurementAuthorize() { ewCache = UserAccountHelper.GetUserPermissionCache(CatsGlobals.Applications.Procurement); }