Merge pull request #4540 from kumpera/android-changes-part1
[mono.git] / mcs / class / System.IdentityModel / System.IdentityModel.Tokens / SamlAuthorityBinding.cs
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.
27 //
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;
35
36 namespace System.IdentityModel.Tokens
37 {
38         [DataContract]
39         public class SamlAuthorityBinding
40         {
41                 XmlQualifiedName kind;
42                 string binding, location;
43                 bool is_readonly;
44
45                 public SamlAuthorityBinding ()
46                 {
47                 }
48
49                 public SamlAuthorityBinding (XmlQualifiedName authorityKind, string binding, string location)
50                 {
51                         if (authorityKind == null)
52                                 throw new ArgumentNullException ("authorityKind");
53                         AuthorityKind = authorityKind;
54                         Binding = binding;
55                         Location = location;
56                 }
57
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;
68                         }
69                 }
70
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;
79                         }
80                 }
81
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;
90                         }
91                 }
92
93                 public bool IsReadOnly {
94                         get { return is_readonly; }
95                 }
96
97                 void CheckReadOnly ()
98                 {
99                         if (IsReadOnly)
100                                 throw new InvalidOperationException ("This object is read-only.");
101                 }
102
103                 public void MakeReadOnly ()
104                 {
105                         is_readonly = true;
106                 }
107
108                 [MonoTODO]
109                 public virtual void ReadXml (XmlDictionaryReader reader,
110                         SamlSerializer samlSerializer,
111                         SecurityTokenSerializer keyInfoSerializer,
112                         SecurityTokenResolver outOfBandTokenResolver)
113                 {
114                         throw new NotImplementedException ();
115                 }
116
117                 public virtual void WriteXml (
118                         XmlDictionaryWriter writer,
119                         SamlSerializer samlSerializer,
120                         SecurityTokenSerializer keyInfoSerializer)
121                 {
122                         if (writer == null)
123                                 throw new ArgumentNullException ("writer");
124                         if (samlSerializer == null)
125                                 throw new ArgumentNullException ("samlSerializer");
126
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.");
133
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 ();
140                 }
141         }
142 }