Example #1
0
		public void SetPermissions (AccessControlList dacl)
		{
			throw new NotImplementedException ();
		}
Example #2
0
 /// <summary>
 /// Assigns access rights to the queue based on the contents of an access control list.
 /// </summary>
 /// <param name="dacl">A <see cref="T:System.Messaging.AccessControlList"/> that contains one or more access control entries that specify the trustees and the permissions to grant. </param><exception cref="T:System.Messaging.MessageQueueException">An error occurred when accessing a Message Queuing method. </exception><PermissionSet><IPermission class="System.Messaging.MessageQueuePermission, System.Messaging, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" version="1" Unrestricted="true"/></PermissionSet>
 public void SetPermissions(AccessControlList dacl)
 {
     _queue.SetPermissions(dacl);
 }
Example #3
0
        private void CreateMessageQueue()
        {
            if (MessageQueue.Exists(_QueueName))
            {
                _Queue = new MessageQueue(_QueueName);
            }
            else
            {
                _Queue = MessageQueue.Create(_QueueName, false);

                var acl = new AccessControlList();

                PrepareAccessControlEntries(acl);

                _Queue.SetPermissions(acl);
                _Queue.DefaultPropertiesToSend.Recoverable = true;

                _Queue.Formatter = new XmlMessageFormatter();
                //_queue.Formatter = new XmlMessageFormatter(new Type() { typeof(System.String) });
            }
        }
Example #4
0
        private static void PrepareAccessControlEntries(AccessControlList acl)
        {
            string aclEntry = @"\Administrators";
            AddACLEntry(acl, aclEntry);

            aclEntry = @"\Everyone";
            AddACLEntry(acl, aclEntry);
        }
Example #5
0
 private static void AddACLEntry(AccessControlList acl, string aclEntry)
 {
     var ace = new AccessControlEntry();
     ace.Trustee = new Trustee(aclEntry);
     ace.EntryType = AccessControlEntryType.Set;
     ace.GenericAccessRights = GenericAccessRights.All;
     ace.StandardAccessRights = StandardAccessRights.All;
     acl.Add(ace);
 }
Example #6
0
        // 尝试初始化 MSMQ 环境
        public void InitialMsmq()
        {
            if (MsmqInitialized == true)
                return;

            if (string.IsNullOrEmpty(this.OutgoingQueue) == true)
            {
                // 清除 Hangup 状态
                if (this.ContainsHangup("MessageQueueCreateFail") == true)
                {
                    this.ClearHangup("MessageQueueCreateFail");
                    this.WriteErrorLog("*** 系统已解除 MessageQueueCreateFail 挂起状态");
                }
                return;
            }

            try
            {
#if NO
                            if (MessageQueue.Exists(this.OutgoingQueue))
                            {
                                MessageQueue.Delete(this.OutgoingQueue);
                            }
#endif

                if (!MessageQueue.Exists(this.OutgoingQueue))
                {
                    MessageQueue queue = MessageQueue.Create(this.OutgoingQueue);

#if NO
                                // Create an AccessControlList.
                                AccessControlList list = new AccessControlList();

                                // Create a new trustee to represent the "Everyone" user group.
                                Trustee tr = new Trustee("Everyone");

                                // Create an AccessControlEntry, granting the trustee read access to
                                // the queue.
                                AccessControlEntry entry = new AccessControlEntry(
                                    tr, GenericAccessRights.Read,
                         StandardAccessRights.Read,
                                    AccessControlEntryType.Allow);

                                // Add the AccessControlEntry to the AccessControlList.
                                list.Add(entry);


                                // Apply the AccessControlList to the queue.
                                queue.SetPermissions(list);
#endif

                    var wi = WindowsIdentity.GetCurrent();
                    if (wi.IsSystem == true)
                    {
                        // 当前用户已经是 LocalSystem 了,需要额外给 Everyone 添加权限,以便让 dp2Capo 的控制台方式运行能访问这个 Queue
                        queue.SetPermissions(@"Everyone",
    MessageQueueAccessRights.ReceiveMessage
    | MessageQueueAccessRights.DeleteMessage
    | MessageQueueAccessRights.PeekMessage
    | MessageQueueAccessRights.GenericRead);
                    }

                    // 如果当前是 Administrator,表示可能是 dp2libraryxe 启动的方式,那么需要专门给 LocalSystem 操作 Queue 的权限,以便 Windows Service 方式的 dp2Capo 能访问 Queue
                    var wp = new WindowsPrincipal(wi);
                    if (wp.IsInRole(WindowsBuiltInRole.Administrator))
                    {
                        queue.SetPermissions(@"NT AUTHORITY\System",
                            MessageQueueAccessRights.FullControl);
                    }

                    this.WriteErrorLog("首次创建 MSMQ 队列 '" + this.OutgoingQueue + "' 成功");
                }

                MsmqInitialized = true;
                // 清除 Hangup 状态
                if (this.ContainsHangup("MessageQueueCreateFail") == true)
                {
                    this.ClearHangup("MessageQueueCreateFail");
                    this.WriteErrorLog("*** 系统已解除 MessageQueueCreateFail 挂起状态");
                }
            }
            catch (Exception ex)
            {
                if (this.ContainsHangup("MessageQueueCreateFail") == true)
                {
                    this.WriteErrorLog("*** 重试探测和尝试创建 MSMQ 队列 '" + this.OutgoingQueue + "' 失败: " + ExceptionUtil.GetExceptionMessage(ex)
    + " 系统仍处于挂起状态。");
                }
                else
                {
                    this.AddHangup("MessageQueueCreateFail");
                    this.WriteErrorLog("*** 探测和尝试创建 MSMQ 队列 '" + this.OutgoingQueue + "' 时出现异常: " + ExceptionUtil.GetDebugText(ex)
                        + " 系统已被挂起。");
                }
            }
        }