コード例 #1
0
        public static void XacmlResponseAssert(XacmlContextResponse responseData, XacmlContextResponse evaluatedResponse) {
            var responseResults = responseData.Results.ToList();
            var evaluationResults = evaluatedResponse.Results.ToList();

            Assert.AreEqual(responseResults.Count, evaluationResults.Count, "Results count mismatch");

            for (int i = 0; i < responseResults.Count; i++) {
                Assert.AreEqual(responseResults[i].ResourceId, evaluationResults[i].ResourceId);
                Assert.AreEqual(responseResults[i].Decision, evaluationResults[i].Decision, evaluationResults[i].Status.StatusMessage);
                // UNDONE: Assert.AreEqual(responseResults[i].Status.StatusCode.Value, evaluationResults[i].Status.StatusCode.Value);

                Assert.AreEqual(responseResults[i].Attributes.Count, evaluationResults[i].Attributes.Count, "Attributes count mismatch");
                foreach (var responseAttribute in responseResults[i].Attributes) {
                    var evaluateAttribute = evaluationResults[i].Attributes.First(a => a.Category == responseAttribute.Category);
                    Assert.AreEqual(responseAttribute.Attributes.Count, evaluateAttribute.Attributes.Count);
                }

                Assert.AreEqual(responseResults[i].Obligations.Count, evaluationResults[i].Obligations.Count, "Obligations count mismatch");
                Assert.AreEqual(responseResults[i].Advices.Count, evaluationResults[i].Advices.Count, "Advices count mismatch");

                Assert.AreEqual(responseResults[i].PolicyIdReferences.Count, evaluationResults[i].PolicyIdReferences.Count, "PolicyIdentifierList - Policy count mismatch");
                Assert.AreEqual(responseResults[i].PolicySetIdReferences.Count, evaluationResults[i].PolicySetIdReferences.Count, "PolicyIdentifierList - PolicySet count mismatch");
            }
        }
コード例 #2
0
        public void WriteResponse_11()
        {
            var response = new XacmlContextResponse(new XacmlContextResult(XacmlContextDecision.NotApplicable, new XacmlContextStatus(XacmlContextStatusCode.Success)));

            StringBuilder builder = new StringBuilder();
            using (XmlWriter writer = XmlWriter.Create(builder))
            {
                var serializer = new Xacml11ProtocolSerializer();
                serializer.WriteContextResponse(writer, response);
            }

            string xml = builder.ToString();
            ValidateMessage(xml, @"..\..\_Data\cs-xacml-schema-context-01.xsd");
        }
コード例 #3
0
        public virtual XacmlContextResponse ReadContextResponse(XmlReader reader) {
            Contract.Requires<ArgumentNullException>(reader != null, "reader");

            if (!XacmlProtocolSerializer.CanReadContext(reader, XacmlConstants.ElementNames.Response, this.version.NamespaceContext)) {
                throw Diagnostic.DiagnosticTools.ExceptionUtil.ThrowHelperError(new InvalidOperationException());
            }

            reader.ReadStartElement(XacmlConstants.ElementNames.Response, this.version.NamespaceContext);

            List<XacmlContextResult> results = new List<XacmlContextResult>();
            this.ReadList(results, XacmlConstants.ElementNames.Result, this.version.NamespaceContext, ReadContextResult, reader, isRequired: true);

            XacmlContextResponse result = new XacmlContextResponse(results);

            reader.ReadEndElement();

            return result;
        }
コード例 #4
0
        /// <summary>
        /// public void WriteResponse
        /// </summary>
        /// <param name="writer">XmlWriter writer</param>
        /// <param name="data">XacmlContextResponse data</param>
        public virtual void WriteContextResponse(XmlWriter writer, XacmlContextResponse data) {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(data != null);

            writer.WriteStartElement(XacmlConstants.Prefixes.Context, XacmlConstants.ElementNames.Response, this.version.NamespaceContext);

            // Results

            if (data.Results.Count == 0) {
                throw Diagnostic.DiagnosticTools.ExceptionUtil.ThrowHelperError(new XacmlSerializationException("Results is empty"));
            }

            foreach (var result in data.Results) {
                this.WriteContextResult(writer, result);
            }

            writer.WriteEndElement();
        }