private void Initialization() { BaseUser user = new BaseUser(); user.IsGuest = true; user.Name = "Guest"; LoggedUser = user; }
public bool HasPermission(object accessingObject, BaseUser user) { ILog logger = LogManager.GetLogger("AppFrame"); logger.Info("Check permission "); if (accessingObject == null || user == null) { return false; } // get key string key = (string)accessingObject; logger.Info(" key is" + key); // get valid role for accessing object IList<Role> validRoles = permissionMap[key]; // check whether user is valid for accessing object for (int i = 0; i < validRoles.Count; i++) { Role validRole = validRoles[i]; logger.Info(" Role name is " + validRole.Name); if (user.IsInRole(validRole)) { logger.Info("return true"); return true; } } logger.Info("return false"); return false; }
private static void setPermission(BaseUser user, ref ToolStripMenuItem menuItem, MenuItemPermission permission) { // 1. get Menu Item // 2. Check role of user if(menuItem == null) return; bool hasPermission = permission.HasPermission(menuItem.Name, user); // 3. Process menu presentation base on user's role. if (hasPermission) { menuItem.Enabled = true; menuItem.Visible = true; } else { switch (permission.DeniedAction) { case MenuItemPermission.DISABLED: menuItem.Enabled = false; break; case MenuItemPermission.INVISIBLE: menuItem.Visible = false; break; case MenuItemPermission.POPUP: break; case MenuItemPermission.NORMAL: break; } } for(int i = 0;i<menuItem.DropDownItems.Count;i++) { ToolStripMenuItem childMenuItem = menuItem.DropDownItems[i] as ToolStripMenuItem; setPermission(user,ref childMenuItem, permission); } }
public static BaseUser CreateGuestUser() { BaseUser guestUser = new BaseUser(); guestUser.IsGuest = true; guestUser.Name = "Guest"; guestUser.FullName = "Khách viếng thăm"; return guestUser; }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <param name="menuStrip"></param> /// <param name="menuItemPermission"></param> public static void setPermission(BaseUser user, ref MenuStrip menuStrip, MenuItemPermission menuItemPermission) { for (int i = 0; i < menuStrip.Items.Count ; i++) { // 1. get Menu Item ToolStripMenuItem toolStripMenuItem = menuStrip.Items[i] as ToolStripMenuItem; // 2. Set permission setPermission(user, ref toolStripMenuItem, menuItemPermission); // 3. Set permission for child } }
public BaseUser login(string username,string password) { BaseUser checkingUser = new BaseUser(); if(UserManager.validateUser(username,password)) { checkingUser = UserManager.getUser(username); } else { checkingUser = UserManager.getUser(null); } return checkingUser; }
public void Before(System.Reflection.MethodInfo method, object[] args, object target) { ILog logger = LogManager.GetLogger("AppFrame"); logger.Info("Go to InsertUserInfoToLogicAdvice"); // create a new instance of BaseUser BaseUser currentUser = ClientInfo.getInstance().LoggedUser as BaseUser; BaseUser baseUser = new BaseUser(); baseUser.Name = currentUser.Name; baseUser.Roles = currentUser.Roles; baseUser.IsGuest = currentUser.IsGuest; IAuthoriseLogic logic = target as IAuthoriseLogic; logic.CurrentUser = baseUser; logger.Info("Set BaseUser completed !"); }
/// <summary> /// /// </summary> /// <param name="accessingObject"></param> /// <param name="user"></param> /// <returns></returns> public bool HasPermission(object accessingObject, BaseUser user) { if (accessingObject == null || user == null) { return false; } // get key string key = (string) accessingObject; // get valid role for accessing object List<Role> validRoles = toolStripItemMap[key]; // check whether user is valid for accessing object for (int i = 0; i < validRoles.Count; i++) { Role validRole = validRoles[i]; if (user.IsInRole(validRole)) { return true; } } return false; }
private static void setPermission(BaseUser baseUser, ref ToolStrip toolStrip, ToolStripItemPermission toolStripPermission) { for (int i = 0; i < toolStrip.Items.Count ; i++) { // 1. get Menu Item ToolStripItem toolStripMenuItem = toolStrip.Items[i] as ToolStripItem; // 2. Set permission setPermission(baseUser, ref toolStripMenuItem, toolStripPermission); // 3. Set permission for child } }
private static void setPermission(BaseUser baseUser, ref ToolStripItem toolStripMenuItem, ToolStripItemPermission toolStripPermission) { // 1. get Menu Item // 2. Check role of user if (toolStripMenuItem == null) return; bool hasPermission = toolStripPermission.HasPermission(toolStripMenuItem.Name, baseUser); // 3. Process menu presentation base on user's role. if (hasPermission) { toolStripMenuItem.Enabled = true; toolStripMenuItem.Visible = true; } else { switch (toolStripPermission.DeniedAction) { case MenuItemPermission.DISABLED: toolStripMenuItem.Enabled = false; break; case MenuItemPermission.INVISIBLE: toolStripMenuItem.Visible = false; break; case MenuItemPermission.POPUP: break; case MenuItemPermission.NORMAL: break; } } }