コード例 #1
0
        /// <summary>
        /// Checks the validity of the specified access rights.
        /// </summary>
        /// <param name="value">
        /// The access rights to check.
        /// </param>
        protected override void ValidateRights(IEnumerable <AccessRights> value)
        {
            base.ValidateRights(value);

            if (!SharedAccessAuthorizationRule.IsValidCombinationOfRights(value))
            {
                throw new ArgumentException(SRClient.InvalidCombinationOfManageRight);
            }
        }
コード例 #2
0
        /// <summary>
        /// Determines whether the specified object is equal to the current object.
        /// </summary>
        ///
        /// <returns>
        /// true if the specified object is equal to the current object; otherwise, false.
        /// </returns>
        /// <param name="obj">The object to compare with the current object.</param>
        public override bool Equals(Object obj)
        {
            if (!base.Equals(obj))
            {
                return(false);
            }

            SharedAccessAuthorizationRule comparand = (SharedAccessAuthorizationRule)obj;

            return(string.Equals(this.KeyName, comparand.KeyName, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(this.PrimaryKey, comparand.PrimaryKey, StringComparison.OrdinalIgnoreCase) &&
                   string.Equals(this.SecondaryKey, comparand.SecondaryKey, StringComparison.OrdinalIgnoreCase));
        }
コード例 #3
0
        /// <summary>
        /// Checks the validity of the authorization rule.
        /// </summary>
        protected override void OnValidate()
        {
            if (string.IsNullOrEmpty(this.InternalKeyName) || !string.Equals(this.InternalKeyName, Auth.SharedAccessSignatureBuilder.UrlEncode(this.InternalKeyName)))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyContainsInvalidCharacters);
            }

            if (this.InternalKeyName.Length > 256)
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyNameTooBig((object)256));
            }
            if (string.IsNullOrEmpty(this.InternalPrimaryKey))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleRequiresPrimaryKey);
            }

            if (Encoding.ASCII.GetByteCount(this.InternalPrimaryKey) != 44)
            {
                throw new InvalidDataContractException(SRCore.SharedAccessRuleAllowsFixedLengthKeys((object)44));
            }

            if (!SharedAccessAuthorizationRule.CheckBase64(this.InternalPrimaryKey))
            {
                throw new InvalidDataContractException(SRCore.SharedAccessKeyShouldbeBase64);
            }

            if (!string.IsNullOrEmpty(this.InternalSecondaryKey))
            {
                if (Encoding.ASCII.GetByteCount(this.InternalSecondaryKey) != 44)
                {
                    throw new InvalidDataContractException(SRCore.SharedAccessRuleAllowsFixedLengthKeys((object)44));
                }
                if (!SharedAccessAuthorizationRule.CheckBase64(this.InternalSecondaryKey))
                {
                    throw new InvalidDataContractException(SRCore.SharedAccessKeyShouldbeBase64);
                }
            }

            if (!SharedAccessAuthorizationRule.IsValidCombinationOfRights(this.Rights))
            {
                throw new InvalidDataContractException(SRClient.InvalidCombinationOfManageRight);
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Microsoft.Azure.NotificationHubs.Messaging.SharedAccessAuthorizationRule" /> class.
 /// </summary>
 /// <param name="keyName">The authorization rule key name.</param>
 /// <param name="primaryKey">The primary key for the authorization rule.</param>
 /// <param name="rights">The list of rights.</param>
 public SharedAccessAuthorizationRule(string keyName, string primaryKey, IEnumerable <AccessRights> rights)
     : this(keyName, primaryKey, SharedAccessAuthorizationRule.GenerateRandomKey(), rights)
 {
 }
コード例 #5
0
 /// <summary>
 /// Gets the rule associated with the specified key.
 /// </summary>
 ///
 /// <returns>
 /// true if the <see cref="T:Microsoft.Azure.NotificationHubs.Messaging.AuthorizationRules"/> contains an element with the specified key; otherwise, false.
 /// </returns>
 /// <param name="keyName">The name of the key.</param><param name="rule">The rule associated with the specified key.</param>
 public bool TryGetSharedAccessAuthorizationRule(string keyName, out SharedAccessAuthorizationRule rule)
 {
     return(this.nameToSharedAccessAuthorizationRuleMap.TryGetValue(keyName, out rule));
 }