Ejemplo n.º 1
0
        /// <summary>
        ///     Zahteva od PIP komponente dodatne atribute.
        /// </summary>
        /// <param name="attributeDesignator"></param>
        /// <returns></returns>
        public List <AttributeType> RequestForEnvironmentAttribute(AttributeDesignatorType attributeDesignator)
        {
            List <AttributeType> RequestedAttributes = new List <AttributeType>(3);

            /// zahteva od PIP komponente atribute okruzenja
            NetTcpBinding binding = new NetTcpBinding();

            binding.CloseTimeout   = new TimeSpan(0, 10, 0);
            binding.OpenTimeout    = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
            binding.SendTimeout    = new TimeSpan(0, 10, 0);
            string address = "net.tcp://localhost:7000/PipService";

            DomainAttribute EnvironmentAttribute = new DomainAttribute();

            using (PipProxy proxy = new PipProxy(binding, new EndpointAddress(address)))
            {
                EnvironmentAttribute = proxy.RequestEnvironmentAttribute(attributeDesignator.AttributeId);
            }

            AttributeType XacmlAttribute = CreateXacmlAttribute(EnvironmentAttribute);

            RequestedAttributes.Add(XacmlAttribute);
            return(RequestedAttributes);
        }
Ejemplo n.º 2
0
        public static List <AttributeType> RequestBagOfValues(AttributeDesignatorType attributeDesignator, RequestType request)
        {
            List <AttributeType> RequestedAttributes = new List <AttributeType>(3);

            AttributesType[] Attributes = request.Attributes;

            foreach (AttributesType Attribute in Attributes)
            {
                /// provera jednakosti Category atributa
                if (attributeDesignator.Category.Equals(Attribute.Category))
                {
                    AttributeType[] AttributesType = Attribute.Attribute;

                    foreach (AttributeType AttrType in AttributesType)
                    {
                        /// provera jednakosti AttributeId atributa
                        if (attributeDesignator.AttributeId.Equals(AttrType.AttributeId))
                        {
                            AttributeValueType[] AttributeValues = AttrType.AttributeValue;
                            foreach (AttributeValueType AttrValue in AttributeValues)
                            {
                                if (AttrValue.DataType.Equals(attributeDesignator.DataType))
                                {
                                    RequestedAttributes.Add(AttrType);
                                }
                            }
                        }
                    }
                }
            }

            return(RequestedAttributes);
        }
Ejemplo n.º 3
0
        public List <AttributeType> RequestForSubjectAttribute(AttributeDesignatorType attributeDesignator, string subjectId)
        {
            List <AttributeType> RequestedAttributes = new List <AttributeType>(3);

            /// zahteva od PIP komponente atribute okruzenja
            NetTcpBinding binding = new NetTcpBinding();

            binding.CloseTimeout   = new TimeSpan(0, 10, 0);
            binding.OpenTimeout    = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
            binding.SendTimeout    = new TimeSpan(0, 10, 0);
            string address = "net.tcp://localhost:7000/PipService";

            List <DomainAttribute> SubjecttAttributes = new List <DomainAttribute>();

            using (PipProxy proxy = new PipProxy(binding, new EndpointAddress(address)))
            {
                SubjecttAttributes = proxy.RequestSubjectAttributes(attributeDesignator.AttributeId, subjectId);
            }

            foreach (DomainAttribute attribute in SubjecttAttributes)
            {
                AttributeType XacmlAttribute = CreateXacmlAttribute(attribute);
                RequestedAttributes.Add(XacmlAttribute);
            }

            return(RequestedAttributes);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Redosled navodjenja Apply elementa u XACML politici je bitan
        ///     1. Apply koji definise tip (AttributeDesignator element)
        ///     2. Donja granica
        ///     3. Gordnja granica
        /// </summary>
        /// <param name="Item"> ApplyType element - Sadrzi listu Apply elemenata</param>
        /// <param name="request"> Xacml zahtev </param>
        /// <returns></returns>
        public override bool EvaluateConditionFor(ApplyType Item, RequestType request)
        {
            bool TimeConditionResult = true;

            ApplyType currentTimeItem = Item.Items[0] as ApplyType;
            ApplyType lowerBoundItem  = Item.Items[1] as ApplyType;
            ApplyType upperBoundItem  = Item.Items[2] as ApplyType;

            // designator za def DataType, Category, AttributeId
            AttributeDesignatorType attributeDesignator = currentTimeItem.Items[0] as AttributeDesignatorType;

            // lower bound time
            ExpressionType[]   lowItems        = lowerBoundItem.Items;
            ApplyType          lowItem         = lowItems[0] as ApplyType;
            AttributeValueType lowItemValue    = lowItem.Items[0] as AttributeValueType;
            XmlNode            lowItemValueAny = lowItemValue.Any[0] as XmlNode;

            string lowerBoundTime = lowItemValueAny.Value as string;

            // upper bound time
            ExpressionType[]   uppItems        = upperBoundItem.Items;
            ApplyType          uppItem         = uppItems[0] as ApplyType;
            AttributeValueType uppItemValue    = uppItem.Items[0] as AttributeValueType;
            XmlNode            uppItemValueAny = uppItemValue.Any[0] as XmlNode;

            string upperBoundTime = uppItemValueAny.Value as string;

            // konverzija vremena - daylight saving time - +1 na vremensku zonu tako da je srbija na +2 po letnjem racunanju vremena
            // preporuka da se vreme definise u UTC formatu
            DateTime lowerBoundTimeValue = DateTime.Parse(lowerBoundTime, System.Globalization.CultureInfo.CurrentCulture);
            DateTime upperBoundTimeValue = DateTime.Parse(upperBoundTime, System.Globalization.CultureInfo.CurrentCulture);

            bool exists = false;
            List <AttributeType> Attributes = new List <AttributeType>(2);

            Attributes = AttributeDesignatorManager.RequestBagOfValues(attributeDesignator, request);

            if (Attributes.Count == 0)
            {
                // Provera MustBePresented atributa
                if (attributeDesignator.MustBePresent)
                {
                    // PDP zahteva od PIP dobavljanje atributa koji su potrebni
                    ContextHandler ch = new ContextHandler();
                    Attributes = ch.RequestForEnvironmentAttribute(attributeDesignator);
                }
                else
                {
                    return(TimeConditionResult);
                }
            }

            TimeConditionResult = TimeConditionEvaluation(lowerBoundTimeValue, upperBoundTimeValue, Attributes, out exists);

            return(TimeConditionResult);
        }
Ejemplo n.º 5
0
        public static TargetResult CheckTarget(TargetType Target, RequestType request)
        {
            MatchFunctions[XacmlFunctions.STRING_EQUAL] = new StringEqual();

            ContextHandler ch = new ContextHandler();

            int numberOfMatchAnyOf         = 0;
            int numberOfNoMatchAnyOf       = 0;
            int numberOfIndeterminateAnyOf = 0;

            if (Target != null)
            {
                if (Target.AnyOf != null)
                {
                    foreach (AnyOfType AnyOf in Target.AnyOf)
                    {
                        int numberOfMatchAllOf         = 0;
                        int numberOfIndeterminateAllOf = 0;
                        int numberOfNoMatchAllOf       = 0;

                        AllOfType[] AllOfs = AnyOf.AllOf;
                        foreach (AllOfType AllOf in AllOfs)
                        {
                            int numberOfFalseMatch         = 0;
                            int numberOfIndeterminateMatch = 0;

                            MatchType[] Matches = AllOf.Match;
                            try
                            {
                                foreach (MatchType Match in Matches)
                                {
                                    AttributeDesignatorType AttributeDesignator = Match.Item as AttributeDesignatorType;
                                    AttributeValueType      AttributeValue      = Match.AttributeValue;

                                    List <AttributeType> Attributes = AttributeDesignatorManager.RequestBagOfValues(AttributeDesignator, request);

                                    int numberOfMatch = 0;

                                    if (Attributes.Count == 0)
                                    {
                                        // bag of values je prazan, provera atributa MustBePresented
                                        if (AttributeDesignator.MustBePresent)
                                        {
                                            // TODO zahteva dobavljanje atributa od PIP
                                            if (AttributeDesignator.Category.Equals(XacmlSubject.CATEGORY))
                                            {
                                                string subjectId = SubjectIdResolver.SubjectId(request);
                                                if (!(subjectId == null))
                                                {
                                                    Attributes = ch.RequestForSubjectAttribute(AttributeDesignator, subjectId);
                                                }
                                                else
                                                {
                                                    Attributes = null;
                                                }
                                            }
                                            else
                                            {
                                                Attributes = ch.RequestForEnvironmentAttribute(AttributeDesignator);
                                            }

                                            // ako PIP ne vrati atribut - zbog true vrednosti MustBePresented
                                            if (Attributes != null)
                                            {
                                                if (Attributes[0] == null)
                                                {
                                                    numberOfIndeterminateMatch++;
                                                    continue;
                                                }
                                            }
                                            else
                                            {
                                                numberOfIndeterminateMatch++;
                                                continue;
                                            }
                                            if (Attributes.Count == 0)
                                            {
                                                numberOfIndeterminateMatch++;
                                                continue;
                                            }
                                        }
                                    }
                                    string attributeValue = string.Empty;

                                    foreach (AttributeType attr in Attributes)
                                    {
                                        AttributeValueType[] attrValues = attr.AttributeValue;
                                        foreach (AttributeValueType attrValue in attrValues)
                                        {
                                            XmlNode node = attrValue.Any[0];
                                            attributeValue = node.Value;
                                        }
                                        string value = AttributeValue.Any[0].Value.ToString();

                                        // evaluacija prema funkciji definisanoj MatchId atributom
                                        bool decision = MatchFunctions[Match.MatchId].CheckIfMatch(ref value, ref attributeValue);

                                        if (decision)
                                        {
                                            numberOfMatch++;
                                        }
                                    }

                                    if (numberOfMatch == 0)
                                    {
                                        numberOfFalseMatch++;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                numberOfIndeterminateMatch++;
                            }

                            /// AllOf evaluacija
                            if (numberOfFalseMatch != 0)
                            {
                                numberOfNoMatchAllOf++;
                            }
                            else if (numberOfIndeterminateMatch > 0)
                            {
                                numberOfIndeterminateAllOf++;
                            }
                            else if (numberOfFalseMatch == 0 && numberOfIndeterminateMatch == 0)
                            {
                                numberOfMatchAllOf++;
                            }
                        }

                        /// AnyOf evaluacija
                        if (numberOfIndeterminateAllOf > 0 && numberOfMatchAllOf == 0)
                        {
                            numberOfIndeterminateAnyOf++;
                        }
                        else if (numberOfMatchAllOf > 0)
                        {
                            numberOfMatchAnyOf++;
                        }
                        else if (numberOfNoMatchAllOf > 0)
                        {
                            numberOfNoMatchAnyOf++;
                        }
                    }
                }
                else
                {
                    // empty target
                    return(TargetResult.Match);
                }
            }
            else
            {
                // empty target
                return(TargetResult.Match);
            }

            if (numberOfNoMatchAnyOf > 0)
            {
                return(TargetResult.NoMatch);
            }
            else if (numberOfMatchAnyOf > 0 && numberOfIndeterminateAnyOf == 0)
            {
                return(TargetResult.Match);
            }
            else
            {
                return(TargetResult.Indeterminate);
            }
        }