Exemple #1
0
 protected override void ValidateRights(IEnumerable <AccessRights> value)
 {
     base.ValidateRights(value);
     if (!SharedAccessAuthorizationRule.IsValidCombinationOfRights(value))
     {
         throw new ArgumentException(SRClient.InvalidCombinationOfManageRight);
     }
 }
Exemple #2
0
        public override bool Equals(object obj)
        {
            if (!base.Equals(obj))
            {
                return(false);
            }
            SharedAccessAuthorizationRule sharedAccessAuthorizationRule = (SharedAccessAuthorizationRule)obj;

            if (!string.Equals(this.KeyName, sharedAccessAuthorizationRule.KeyName, StringComparison.OrdinalIgnoreCase) || !string.Equals(this.PrimaryKey, sharedAccessAuthorizationRule.PrimaryKey, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            return(string.Equals(this.SecondaryKey, sharedAccessAuthorizationRule.SecondaryKey, StringComparison.OrdinalIgnoreCase));
        }
        public void Add(AuthorizationRule item)
        {
            SharedAccessAuthorizationRule sharedAccessAuthorizationRule;

            if (item is SharedAccessAuthorizationRule)
            {
                SharedAccessAuthorizationRule sharedAccessAuthorizationRule1 = item as SharedAccessAuthorizationRule;
                if (this.nameToSharedAccessAuthorizationRuleMap.TryGetValue(sharedAccessAuthorizationRule1.KeyName, out sharedAccessAuthorizationRule))
                {
                    this.nameToSharedAccessAuthorizationRuleMap.Remove(sharedAccessAuthorizationRule1.KeyName);
                    this.innerCollection.Remove(sharedAccessAuthorizationRule);
                    this.duplicateAddForSharedAccessAuthorizationRule = true;
                }
                this.nameToSharedAccessAuthorizationRuleMap.Add(sharedAccessAuthorizationRule1.KeyName, sharedAccessAuthorizationRule1);
            }
            this.innerCollection.Add(item);
        }
Exemple #4
0
 protected override void OnValidate()
 {
     if (string.IsNullOrEmpty(this.InternalKeyName) || !string.Equals(this.InternalKeyName, HttpUtility.UrlEncode(this.InternalKeyName)))
     {
         throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyContainsInvalidCharacters);
     }
     if (this.InternalKeyName.Length > 256)
     {
         throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleKeyNameTooBig(256));
     }
     if (string.IsNullOrEmpty(this.InternalPrimaryKey))
     {
         throw new InvalidDataContractException(SRCore.SharedAccessAuthorizationRuleRequiresPrimaryKey);
     }
     if (Encoding.ASCII.GetByteCount(this.InternalPrimaryKey) != 44)
     {
         throw new InvalidDataContractException(SRCore.SharedAccessRuleAllowsFixedLengthKeys(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(44));
         }
         if (!SharedAccessAuthorizationRule.CheckBase64(this.InternalSecondaryKey))
         {
             throw new InvalidDataContractException(SRCore.SharedAccessKeyShouldbeBase64);
         }
     }
     if (!SharedAccessAuthorizationRule.IsValidCombinationOfRights(base.Rights))
     {
         throw new InvalidDataContractException(SRClient.InvalidCombinationOfManageRight);
     }
 }
 public bool TryGetSharedAccessAuthorizationRule(string keyName, out SharedAccessAuthorizationRule rule)
 {
     return(this.nameToSharedAccessAuthorizationRuleMap.TryGetValue(keyName, out rule));
 }
Exemple #6
0
 public SharedAccessAuthorizationRule(string keyName, string primaryKey, IEnumerable <AccessRights> rights) : this(keyName, primaryKey, SharedAccessAuthorizationRule.GenerateRandomKey(), rights)
 {
 }