private void permissionCheckBox_CheckedChanged(object sender, EventArgs e) { CheckBox chkBox = sender as CheckBox; if (chkBox != null) { // Find out which permission has changed Permission permission = Permission.None; foreach (Permission p in Enum.GetValues(typeof(Permission))) { if (chkBox.Name.Contains(SecurityDemoHelper.GetPermissionString(p))) { permission = p; break; } } // Check if the permission is set char domainName = (char)cboDomain.SelectedItem; SecurityAccess access = chkBox.Name.Contains("View") ? SecurityAccess.View : SecurityAccess.Modify; bool permissionGranted = owner.SecurityManager.IsGranted(permission, access, domainName); // Update only if the granted state changed if (permissionGranted != chkBox.Checked) { StandardRole role = (StandardRole)cboUser.SelectedItem; // Set General or Domain permissions if (permission == Permission.Designs || permission == Permission.Security || permission == Permission.Templates) { if (chkBox.Checked) { owner.SecurityManager.AddPermissions(role, permission, access); } else { owner.SecurityManager.RemovePermissions(role, permission, access); } } else { if (chkBox.Checked) { owner.SecurityManager.AddPermissions(domainName, role, permission, access); } else { owner.SecurityManager.RemovePermissions(domainName, role, permission, access); } } UpdateSecurityControls(); } } }
/// <summary> /// Returns the name of the given role. /// </summary> public string GetRoleName(StandardRole role) { switch (role) { case StandardRole.Administrator: return(roleNameAdministrator); case StandardRole.Designer: return(roleNameDesigner); case StandardRole.Guest: return(roleNameGuest); case StandardRole.Operator: return(roleNameOperator); case StandardRole.SuperUser: return(roleNameSuperUser); default: throw new InvalidOperationException(string.Format("{0} is not a valid role for this operation.", role)); } }
/// <summary> /// Returns the name of the given role. /// </summary> public string GetRoleName(StandardRole role) { switch (role) { case StandardRole.Administrator: return(roleNameAdministrator); case StandardRole.Designer: return(roleNameDesigner); case StandardRole.Guest: return(roleNameGuest); case StandardRole.Operator: return(roleNameOperator); case StandardRole.SuperUser: return(roleNameSuperUser); default: throw new InvalidOperationException(string.Format(Dataweb.NShape.Properties.Resources.MessageFmt_0IsNotAValidRoleForThisOperation, role)); } }
/// <summary> /// Removes permissions from the given domain and role. /// </summary> /// <remarks>Security domain dependent permissions are checked against the role's domain permissions.</remarks> public void RemovePermissions(char domain, StandardRole role, Permission permissions, SecurityAccess access) { string roleName = GetRoleName(role); RemovePermissions(domain, roleName, permissions, access); }
/// <summary> /// Removes permissions from the given domain and role. /// </summary> /// <remarks>Security domain dependent permissions are checked against the role's domain permissions.</remarks> public void RemovePermissions(char domain, StandardRole role, Permission permissions) { RemovePermissions(domain, role, permissions, SecurityAccess.View); }
/// <summary> /// Removes permissions from the given role. /// </summary> /// <remarks>Security domain independent permissions are checked against the role permissions.</remarks> public void RemovePermissions(StandardRole role, Permission permissions) { RemovePermissions(role, permissions, SecurityAccess.View); }
/// <summary> /// Redefines the permissions of the given domain and role. /// </summary> /// <remarks>Security domain dependent permissions are checked against the role's domain permissions.</remarks> public void SetPermissions(char domain, StandardRole role, Permission permissions) { SetPermissions(domain, role, permissions, SecurityAccess.Modify); }
/// <summary> /// Redefines the permissions of the given role. /// </summary> /// <remarks>Security domain independent permissions are checked against the role permissions.</remarks> public void SetPermissions(StandardRole role, Permission permissions, SecurityAccess access) { string roleName = GetRoleName(role); SetPermissions(roleName, permissions, access); }
/// <summary> /// Redefines the permissions of the given role. /// </summary> /// <remarks>Security domain independent permissions are checked against the role permissions.</remarks> public void SetPermissions(StandardRole role, Permission permissions) { SetPermissions(role, permissions, SecurityAccess.Modify); }
/// <summary> /// Returns the name of the given role. /// </summary> public string GetRoleName(StandardRole role) { switch (role) { case StandardRole.Administrator: return roleNameAdministrator; case StandardRole.Designer: return roleNameDesigner; case StandardRole.Guest: return roleNameGuest; case StandardRole.Operator: return roleNameOperator; case StandardRole.SuperUser: return roleNameSuperUser; default: throw new InvalidOperationException(string.Format("{0} is not a valid role for this operation.", role)); } }
/// <summary> /// Removes permissions from the given domain and role. /// </summary> public void RemovePermissions(char domain, StandardRole role, Permission permissions) { string roleName = GetRoleName(role); RemovePermissions(domain, roleName, permissions); }
/// <summary> /// Redefines the permissions of the given domain and role. /// </summary> public void SetPermissions(char domain, StandardRole role, Permission permissions) { string roleName = GetRoleName(role); SetPermissions(domain, roleName, permissions); }