/// <include file='doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Intersect"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));
            }

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;

            if (this.IsUnrestricted())
            {
                return(targetQueuePermission.Copy());
            }

            if (targetQueuePermission.IsUnrestricted())
            {
                return(this.Copy());
            }

            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();
            MessageQueuePermission newPermission = new MessageQueuePermission();
            Hashtable newFormatNames             = new Hashtable(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture));

            newPermission.resolvedFormatNames = newFormatNames;
            IDictionaryEnumerator formatNamesEnumerator;
            Hashtable             formatNamesTable;

            if (this.resolvedFormatNames.Count < targetQueuePermission.resolvedFormatNames.Count)
            {
                formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
                formatNamesTable      = targetQueuePermission.resolvedFormatNames;
            }
            else
            {
                formatNamesEnumerator = targetQueuePermission.resolvedFormatNames.GetEnumerator();
                formatNamesTable      = this.resolvedFormatNames;
            }

            while (formatNamesEnumerator.MoveNext())
            {
                if (formatNamesTable.ContainsKey(formatNamesEnumerator.Key))
                {
                    string currentFormatName = (string)formatNamesEnumerator.Key;
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)formatNamesEnumerator.Value;
                    MessageQueuePermissionAccess targetAccess  = (MessageQueuePermissionAccess)formatNamesTable[currentFormatName];
                    newFormatNames.Add(currentFormatName, currentAccess & targetAccess);
                }
            }

            return(newPermission);
        }
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(false);
            }
            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString("InvalidParameter", new object[] { "target", target.ToString() }));
            }
            MessageQueuePermission permission = (MessageQueuePermission)target;

            if (!permission.IsUnrestricted())
            {
                IDictionaryEnumerator enumerator;
                if (this.IsUnrestricted())
                {
                    return(false);
                }
                this.ResolveFormatNames();
                permission.ResolveFormatNames();
                if (((this.resolvedFormatNames.Count == 0) && (permission.resolvedFormatNames.Count != 0)) || ((this.resolvedFormatNames.Count != 0) && (permission.resolvedFormatNames.Count == 0)))
                {
                    return(false);
                }
                if (permission.resolvedFormatNames.ContainsKey("*"))
                {
                    MessageQueuePermissionAccess access = (MessageQueuePermissionAccess)permission.resolvedFormatNames["*"];
                    enumerator = this.resolvedFormatNames.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        MessageQueuePermissionAccess access2 = (MessageQueuePermissionAccess)enumerator.Value;
                        if ((access2 & access) != access2)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                enumerator = this.resolvedFormatNames.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string key = (string)enumerator.Key;
                    if (!permission.resolvedFormatNames.ContainsKey(key))
                    {
                        return(false);
                    }
                    MessageQueuePermissionAccess access3 = (MessageQueuePermissionAccess)enumerator.Value;
                    MessageQueuePermissionAccess access4 = (MessageQueuePermissionAccess)permission.resolvedFormatNames[key];
                    if ((access3 & access4) != access3)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
		public override IPermission Copy ()
		{
			if (_unrestricted)
				return new MessageQueuePermission (PermissionState.Unrestricted);
			else {
				MessageQueuePermission copy = new MessageQueuePermission (PermissionState.None);
				foreach (MessageQueuePermissionEntry entry in _list)
					copy._list.Add (entry);
				return copy;
			}
		}
        public override IPermission Copy()
        {
            MessageQueuePermission permission = new MessageQueuePermission {
                isUnrestricted = this.isUnrestricted
            };

            foreach (MessageQueuePermissionEntry entry in this.PermissionEntries)
            {
                permission.PermissionEntries.Add(entry);
            }
            permission.resolvedFormatNames = this.resolvedFormatNames;
            return(permission);
        }
        public override IPermission Intersect(IPermission target)
        {
            IDictionaryEnumerator enumerator;
            Hashtable             resolvedFormatNames;

            if (target == null)
            {
                return(null);
            }
            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString("InvalidParameter", new object[] { "target", target.ToString() }));
            }
            MessageQueuePermission permission = (MessageQueuePermission)target;

            if (this.IsUnrestricted())
            {
                return(permission.Copy());
            }
            if (permission.IsUnrestricted())
            {
                return(this.Copy());
            }
            this.ResolveFormatNames();
            permission.ResolveFormatNames();
            MessageQueuePermission permission2 = new MessageQueuePermission();
            Hashtable hashtable = new Hashtable(GetComparer());

            permission2.resolvedFormatNames = hashtable;
            if (this.resolvedFormatNames.Count < permission.resolvedFormatNames.Count)
            {
                enumerator          = this.resolvedFormatNames.GetEnumerator();
                resolvedFormatNames = permission.resolvedFormatNames;
            }
            else
            {
                enumerator          = permission.resolvedFormatNames.GetEnumerator();
                resolvedFormatNames = this.resolvedFormatNames;
            }
            while (enumerator.MoveNext())
            {
                if (resolvedFormatNames.ContainsKey(enumerator.Key))
                {
                    string key = (string)enumerator.Key;
                    MessageQueuePermissionAccess access  = (MessageQueuePermissionAccess)enumerator.Value;
                    MessageQueuePermissionAccess access2 = (MessageQueuePermissionAccess)resolvedFormatNames[key];
                    hashtable.Add(key, access & access2);
                }
            }
            return(permission2);
        }
        /// <include file='doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Union"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }

            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));
            }

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;
            MessageQueuePermission newPermission         = new MessageQueuePermission();

            if (this.IsUnrestricted() || targetQueuePermission.IsUnrestricted())
            {
                newPermission.isUnrestricted = true;
                return(newPermission);
            }

            Hashtable newFormatNames = new Hashtable(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture));

            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();

            IDictionaryEnumerator formatNamesEnumerator       = this.resolvedFormatNames.GetEnumerator();
            IDictionaryEnumerator targetFormatNamesEnumerator = targetQueuePermission.resolvedFormatNames.GetEnumerator();

            while (formatNamesEnumerator.MoveNext())
            {
                newFormatNames[(string)formatNamesEnumerator.Key] = formatNamesEnumerator.Value;
            }

            while (targetFormatNamesEnumerator.MoveNext())
            {
                if (!newFormatNames.ContainsKey(targetFormatNamesEnumerator.Key))
                {
                    newFormatNames[targetFormatNamesEnumerator.Key] = targetFormatNamesEnumerator.Value;
                }
                else
                {
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)newFormatNames[targetFormatNamesEnumerator.Key];
                    newFormatNames[targetFormatNamesEnumerator.Key] = currentAccess | (MessageQueuePermissionAccess)targetFormatNamesEnumerator.Value;
                }
            }

            newPermission.resolvedFormatNames = newFormatNames;
            return(newPermission);
        }
Exemplo n.º 7
0
 public override IPermission Copy()
 {
     if (_unrestricted)
     {
         return(new MessageQueuePermission(PermissionState.Unrestricted));
     }
     else
     {
         MessageQueuePermission copy = new MessageQueuePermission(PermissionState.None);
         foreach (MessageQueuePermissionEntry entry in _list)
         {
             copy._list.Add(entry);
         }
         return(copy);
     }
 }
Exemplo n.º 8
0
        private MessageQueuePermission Cast(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            MessageQueuePermission mqp = (target as MessageQueuePermission);

            if (mqp == null)
            {
                ThrowInvalidPermission(target, typeof(MessageQueuePermission));
            }

            return(mqp);
        }
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString("InvalidParameter", new object[] { "target", target.ToString() }));
            }
            MessageQueuePermission permission  = (MessageQueuePermission)target;
            MessageQueuePermission permission2 = new MessageQueuePermission();

            if (this.IsUnrestricted() || permission.IsUnrestricted())
            {
                permission2.isUnrestricted = true;
                return(permission2);
            }
            Hashtable hashtable = new Hashtable(GetComparer());

            this.ResolveFormatNames();
            permission.ResolveFormatNames();
            IDictionaryEnumerator enumerator  = this.resolvedFormatNames.GetEnumerator();
            IDictionaryEnumerator enumerator2 = permission.resolvedFormatNames.GetEnumerator();

            while (enumerator.MoveNext())
            {
                hashtable[(string)enumerator.Key] = enumerator.Value;
            }
            while (enumerator2.MoveNext())
            {
                if (!hashtable.ContainsKey(enumerator2.Key))
                {
                    hashtable[enumerator2.Key] = enumerator2.Value;
                }
                else
                {
                    MessageQueuePermissionAccess access = (MessageQueuePermissionAccess)hashtable[enumerator2.Key];
                    hashtable[enumerator2.Key] = access | ((MessageQueuePermissionAccess)enumerator2.Value);
                }
            }
            permission2.resolvedFormatNames = hashtable;
            return(permission2);
        }
        public static bool TryGetPermissions(this MessageQueue queue, string user, out MessageQueueAccessRights? rights)
        {
            if (!administerGranted)
            {
                var permission = new MessageQueuePermission(MessageQueuePermissionAccess.Administer, PREFIX_FORMAT_NAME + queue.FormatName);
                permission.Demand();

                administerGranted = true;
            }

            var sid = GetSidForUser(user);

            try
            {
                rights = GetPermissions(queue.FormatName, sid);
                return true;
            }
            catch
            {
                rights = null;
                return false;
            }
        }
Exemplo n.º 11
0
        /// <include file='doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Union"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
                return this.Copy();

            if (!(target is MessageQueuePermission))
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;
            MessageQueuePermission newPermission = new MessageQueuePermission();
            if (this.IsUnrestricted() || targetQueuePermission.IsUnrestricted())
            {
                newPermission.isUnrestricted = true;
                return newPermission;
            }

            Hashtable newFormatNames = new Hashtable(GetComparer());
            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();

            IDictionaryEnumerator formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
            IDictionaryEnumerator targetFormatNamesEnumerator = targetQueuePermission.resolvedFormatNames.GetEnumerator();
            while (formatNamesEnumerator.MoveNext())
                newFormatNames[(string)formatNamesEnumerator.Key] = formatNamesEnumerator.Value;

            while (targetFormatNamesEnumerator.MoveNext())
            {
                if (!newFormatNames.ContainsKey(targetFormatNamesEnumerator.Key))
                    newFormatNames[targetFormatNamesEnumerator.Key] = targetFormatNamesEnumerator.Value;
                else
                {
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)newFormatNames[targetFormatNamesEnumerator.Key];
                    newFormatNames[targetFormatNamesEnumerator.Key] = currentAccess | (MessageQueuePermissionAccess)targetFormatNamesEnumerator.Value;
                }
            }

            newPermission.resolvedFormatNames = newFormatNames;
            return newPermission;
        }
Exemplo n.º 12
0
        /// <include file='doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Intersect"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
                return null;

            if (!(target is MessageQueuePermission))
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;
            if (this.IsUnrestricted())
                return targetQueuePermission.Copy();

            if (targetQueuePermission.IsUnrestricted())
                return this.Copy();

            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();
            MessageQueuePermission newPermission = new MessageQueuePermission();
            Hashtable newFormatNames = new Hashtable(GetComparer());
            newPermission.resolvedFormatNames = newFormatNames;
            IDictionaryEnumerator formatNamesEnumerator;
            Hashtable formatNamesTable;
            if (this.resolvedFormatNames.Count < targetQueuePermission.resolvedFormatNames.Count)
            {
                formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
                formatNamesTable = targetQueuePermission.resolvedFormatNames;
            }
            else
            {
                formatNamesEnumerator = targetQueuePermission.resolvedFormatNames.GetEnumerator();
                formatNamesTable = this.resolvedFormatNames;
            }

            while (formatNamesEnumerator.MoveNext())
            {
                if (formatNamesTable.ContainsKey(formatNamesEnumerator.Key))
                {
                    string currentFormatName = (string)formatNamesEnumerator.Key;
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)formatNamesEnumerator.Value;
                    MessageQueuePermissionAccess targetAccess = (MessageQueuePermissionAccess)formatNamesTable[currentFormatName];
                    newFormatNames.Add(currentFormatName, currentAccess & targetAccess);
                }
            }

            return newPermission;
        }
Exemplo n.º 13
0
        /// <include file='doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Copy"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Copy()
        {
            MessageQueuePermission permission = new MessageQueuePermission();
            permission.isUnrestricted = this.isUnrestricted;
            foreach (MessageQueuePermissionEntry entry in this.PermissionEntries)
                permission.PermissionEntries.Add(entry);

            permission.resolvedFormatNames = this.resolvedFormatNames;
            return permission;
        }
Exemplo n.º 14
0
        public override IPermission Union(IPermission target)
        {
            MessageQueuePermission mqp = Cast(target);

            return(null);
        }
 internal MessageQueuePermissionEntryCollection(MessageQueuePermission owner)
 {
     this.owner = owner;
 }
        /// <include file='doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.IsSubsetOf"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(false);
            }

            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));
            }

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;

            if (targetQueuePermission.IsUnrestricted())
            {
                return(true);
            }
            else if (this.IsUnrestricted())
            {
                return(false);
            }

            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();

            //If one of the tables is empty the subset cannot be resolved reliably, should assume
            //then that they are not subset of each other.
            if ((this.resolvedFormatNames.Count == 0 && targetQueuePermission.resolvedFormatNames.Count != 0) ||
                (this.resolvedFormatNames.Count != 0 && targetQueuePermission.resolvedFormatNames.Count == 0))
            {
                return(false);
            }

            //If the target table contains a wild card, all the current formatName access need to be
            //a subset of the target.
            IDictionaryEnumerator formatNamesEnumerator;

            if (targetQueuePermission.resolvedFormatNames.ContainsKey(Any))
            {
                MessageQueuePermissionAccess targetAccess = (MessageQueuePermissionAccess)targetQueuePermission.resolvedFormatNames[Any];
                formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
                while (formatNamesEnumerator.MoveNext())
                {
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)formatNamesEnumerator.Value;
                    if ((currentAccess & targetAccess) != currentAccess)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            //If the current table contains a wild card it can be treated as any other format name.
            formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
            while (formatNamesEnumerator.MoveNext())
            {
                string currentFormatName = (string)formatNamesEnumerator.Key;
                if (!targetQueuePermission.resolvedFormatNames.ContainsKey(currentFormatName))
                {
                    return(false);
                }
                else
                {
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)formatNamesEnumerator.Value;
                    MessageQueuePermissionAccess targetAccess  = (MessageQueuePermissionAccess)targetQueuePermission.resolvedFormatNames[currentFormatName];
                    if ((currentAccess & targetAccess) != currentAccess)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
		internal MessageQueuePermissionEntryCollection (MessageQueuePermission owner)
		{
			this.owner = owner;
		}
Exemplo n.º 18
0
        public override bool IsSubsetOf(IPermission target)
        {
            MessageQueuePermission mqp = Cast(target);

            return(false);
        }