コード例 #1
0
ファイル: SecuredObject.cs プロジェクト: zhuxb711/Vanara
 public SecuredObject(CommonObjectSecurity security, string objName, string displayName)
 {
     ObjectSecurity = security;
     ObjectName     = objName;
     DisplayName    = displayName;
     IsContainer    = IsContainerObject(ObjectSecurity);
     MandatoryLabel = new SystemMandatoryLabel(ObjectSecurity);
 }
コード例 #2
0
        public SecuredObject(object knownObject)
        {
            // If just being passed a security object, grab it and stop
            if (knownObject is CommonObjectSecurity)
            {
                ObjectSecurity = knownObject as CommonObjectSecurity;
            }
            else
            {
                // Special handling for Tasks
                if (knownObject.GetType().FullName == "Microsoft.Win32.TaskScheduler.Task" || knownObject.GetType().FullName == "Microsoft.Win32.TaskScheduler.TaskFolder")
                {
                    IsContainer  = knownObject.GetType().Name == "TaskFolder";
                    TargetServer = knownObject.GetPropertyValue("TaskService").GetPropertyValue <string>("TargetServer");
                }

                // Get the security object using the standard "GetAccessControl" method
                try
                {
                    ObjectSecurity = knownObject.InvokeMethod <CommonObjectSecurity>("GetAccessControl", AccessControlSections.All);
                }
                catch (TargetInvocationException)
                {
                    try { ObjectSecurity = knownObject.InvokeMethod <CommonObjectSecurity>("GetAccessControl", AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner); }
                    catch { }
                }
                catch { }
                if (ObjectSecurity == null)
                {
                    try { ObjectSecurity = knownObject.InvokeMethod <CommonObjectSecurity>("GetAccessControl"); }
                    catch { }
                }
                if (ObjectSecurity == null)
                {
                    throw new ArgumentException("Object must have a GetAccessControl member.");
                }

                // Get the object names
                switch (knownObject.GetType().Name)
                {
                case "RegistryKey":
                    ObjectName  = knownObject.GetPropertyValue <string>("Name");
                    DisplayName = System.IO.Path.GetFileNameWithoutExtension(ObjectName);
                    break;

                case "Task":
                    DisplayName = knownObject.GetPropertyValue <string>("Name");
                    ObjectName  = knownObject.GetPropertyValue <string>("Path");
                    break;

                default:
                    ObjectName  = knownObject.GetPropertyValue <string>("FullName");
                    DisplayName = knownObject.GetPropertyValue <string>("Name");
                    if (ObjectName == null)
                    {
                        ObjectName = DisplayName;
                    }
                    break;
                }

                // Set the base object
                BaseObject = knownObject;
            }
            IsContainer    = SecuredObject.IsContainerObject(ObjectSecurity);
            MandatoryLabel = new SystemMandatoryLabel(ObjectSecurity);
        }