2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.IdentityModel / System.IdentityModel.Tokens / SamlConditions.cs
blobe4e956844821b4d60c059a3d08520045149ec94f
1 //
2 // SamlConditions.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.Collections.Generic;
30 using System.Globalization;
31 using System.Xml;
32 using System.IdentityModel.Policy;
33 using System.IdentityModel.Selectors;
34 using System.Security.Cryptography;
36 namespace System.IdentityModel.Tokens
38 public class SamlConditions
40 DateTime not_before = DateTime.SpecifyKind (DateTime.MinValue.AddDays (1), DateTimeKind.Utc);
41 DateTime not_on_after = DateTime.SpecifyKind (DateTime.MaxValue.AddDays (-1), DateTimeKind.Utc);
42 bool is_readonly, has_not_before, has_not_on_after;
43 List<SamlCondition> conditions = new List<SamlCondition> ();
45 public SamlConditions ()
49 public SamlConditions (DateTime notBefore, DateTime notOnOrAfter)
51 this.NotBefore = notBefore;
52 this.NotOnOrAfter = notOnOrAfter;
55 public SamlConditions (DateTime notBefore, DateTime notOnOrAfter,
56 IEnumerable<SamlCondition> conditions)
57 : this (notBefore, notOnOrAfter)
59 if (conditions != null) {
60 foreach (SamlCondition cond in conditions)
61 this.conditions.Add (cond);
65 public IList<SamlCondition> Conditions {
66 get { return conditions; }
69 public DateTime NotBefore {
70 get { return not_before; }
71 set {
72 CheckReadOnly ();
73 not_before = value;
74 has_not_before = true;
78 public DateTime NotOnOrAfter {
79 get { return not_on_after; }
80 set {
81 CheckReadOnly ();
82 not_on_after = value;
83 has_not_on_after = true;
87 public bool IsReadOnly {
88 get { return is_readonly; }
91 private void CheckReadOnly ()
93 if (is_readonly)
94 throw new InvalidOperationException ("This SAML 'Conditions' is read-only.");
97 public void MakeReadOnly ()
99 is_readonly = true;
102 [MonoTODO]
103 public virtual void ReadXml (XmlDictionaryReader reader,
104 SamlSerializer samlSerializer,
105 SecurityTokenSerializer keyInfoTokenSerializer,
106 SecurityTokenResolver outOfBandTokenResolver)
108 throw new NotImplementedException ();
111 public virtual void WriteXml (XmlDictionaryWriter writer,
112 SamlSerializer samlSerializer,
113 SecurityTokenSerializer keyInfoTokenSerializer)
115 if (writer == null)
116 throw new ArgumentNullException ("writer");
117 if (samlSerializer == null)
118 throw new ArgumentNullException ("samlSerializer");
119 writer.WriteStartElement ("saml", "Conditions", SamlConstants.Namespace);
120 CultureInfo invariant = CultureInfo.InvariantCulture;
121 if (has_not_before)
122 writer.WriteAttributeString ("NotBefore", NotBefore.ToString (SamlConstants.DateFormat, invariant));
123 if (has_not_on_after)
124 writer.WriteAttributeString ("NotOnOrAfter", NotOnOrAfter.ToString (SamlConstants.DateFormat, invariant));
125 foreach (SamlCondition cond in Conditions)
126 cond.WriteXml (writer, samlSerializer, keyInfoTokenSerializer);
127 writer.WriteEndElement ();