public void WritePolicy_20() {
            var subject = new XacmlSubject(
                new XacmlSubjectMatch[] 
                {  
                    new XacmlSubjectMatch(
                        new Uri("http://www.MatchId.www"),
                        new XacmlAttributeValue(new Uri("http://www.DataType.www")), 
                        new XacmlSubjectAttributeDesignator(new Uri("http://www.AttributeId.www"), new Uri("http://www.DataType.www")) { Issuer = "String", MustBePresent = false, Category = new Uri("http://www.subjectCategory.www")}
                        )
                });

            var resource = new XacmlResource(
            new XacmlResourceMatch[] 
                { 
                    new XacmlResourceMatch(
                        new Uri("http://www.MatchId.www"), 
                        new XacmlAttributeValue(new Uri("http://www.DataType.www") /*, "xxxx" */), 
                        new XacmlResourceAttributeDesignator(new Uri("http://www.AttributeId.www"), new Uri("http://www.DataType.www")) { Issuer = "String", MustBePresent = false} 
                        )
                });

            var action = new XacmlAction(
                new XacmlActionMatch[] 
                { 
                    new XacmlActionMatch(
                        new Uri("http://www.MatchId.www"), 
                        new XacmlAttributeValue(new Uri("http://www.DataType.www")), 
                        new XacmlActionAttributeDesignator(new Uri("http://www.AttributeId.www"), new Uri("http://www.DataType.www")){ Issuer = "String", MustBePresent = false} 
                        )
                });

            var target = new XacmlTarget(subject, resource, action, null);

            // new Uri("http://www.PolicySetId.www")
            XacmlPolicySet xacmlPolicySet = new XacmlPolicySet(new Uri("http://www.PolicyCombiningAlgId.www"), target) {
                Description = "description string",
                XPathVersion = Xacml10Constants.XPathVersions.Xpath10,
            };
            
            ////#region Policy
            XacmlEnvironment env = new XacmlEnvironment(
                new XacmlEnvironmentMatch[]
                {
                    new XacmlEnvironmentMatch(
                        new Uri("http://www.EnvironmentMatchIdId.www"), 
                        new XacmlAttributeValue(new Uri("http://www.AttributValue.www")), 
                        new XacmlEnvironmentAttributeDesignator(new Uri("http://www.AttributeId.www"), new Uri("http://www.DataType.www")){ Issuer = "String", MustBePresent = false} 
                        )
                });

            XacmlTarget targetWithEnvironment = new XacmlTarget(null, null, null, new XacmlEnvironment[] { env });

            XacmlPolicy xacmlPolicy = new XacmlPolicy(new Uri("http://www.PolicyId.www"), new Uri("http://www.RuleCombiningAlgId.www"), targetWithEnvironment) {
                Description = "description string",
                XPathVersion = Xacml10Constants.XPathVersions.Xpath10,
            };

            XacmlRule xacmlRule = new XacmlRule("http://www.RuleId.www", XacmlEffectType.Permit) {
                Description = "xacmlRule description"
            };

            xacmlPolicy.Rules.Add(xacmlRule);

            XacmlAttributeAssignment xacmlAttributeAssignment = new XacmlAttributeAssignment(new Uri("http://www.AttributeId.www"), new Uri("http://www.DataType.www"));
            XacmlObligation xacmlObligation = new XacmlObligation(new Uri("http://www.ObligationId.www"), XacmlEffectType.Permit, new XacmlAttributeAssignment[] { xacmlAttributeAssignment });
            xacmlPolicy.Obligations.Add(xacmlObligation);

            xacmlPolicySet.Policies.Add(xacmlPolicy);

            StringBuilder builder = new StringBuilder();
            using (XmlWriter writer = XmlWriter.Create(builder)) {
                var serializer = new Xacml20ProtocolSerializer();
                serializer.WritePolicySet(writer, xacmlPolicySet);
            }

            string xml = builder.ToString();
            ValidateMessage(xml, @"..\..\_Data\access_control-xacml-2.0-policy-schema-os.xsd");
        }
        /// <summary>
        /// Reads the action.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        /// <exception cref="System.Xml.XmlException">Action NotStartElement</exception>
        protected virtual XacmlAction ReadAction(XmlReader reader) {
            Contract.Requires<ArgumentNullException>(reader != null, "reader");

            if (!reader.IsStartElement(XacmlConstants.ElementNames.Action, this.version.NamespacePolicy)) {
                throw Diagnostic.DiagnosticTools.ExceptionUtil.ThrowHelperError(new XmlException("Action NotStartElement"));
            }

            reader.ReadStartElement(XacmlConstants.ElementNames.Action, this.version.NamespacePolicy);

            List<XacmlActionMatch> matches = new List<XacmlActionMatch>();

            this.ReadListAbstract(matches, XacmlConstants.ElementNames.ActionMatch, this.version.NamespacePolicy, ReadMatch, reader, true);

            XacmlAction act = new XacmlAction(matches);

            reader.ReadEndElement();
            return act;
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XacmlTarget" /> class.
 /// </summary>
 /// <param name="subject">The subject.</param>
 /// <param name="resource">The resource.</param>
 /// <param name="action">The action.</param>
 /// <param name="environment">The environment.</param>
 /// <remarks>
 /// Used only from XACML 2.0
 /// </remarks>
 public XacmlTarget(XacmlSubject subject, XacmlResource resource, XacmlAction action, XacmlEnvironment environment)
     : this(subject != null ? new XacmlSubject[] { subject } : null, resource != null ? new XacmlResource[] { resource } : null, action != null ? new XacmlAction[] { action } : null, environment != null ? new XacmlEnvironment[] { environment } : null)
 {
 }
        /// <summary>
        /// protected virtual void WriteAction
        /// </summary>
        /// <param name="writer">XmlWriter writer</param>
        /// <param name="data">XacmlAction data</param>
        protected virtual void WriteAction(XmlWriter writer, XacmlAction data) {
            Contract.Requires<ArgumentNullException>(writer != null);
            Contract.Requires<ArgumentNullException>(data != null);

            writer.WriteStartElement(XacmlConstants.Prefixes.Policy, XacmlConstants.ElementNames.Action, this.version.NamespacePolicy);

            foreach (var actionMatch in data.Matches) {
                writer.WriteAttributeString(XacmlConstants.AttributeNames.MatchId, actionMatch.MatchId.OriginalString);

                writer.WriteStartElement(XacmlConstants.Prefixes.Policy, XacmlConstants.ElementNames.AttributeValue, this.version.NamespacePolicy);
                writer.WriteAttributeString(XacmlConstants.AttributeNames.DataType, actionMatch.AttributeValue.DataType.OriginalString);
                //// writer.WriteString("Text");
                writer.WriteEndElement();
            }
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XacmlTarget"/> class.
 /// </summary>
 /// <param name="subject">The subject.</param>
 /// <param name="resource">The resource.</param>
 /// <param name="action">The action.</param>
 /// <param name="environment">The environment.</param>
 /// <remarks>
 /// Used only from XACML 1.0/1.1/2.0
 /// </remarks>
 public XacmlTarget(XacmlSubject subject, XacmlResource resource, XacmlAction action)
     : this(subject != null ? new XacmlSubject[] { subject } : null, resource != null ? new XacmlResource[] { resource } : null, action != null ? new XacmlAction[] { action } : null, null)
 {
 }