コード例 #1
0
        private void GridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
        {
            string fieldName    = e.Column.FieldName;
            object targetObject = employeeGridView.GetRow(e.RowHandle);

            if (!security.IsGranted(new PermissionRequest(securedObjectSpace, typeof(Employee), SecurityOperations.Read, targetObject, fieldName)))
            {
                e.RepositoryItem = new RepositoryItemProtectedContentTextEdit();
            }
        }
コード例 #2
0
 private void EmployeeListForm_Load(object sender, EventArgs e)
 {
     security            = ((MainForm)MdiParent).Security;
     objectSpaceProvider = ((MainForm)MdiParent).ObjectSpaceProvider;
     securedObjectSpace  = objectSpaceProvider.CreateObjectSpace();
     employeeBindingSource.DataSource = securedObjectSpace.GetObjects <Employee>();
     newBarButtonItem.Enabled         = security.IsGranted(new PermissionRequest(securedObjectSpace, typeof(Employee), SecurityOperations.Create));
 }
        private void AddControl(LayoutControlItem layout, object targetObject, string memberName)
        {
            layout.Text = memberName;
            Type     type = targetObject.GetType();
            BaseEdit control;

            if (security.IsGranted(new PermissionRequest(securedObjectSpace, type, SecurityOperations.Read, targetObject, memberName)))
            {
                control = GetControl(type, memberName);
                if (control != null)
                {
                    control.DataBindings.Add(new Binding("EditValue", employeeBindingSource, memberName, true, DataSourceUpdateMode.OnPropertyChanged));
                    control.Enabled = security.IsGranted(new PermissionRequest(securedObjectSpace, type, SecurityOperations.Write, targetObject, memberName));
                }
            }
            else
            {
                control         = new ProtectedContentEdit();
                control.Enabled = false;
            }
            dataLayoutControl1.Controls.Add(control);
            layout.Control = control;
        }
コード例 #4
0
        static void Main()
        {
            RegisterEntities();
            AuthenticationStandard  authentication = new AuthenticationStandard();
            SecurityStrategyComplex security       = new SecurityStrategyComplex(typeof(PermissionPolicyUser), typeof(PermissionPolicyRole), authentication);

            security.RegisterXPOAdapterProviders();

            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SecuredObjectSpaceProvider objectSpaceProvider = new SecuredObjectSpaceProvider(security, connectionString, null);

            PasswordCryptographer.EnableRfc2898       = true;
            PasswordCryptographer.SupportLegacySha512 = false;

            string userName = "******";
            string password = string.Empty;

            authentication.SetLogonParameters(new AuthenticationStandardLogonParameters(userName, password));
            IObjectSpace loginObjectSpace = objectSpaceProvider.CreateObjectSpace();

            security.Logon(loginObjectSpace);

            using (StreamWriter file = new StreamWriter("result.txt", false)) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append($"{userName} is logged on.\n");
                stringBuilder.Append("List of the 'Employee' objects:\n");
                using (IObjectSpace securedObjectSpace = objectSpaceProvider.CreateObjectSpace()) {
                    foreach (Employee employee in securedObjectSpace.GetObjects <Employee>())
                    {
                        stringBuilder.Append("=========================================\n");
                        stringBuilder.Append($"Full name: {employee.FullName}\n");
                        if (security.IsGranted(new PermissionRequest(securedObjectSpace, typeof(Employee), SecurityOperations.Read, employee, nameof(Department))))
                        {
                            stringBuilder.Append($"Department: {employee.Department.Title}\n");
                        }
                        else
                        {
                            stringBuilder.Append("Department: [Protected content]\n");
                        }
                    }
                }
                file.Write(stringBuilder);
            }
            Console.WriteLine(@"The result.txt file has been created in the \bin\Debug directory.");
            Console.WriteLine("Press any key to close the console...");
            Console.ReadLine();
        }
 private void EmployeeDetailForm_Load(object sender, EventArgs e)
 {
     security            = ((MainForm)MdiParent).Security;
     objectSpaceProvider = ((MainForm)MdiParent).ObjectSpaceProvider;
     securedObjectSpace  = objectSpaceProvider.CreateObjectSpace();
     if (employee == null)
     {
         employee = securedObjectSpace.CreateObject <Employee>();
     }
     else
     {
         employee = securedObjectSpace.GetObject(employee);
         deleteBarButtonItem.Enabled = security.IsGranted(new PermissionRequest(securedObjectSpace, typeof(Employee), SecurityOperations.Delete, employee));
     }
     employeeBindingSource.DataSource = employee;
     AddControls();
 }
コード例 #6
0
        private bool IsGranted(string operation, object employee = null, GridViewDataColumn column = null)
        {
            string memberName = column?.FieldName.Split('!')[0];

            return(security.IsGranted(new PermissionRequest(objectSpace, typeof(Employee), operation, employee, memberName)));
        }