예제 #1
0
        protected Restriction(AuthorizationDataType actualType, AuthorizationDataType expectedType)
        {
            if (actualType != expectedType)
            {
                throw new InvalidOperationException($"Cannot create {expectedType} because actual type is {actualType}");
            }

            Type = actualType;
        }
예제 #2
0
        private static void AddRestrictionType(
            Dictionary <AuthorizationDataType, IEnumerable <AuthorizationDataElement> > dictionary,
            AuthorizationDataType adType,
            IEnumerable <AuthorizationDataElement> elementsToAdd
            )
        {
            var elements = new List <AuthorizationDataElement>();

            if (dictionary.TryGetValue(adType, out IEnumerable <AuthorizationDataElement> existingElements))
            {
                elements = existingElements.Union(elementsToAdd).ToList();
            }
            else
            {
                elements = elementsToAdd.ToList();
            }

            dictionary[adType] = elements;
        }
예제 #3
0
        public static IEnumerable <AuthorizationData> ParseElements(Asn1Element authData)
        {
            var dictionary = new Dictionary <AuthorizationDataType, IEnumerable <AuthorizationDataElement> >();

            AuthorizationDataType adType = 0;

            for (var i = 0; i < authData.Count; i++)
            {
                var authDataElement = authData[i];

                switch (authDataElement.ContextSpecificTag)
                {
                case 0:
                    adType = (AuthorizationDataType)authDataElement[0].AsLong();
                    break;

                case 1:
                    switch (adType)
                    {
                    case AuthorizationDataType.AdIfRelevant:
                        var relevant = authDataElement.AsEncapsulatedElement();

                        for (var r = 0; r < relevant.Count; r++)
                        {
                            AddRestrictionType(dictionary, adType, ExtractRestrictions(relevant[r]));
                        }
                        break;

                    default:
                        Debug.WriteLine($"Unknown AdType: {adType}");
                        break;
                    }

                    break;
                }
            }

            return(dictionary.Select(kv => new AuthorizationData(kv.Key, kv.Value)));
        }
예제 #4
0
        private static IEnumerable <T> AssertAllAreRestrictionType <T>(KerberosIdentity identity, AuthorizationDataType type, int expectedCount)
            where T : Restriction
        {
            if (identity.Restrictions.TryGetValue(type, out IEnumerable <Restriction> restrictions))
            {
                Assert.IsNotNull(restrictions);
            }

            Assert.AreEqual(expectedCount, restrictions.Count());

            var typedRestrictions = restrictions.Select(r => r as T).Where(r => r != null);

            Assert.AreEqual(expectedCount, typedRestrictions.Count());

            return(typedRestrictions);
        }
예제 #5
0
 public AuthorizationData(AuthorizationDataType key, IEnumerable <AuthorizationDataElement> value)
 {
     Type           = key;
     authorizations = value.ToList();
 }