5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.Collections.Generic;
29 using System.Collections.ObjectModel;
30 using System.Runtime.Serialization;
31 using System.IdentityModel.Claims;
32 using System.IdentityModel.Selectors;
35 namespace System.IdentityModel.Tokens
37 public class SamlSubject
39 public static string NameClaimType {
40 get { return ClaimTypes.Name; }
44 string name_format, name_qualifier, name;
46 SecurityKeyIdentifier key_identifier;
47 List<string> confirmation_methods;
48 string confirmation_data;
54 public SamlSubject (string nameFormat, string nameQualifier, string name)
55 : this (nameFormat, nameQualifier, name, new string [0], null, null)
59 public SamlSubject (string nameFormat, string nameQualifier, string name, IEnumerable<string> confirmations, string confirmationData, SecurityKeyIdentifier securityKeyIdentifier)
61 if (name == null || name.Length == 0)
62 throw new ArgumentException ("non-zero length string must be specified for name of SAML Subject.");
63 name_format = nameFormat;
64 name_qualifier = nameQualifier;
67 confirmation_methods = new List<string> (confirmations);
68 confirmation_data = confirmationData;
69 key_identifier = securityKeyIdentifier;
72 public bool IsReadOnly {
73 get { return is_readonly; }
76 public string NameFormat {
77 get { return name_format; }
84 public string NameQualifier {
85 get { return name_qualifier; }
88 name_qualifier = value;
96 if (value == null || value.Length == 0)
97 throw new ArgumentException ("non-zero length string must be specified for name of SAML Subject.");
102 public IList<string> ConfirmationMethods {
103 get { return confirmation_methods; }
106 public string SubjectConfirmationData {
107 get { return confirmation_data; }
110 confirmation_data = value;
114 public SecurityKey Crypto {
115 get { return crypto; }
122 public SecurityKeyIdentifier KeyIdentifier {
123 get { return key_identifier; }
126 key_identifier = value;
130 private void CheckReadOnly ()
133 throw new InvalidOperationException ("This SAML subject is read-only.");
136 public void MakeReadOnly ()
142 public virtual ReadOnlyCollection<Claim> ExtractClaims ()
144 throw new NotImplementedException ();
148 public virtual ClaimSet ExtractSubjectKeyClaimSet (
149 SamlSecurityTokenAuthenticator samlAuthenticator)
151 throw new NotImplementedException ();
154 public virtual void ReadXml (XmlDictionaryReader reader,
155 SamlSerializer samlSerializer,
156 SecurityTokenSerializer keyInfoTokenSerializer,
157 SecurityTokenResolver outOfBandTokenResolver)
160 throw new ArgumentNullException ("reader");
161 if (samlSerializer == null)
162 throw new ArgumentNullException ("samlSerializer");
164 reader.ReadStartElement ("Subject", SamlConstants.Namespace);
165 NameFormat = reader.GetAttribute ("Format");
166 NameQualifier = reader.GetAttribute ("NameQualifier");
167 Name = reader.ReadElementContentAsString ("NameIdentifier", SamlConstants.Namespace);
168 reader.ReadEndElement ();
170 if (Name == null || Name.Length == 0)
171 throw new SecurityTokenException ("non-zero length string must be exist for Name.");
174 public virtual void WriteXml (XmlDictionaryWriter writer,
175 SamlSerializer samlSerializer,
176 SecurityTokenSerializer keyInfoTokenSerializer)
179 throw new ArgumentNullException ("writer");
180 if (samlSerializer == null)
181 throw new ArgumentNullException ("samlSerializer");
183 if (Name == null || Name.Length == 0)
184 throw new SecurityTokenException ("non-zero length string must be set to Name of SAML Subject before being written.");
186 writer.WriteStartElement ("saml", "Subject", SamlConstants.Namespace);
187 writer.WriteStartElement ("saml", "NameIdentifier", SamlConstants.Namespace);
188 writer.WriteAttributeString ("Format", NameFormat);
189 writer.WriteAttributeString ("NameQualifier", NameQualifier);
190 writer.WriteString (Name);
191 writer.WriteEndElement ();
192 writer.WriteEndElement ();