mono_arch_unwindinfo_install_tramp_unwind_info can only be called for JIT:ed code.
[mono.git] / mcs / class / System.IdentityModel / System.IdentityModel.Tokens / SamlAttribute.cs
1 //
2 // SamlAttribute.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005-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.Collections.ObjectModel;
31 using System.Xml;
32 using System.IdentityModel.Claims;
33 using System.IdentityModel.Selectors;
34
35 namespace System.IdentityModel.Tokens
36 {
37         public class SamlAttribute
38         {
39                 bool is_readonly;
40                 string name, ns;
41                 List<string> attribute_values;
42
43                 public SamlAttribute ()
44                 {
45                         attribute_values = new List<string> ();
46                 }
47
48                 public SamlAttribute (Claim claim)
49                 {
50                         if (claim == null)
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);
59
60                         if (claim.Resource != null && !(claim.Resource is string))
61                                 throw new ArgumentException ("Claim resource is not a string.");
62
63                         attribute_values = new List<string> ();
64                         attribute_values.Add ((string) claim.Resource);
65
66                         if (claim.Right != Rights.PossessProperty)
67                                 throw new ArgumentException ("Claim right is not PossessProperty");
68                 }
69
70                 public SamlAttribute (string attributeNamespace,
71                         string attributeName,
72                         IEnumerable<string> attributeValues)
73                 {
74                         ns = attributeNamespace;
75                         name = attributeName;
76                         attribute_values = new List<string> (attributeValues);
77                 }
78
79                 public IList<string> AttributeValues {
80                         get { return attribute_values; }
81                 }
82
83                 public string Name {
84                         get { return name; }
85                         set {
86                                 CheckReadOnly ();
87                                 name = value;
88                         }
89                 }
90
91                 public string Namespace {
92                         get { return ns; }
93                         set {
94                                 CheckReadOnly ();
95                                 ns = value;
96                         }
97                 }
98
99                 public bool IsReadOnly {
100                         get { return is_readonly; }
101                 }
102
103                 private void CheckReadOnly ()
104                 {
105                         if (is_readonly)
106                                 throw new InvalidOperationException ("This SAML assertion is read-only.");
107                 }
108
109                 public void MakeReadOnly ()
110                 {
111                         is_readonly = true;
112                 }
113
114                 [MonoTODO]
115                 public virtual void ReadXml (XmlDictionaryReader reader,
116                         SamlSerializer samlSerializer,
117                         SecurityTokenSerializer keyInfoTokenSerializer,
118                         SecurityTokenResolver outOfBandTokenResolver)
119                 {
120                         throw new NotImplementedException ();
121                 }
122
123                 public virtual void WriteXml (XmlDictionaryWriter writer,
124                         SamlSerializer samlSerializer,
125                         SecurityTokenSerializer keyInfoTokenSerializer)
126                 {
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 ();
133                 }
134
135                 [MonoTODO]
136                 public virtual ReadOnlyCollection<Claim> ExtractClaims ()
137                 {
138                         throw new NotImplementedException ();
139                 }
140         }
141 }