2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.IdentityModel / System.IdentityModel.Tokens / SamlAuthorityBinding.cs
blob8949c160ee1bd103cdc6267460f18d5e5bef366e
1 //
2 // SamlAuthorityBinding.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.Xml;
31 using System.Runtime.Serialization;
32 using System.IdentityModel.Claims;
33 using System.IdentityModel.Policy;
34 using System.IdentityModel.Selectors;
36 namespace System.IdentityModel.Tokens
38 [DataContract]
39 public class SamlAuthorityBinding
41 XmlQualifiedName kind;
42 string binding, location;
43 bool is_readonly;
45 public SamlAuthorityBinding ()
49 public SamlAuthorityBinding (XmlQualifiedName kind, string binding, string location)
51 if (kind == null)
52 throw new ArgumentNullException ("kind");
53 AuthorityKind = kind;
54 Binding = binding;
55 Location = location;
58 [DataMember]
59 public XmlQualifiedName AuthorityKind {
60 get { return kind; }
61 set {
62 CheckReadOnly ();
63 if (value == null)
64 throw new ArgumentNullException ("value");
65 if (value.Equals (XmlQualifiedName.Empty))
66 throw new ArgumentException ("non-empty XmlQualifiedName must be set to AuthorityKind of SamlAuthorityBinding.");
67 kind = value;
71 [DataMember]
72 public string Binding {
73 get { return binding; }
74 set {
75 CheckReadOnly ();
76 if (value == null || value.Length == 0)
77 throw new ArgumentException ("non-zero length string must be set to Binding of SamlAuthorityBinding.");
78 binding = value;
82 [DataMember]
83 public string Location {
84 get { return location; }
85 set {
86 CheckReadOnly ();
87 if (value == null || value.Length == 0)
88 throw new ArgumentException ("non-zero length string must be set to Location of SamlAuthorityBinding.");
89 location = value;
93 public bool IsReadOnly {
94 get { return is_readonly; }
97 void CheckReadOnly ()
99 if (IsReadOnly)
100 throw new InvalidOperationException ("This object is read-only.");
103 public void MakeReadOnly ()
105 is_readonly = true;
108 [MonoTODO]
109 public virtual void ReadXml (XmlDictionaryReader reader,
110 SamlSerializer samlSerializer,
111 SecurityTokenSerializer keyInfoSerializer,
112 SecurityTokenResolver outOfBandTokenResolver)
114 throw new NotImplementedException ();
117 public virtual void WriteXml (
118 XmlDictionaryWriter writer,
119 SamlSerializer samlSerializer,
120 SecurityTokenSerializer keyInfoSerializer)
122 if (writer == null)
123 throw new ArgumentNullException ("writer");
124 if (samlSerializer == null)
125 throw new ArgumentNullException ("samlSerializer");
127 if (AuthorityKind == null)
128 throw new SecurityTokenException ("AuthorityKind must be set to SAML AuthorityBinding before being written.");
129 if (Binding == null)
130 throw new SecurityTokenException ("non-zero length Binding must be set to SAML AuthorityBinding before being written.");
131 if (Location == null)
132 throw new SecurityTokenException ("non-zero length Location must be set to SAML AuthorityBinding before being written.");
134 writer.WriteStartElement ("saml", "AuthorityBinding", SamlConstants.Namespace);
135 writer.WriteXmlnsAttribute (String.Empty, AuthorityKind.Namespace);
136 writer.WriteAttributeString ("AuthorityKind", AuthorityKind.Name);
137 writer.WriteAttributeString ("Location", Location);
138 writer.WriteAttributeString ("Binding", Binding);
139 writer.WriteEndElement ();