示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try {
                // Set up the XML storee component (storage directory and file extension)
                string dir = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)) + @"\Demo Programs\Security Demo\Sample Project";
                xmlStore.DirectoryName = dir;
                xmlStore.FileExtension = ".nspj";

                // Add a search path for shape assemblies (application's startup directory in this case)
                project.LibrarySearchPaths.Add(Application.StartupPath);
                // Set the name of the project to open and open it
                project.Name = "Security Demo Sample Project";
                project.Open();

                // Activate the pointer tool and load the sample diagram
                display1.ActiveTool = toolSetController.DefaultTool;
                display1.LoadDiagram("Simple Circuit");

                chkHideMenuItems.Checked  = true;
                chkHideProperties.Checked = true;
                SecurityDemoHelper.FillUserAndDomainComboBoxes(cboUser, cboDomain);
                InitializeSecurityManager();

                UpdateSecurityInfoCtrls();
            } catch (Exception exc) {
                // Always catch exceptions in the Form.Load event (and show their messages) as the framework
                // swallows all exceptions thrown in this exception handler without any notice in non-debug mode!
                MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        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();
                }
            }
        }
示例#3
0
        private void UpdateSecurityControls()
        {
            if (cboUser.SelectedItem != null && cboDomain.SelectedItem != null)
            {
                // Update Security Infos and the owner's controls
                owner.SecurityManager.CurrentRole = (StandardRole)cboUser.SelectedItem;
                owner.UpdateSecurityInfoCtrls();

                char domainName = (char)cboDomain.SelectedItem;
                SecurityDemoHelper.UpdatePermissionTableCtrls(owner.SecurityManager, permissionsPanel, domainName, Dataweb.NShape.SecurityAccess.View);
                SecurityDemoHelper.UpdatePermissionTableCtrls(owner.SecurityManager, permissionsPanel, domainName, Dataweb.NShape.SecurityAccess.Modify);
            }
        }
示例#4
0
        public SecuritySettingsEditor(MainForm owner)
        {
            InitializeComponent();
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            this.owner = owner;

            SecurityDemoHelper.FillUserAndDomainComboBoxes(cboUser, cboDomain);
            cboUser.SelectedItem    = owner.SecurityManager.CurrentRole;
            cboDomain.SelectedIndex = 0;
        }
示例#5
0
        /// <summary>
        /// Update all controls that display security information
        /// </summary>
        public void UpdateSecurityInfoCtrls()
        {
            if (cboUser.SelectedItem == null || (StandardRole)cboUser.SelectedItem != SecurityManager.CurrentRole)
            {
                cboUser.SelectedItem = SecurityManager.CurrentRole;
            }
            char domainName = (char)(cboDomain.SelectedItem ?? SecurityDemoHelper.NoDomain);

            SecurityDemoHelper.UpdatePermissionTableCtrls(SecurityManager, domainPermissionInfoPanel, domainName, SecurityAccess.View);
            SecurityDemoHelper.UpdatePermissionTableCtrls(SecurityManager, domainPermissionInfoPanel, domainName, SecurityAccess.Modify);
            UpdateDomainPermissionCtrls();

            // Update displayed properties
            propertyGrid1.Refresh();
        }
示例#6
0
        private void propertyController1_ObjectsSet(object sender, Dataweb.NShape.Controllers.PropertyControllerEventArgs e)
        {
            // Get common security domain name of all selected objects
            if (e.Objects.Count > 0)
            {
                char dom = SecurityDemoHelper.NoDomain;
                foreach (object o in e.Objects)
                {
                    if (o is ISecurityDomainObject)
                    {
                        if (dom == SecurityDemoHelper.NoDomain)
                        {
                            dom = ((ISecurityDomainObject)o).SecurityDomainName;
                        }
                        else if (dom != ((ISecurityDomainObject)o).SecurityDomainName)
                        {
                            dom = '!';
                            break;
                        }
                    }
                }
                cboDomain.SelectedIndex = Math.Max(dom - 'A', -1);
            }
            else
            {
                cboDomain.SelectedIndex = -1;
            }

            // Store security objects and their type for later use
            if (e.Objects.Count > 0)
            {
                currentSecurityObjects    = SecurityDemoHelper.GetSecurityDomainObjects(e.Objects);
                currentSecurityObjectType = e.ObjectsType;
            }
            else
            {
                currentSecurityObjects    = null;
                currentSecurityObjectType = null;
            }
            UpdateDomainPermissionCtrls(currentSecurityObjects, currentSecurityObjectType);
        }
示例#7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try {
                string dir = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)) + @"\Demo Programs\Security Demo\Sample Project";
                xmlStore.DirectoryName = dir;
                xmlStore.FileExtension = ".nspj";

                project.LibrarySearchPaths.Add(Application.StartupPath);
                project.Name = "Security Demo Sample Project";
                project.Open();

                display1.CurrentTool = toolSetController.DefaultTool;
                display1.LoadDiagram("Simple Circuit");

                chkHideMenuItems.Checked  = true;
                chkHideProperties.Checked = true;
                SecurityDemoHelper.FillUserAndDomainComboBoxes(cboUser, cboDomain);
                InitializeSecurityManager();

                UpdateSecurityInfoCtrls();
            } catch (Exception exc) {
                MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#8
0
        private void UpdateDomainPermissionCtrls(IEnumerable <ISecurityDomainObject> securityObjects, Type objType)
        {
            lblCurrentSecObj.Text = (objType != null) ? objType.Name : string.Empty;
            string currObjDom = string.Empty;

            if (securityObjects != null)
            {
                foreach (ISecurityDomainObject obj in securityObjects)
                {
                    if (obj == null)
                    {
                        continue;
                    }
                    if (currObjDom.IndexOf(obj.SecurityDomainName) < 0)
                    {
                        currObjDom += string.Format("{0}{1}", string.IsNullOrEmpty(currObjDom) ? "" : ", ", obj.SecurityDomainName);
                    }
                }
                lblCurrentDomain.Text = currObjDom;
            }

            string currGenPermissions = string.Empty;
            string currDomPermissions = string.Empty;

            foreach (Permission permission in Enum.GetValues(typeof(Permission)))
            {
                switch (permission)
                {
                case Permission.All:
                case Permission.None:
                    // Nothing to do
                    break;

                case Permission.Designs:
                case Permission.Security:
                case Permission.Templates:
                    // Update effective permissions
                    if (!string.IsNullOrEmpty(currGenPermissions))
                    {
                        currGenPermissions += ", ";
                    }
                    currGenPermissions += SecurityDemoHelper.GetPermissionString(permission);
                    break;

                case Permission.Connect:
                case Permission.Data:
                case Permission.Delete:
                case Permission.Insert:
                case Permission.Layout:
                case Permission.Present:
                    if (securityObjects != null)
                    {
                        if (SecurityManager.IsGranted(permission, securityObjects))
                        {
                            if (!string.IsNullOrEmpty(currDomPermissions))
                            {
                                currDomPermissions += ", ";
                            }
                            currDomPermissions += SecurityDemoHelper.GetPermissionString(permission);
                        }
                    }
                    break;

                default:
                    Debug.Fail("Unhandled Permission!");
                    break;
                }
            }
            if (string.IsNullOrEmpty(currGenPermissions))
            {
                currGenPermissions = Permission.None.ToString();
            }
            lblCurrentGenPerm.Text = currGenPermissions;
            if (string.IsNullOrEmpty(currDomPermissions))
            {
                currDomPermissions = Permission.None.ToString();
            }
            lblCurrentDomPerm.Text = currDomPermissions;
        }