SamlAuthorityBinding.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // SamlAuthorityBinding.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  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. namespace System.IdentityModel.Tokens
  36. {
  37. [DataContract]
  38. public class SamlAuthorityBinding
  39. {
  40. XmlQualifiedName kind;
  41. string binding, location;
  42. bool is_readonly;
  43. public SamlAuthorityBinding ()
  44. {
  45. }
  46. public SamlAuthorityBinding (XmlQualifiedName kind, string binding, string location)
  47. {
  48. if (kind == null)
  49. throw new ArgumentNullException ("kind");
  50. AuthorityKind = kind;
  51. Binding = binding;
  52. Location = location;
  53. }
  54. [DataMember]
  55. public XmlQualifiedName AuthorityKind {
  56. get { return kind; }
  57. set {
  58. CheckReadOnly ();
  59. if (value == null)
  60. throw new ArgumentNullException ("value");
  61. if (value.Equals (XmlQualifiedName.Empty))
  62. throw new ArgumentException ("non-empty XmlQualifiedName must be set to AuthorityKind of SamlAuthorityBinding.");
  63. kind = value;
  64. }
  65. }
  66. [DataMember]
  67. public string Binding {
  68. get { return binding; }
  69. set {
  70. CheckReadOnly ();
  71. if (value == null || value.Length == 0)
  72. throw new ArgumentException ("non-zero length string must be set to Binding of SamlAuthorityBinding.");
  73. binding = value;
  74. }
  75. }
  76. [DataMember]
  77. public string Location {
  78. get { return location; }
  79. set {
  80. CheckReadOnly ();
  81. if (value == null || value.Length == 0)
  82. throw new ArgumentException ("non-zero length string must be set to Location of SamlAuthorityBinding.");
  83. location = value;
  84. }
  85. }
  86. public bool IsReadOnly {
  87. get { return is_readonly; }
  88. }
  89. void CheckReadOnly ()
  90. {
  91. if (IsReadOnly)
  92. throw new InvalidOperationException ("This object is read-only.");
  93. }
  94. public void MakeReadOnly ()
  95. {
  96. is_readonly = true;
  97. }
  98. [MonoTODO]
  99. public virtual void ReadXml (XmlDictionaryReader reader,
  100. SamlSerializer samlSerializer,
  101. SecurityTokenSerializer keyInfoSerializer,
  102. SecurityTokenResolver outOfBandTokenResolver)
  103. {
  104. throw new NotImplementedException ();
  105. }
  106. public virtual void WriteXml (
  107. XmlDictionaryWriter writer,
  108. SamlSerializer samlSerializer,
  109. SecurityTokenSerializer keyInfoSerializer)
  110. {
  111. if (writer == null)
  112. throw new ArgumentNullException ("writer");
  113. if (samlSerializer == null)
  114. throw new ArgumentNullException ("samlSerializer");
  115. if (AuthorityKind == null)
  116. throw new SecurityTokenException ("AuthorityKind must be set to SAML AuthorityBinding before being written.");
  117. if (Binding == null)
  118. throw new SecurityTokenException ("non-zero length Binding must be set to SAML AuthorityBinding before being written.");
  119. if (Location == null)
  120. throw new SecurityTokenException ("non-zero length Location must be set to SAML AuthorityBinding before being written.");
  121. writer.WriteStartElement ("saml", "AuthorityBinding", SamlConstants.Namespace);
  122. writer.WriteXmlnsAttribute (String.Empty, AuthorityKind.Namespace);
  123. writer.WriteAttributeString ("AuthorityKind", AuthorityKind.Name);
  124. writer.WriteAttributeString ("Location", Location);
  125. writer.WriteAttributeString ("Binding", Binding);
  126. writer.WriteEndElement ();
  127. }
  128. }
  129. }