5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005-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.
29 using System
.Collections
.Generic
;
30 using System
.Collections
.ObjectModel
;
32 using System
.IdentityModel
.Claims
;
33 using System
.IdentityModel
.Selectors
;
35 namespace System
.IdentityModel
.Tokens
37 public class SamlAttribute
41 List
<string> attribute_values
;
43 public SamlAttribute ()
45 attribute_values
= new List
<string> ();
48 public SamlAttribute (Claim claim
)
51 throw new ArgumentNullException ("claim");
52 if (claim
.ClaimType
== null)
53 throw new ArgumentException ("Claim type is null.");
54 int idx
= claim
.ClaimType
.LastIndexOf ('/');
55 if (idx
<= 0 || idx
== claim
.ClaimType
.Length
- 1)
56 throw new ArgumentException ("Claim type does not contain '/' or it is at improper position.");
57 name
= claim
.ClaimType
.Substring (idx
+ 1);
58 ns
= claim
.ClaimType
.Substring (0, idx
);
60 if (claim
.Resource
!= null && !(claim
.Resource
is string))
61 throw new ArgumentException ("Claim resource is not a string.");
63 attribute_values
= new List
<string> ();
64 attribute_values
.Add ((string) claim
.Resource
);
66 if (claim
.Right
!= Rights
.PossessProperty
)
67 throw new ArgumentException ("Claim right is not PossessProperty");
70 public SamlAttribute (string attributeNamespace
,
72 IEnumerable
<string> attributeValues
)
74 ns
= attributeNamespace
;
76 attribute_values
= new List
<string> (attributeValues
);
79 public IList
<string> AttributeValues
{
80 get { return attribute_values; }
91 public string Namespace
{
99 public bool IsReadOnly
{
100 get { return is_readonly; }
103 private void CheckReadOnly ()
106 throw new InvalidOperationException ("This SAML assertion is read-only.");
109 public void MakeReadOnly ()
115 public virtual void ReadXml (XmlDictionaryReader reader
,
116 SamlSerializer samlSerializer
,
117 SecurityTokenSerializer keyInfoTokenSerializer
,
118 SecurityTokenResolver outOfBandTokenResolver
)
120 throw new NotImplementedException ();
123 public virtual void WriteXml (XmlDictionaryWriter writer
,
124 SamlSerializer samlSerializer
,
125 SecurityTokenSerializer keyInfoTokenSerializer
)
127 writer
.WriteStartElement ("saml", "Attribute", SamlConstants
.Namespace
);
128 writer
.WriteAttributeString ("AttributeName", Name
);
129 writer
.WriteAttributeString ("AttributeNamespace", Namespace
);
130 foreach (string s
in AttributeValues
)
131 writer
.WriteElementString ("saml", "AttributeValue", SamlConstants
.Namespace
, s
);
132 writer
.WriteEndElement ();
136 public virtual ReadOnlyCollection
<Claim
> ExtractClaims ()
138 throw new NotImplementedException ();