/pkg/util/samlutils/types.go

https://github.com/yunionio/onecloud · Go · 487 lines · 323 code · 146 blank · 18 comment · 0 complexity · 0e99e52ce6c2dfd2123bd74a95a6bc0f MD5 · raw file

  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package samlutils
  15. import "encoding/xml"
  16. type DigestMethod struct {
  17. XMLName xml.Name
  18. Algorithm string `xml:"Algorithm,attr"`
  19. }
  20. type SigningMethod struct {
  21. XMLName xml.Name
  22. Algorithm string `xml:"Algorithm,attr"`
  23. }
  24. type RequestInitiator struct {
  25. XMLName xml.Name
  26. Binding string `xml:"Binding,attr"`
  27. Location string `xml:"Location,attr"`
  28. }
  29. type SXMLText struct {
  30. XMLName xml.Name
  31. Lang string `xml:"xml:lang,attr"`
  32. Text string `xml:",innerxml"`
  33. }
  34. type SXMLLogo struct {
  35. XMLName xml.Name
  36. Height string `xml:"height,attr"`
  37. Width string `xml:"width,attr"`
  38. URL string `xml:",innerxml"`
  39. }
  40. type SSAMLUIInfo struct {
  41. XMLName xml.Name
  42. DisplayName SXMLText `xml:"DisplayName"`
  43. Description SXMLText `xml:"Description"`
  44. Logo SXMLLogo `xml:"Logo"`
  45. }
  46. type SSAMLScope struct {
  47. XMLName xml.Name
  48. Regexp string `xml:"regexp,attr"`
  49. Scope string `xml:",innerxml"`
  50. }
  51. type Extensions struct {
  52. XMLName xml.Name
  53. // Alg string `xml:"alg,attr"`
  54. // MDAttr string `xml:"mdattr,attr"`
  55. // MDRPI string `xml:"mdrpi,attr"`
  56. // EntityAttributes string `xml:"EntityAttributes"`
  57. SigningMethods []SigningMethod `xml:"SigningMethod"`
  58. DigestMethods []DigestMethod `xml:"DigestMethod"`
  59. RequestInitiator *RequestInitiator `xml:"RequestInitiator"`
  60. UIInfo *SSAMLUIInfo `xml:"UIInfo"`
  61. Scope *SSAMLScope `xml:"Scope"`
  62. }
  63. type X509Certificate struct {
  64. XMLName xml.Name
  65. Cert string `xml:",innerxml"`
  66. }
  67. type X509Data struct {
  68. XMLName xml.Name
  69. X509Certificate X509Certificate `xml:"X509Certificate"`
  70. }
  71. type KeyInfo struct {
  72. XMLName xml.Name
  73. X509Data *X509Data `xml:"X509Data"`
  74. EncryptedKey *EncryptedKey `xml:"EncryptedKey"`
  75. }
  76. type EncryptionMethod struct {
  77. XMLName xml.Name
  78. Algorithm string `xml:"Algorithm,attr"`
  79. DigestMethod *DigestMethod `xml:"DigestMethod"`
  80. }
  81. type KeyDescriptor struct {
  82. XMLName xml.Name
  83. Use string `xml:"use,attr"`
  84. KeyInfo KeyInfo `xml:"KeyInfo"`
  85. EncryptionMethods []EncryptionMethod `xml:"EncryptionMethod"`
  86. }
  87. type SSAMLService struct {
  88. XMLName xml.Name
  89. Binding string `xml:"Binding,attr"`
  90. Location string `xml:"Location,attr"`
  91. Index *string `xml:"index,attr"`
  92. IsDefault *string `xml:"isDefault,attr"`
  93. }
  94. type SSAMLNameIDFormat struct {
  95. XMLName xml.Name
  96. Format string `xml:",innerxml"`
  97. }
  98. type RequestedAttribute struct {
  99. XMLName xml.Name
  100. IsRequired string `xml:"isRequired,attr"`
  101. Name string `xml:"Name,attr"`
  102. FriendlyName string `xml:"FriendlyName,attr"`
  103. }
  104. type AttributeConsumingService struct {
  105. XMLName xml.Name
  106. Index string `xml:"index,attr"`
  107. ServiceName SXMLText `xml:"ServiceName"`
  108. RequestedAttributes []RequestedAttribute `xml:"RequestedAttribute"`
  109. }
  110. type SSODescriptor struct {
  111. XMLName xml.Name
  112. AuthnRequestsSigned *string `xml:"AuthnRequestsSigned,attr"`
  113. WantAssertionsSigned *string `xml:"WantAssertionsSigned,attr"`
  114. ProtocolSupportEnumeration string `xml:"protocolSupportEnumeration,attr"`
  115. Extensions *Extensions `xml:"Extensions"`
  116. KeyDescriptors []KeyDescriptor `xml:"KeyDescriptor"`
  117. ArtifactResolutionServices []SSAMLService `xml:"ArtifactResolutionService"`
  118. SingleLogoutServices []SSAMLService `xml:"SingleLogoutService"`
  119. ManageNameIDServices []SSAMLService `xml:"ManageNameIDService"`
  120. NameIDFormat []SSAMLNameIDFormat `xml:"NameIDFormat"`
  121. SingleSignOnServices []SSAMLService `xml:"SingleSignOnService"`
  122. AssertionConsumerServices []SSAMLService `xml:"AssertionConsumerService"`
  123. AttributeConsumingServices []AttributeConsumingService `xml:"AttributeConsumingService"`
  124. }
  125. type SSAMLValue struct {
  126. XMLName xml.Name
  127. Value string `xml:",innerxml"`
  128. }
  129. type Transforms struct {
  130. XMLName xml.Name
  131. Transforms []EncryptionMethod `xml:"Transform"`
  132. }
  133. type Reference struct {
  134. XMLName xml.Name
  135. URI string `xml:"URI,attr"`
  136. Transforms Transforms `xml:"Transforms"`
  137. DigestMethod EncryptionMethod `xml:"DigestMethod"`
  138. DigestValue SSAMLValue `xml:"DigestValue"`
  139. }
  140. type SignedInfo struct {
  141. XMLName xml.Name
  142. CanonicalizationMethod EncryptionMethod `xml:"CanonicalizationMethod"`
  143. SignatureMethod EncryptionMethod `xml:"SignatureMethod"`
  144. Reference Reference `xml:"Reference"`
  145. }
  146. type Signature struct {
  147. XMLName xml.Name
  148. SignedInfo SignedInfo `xml:"SignedInfo"`
  149. SignatureValue SSAMLValue `xml:"SignatureValue"`
  150. KeyInfo KeyInfo `xml:"KeyInfo"`
  151. }
  152. type Organization struct {
  153. XMLName xml.Name
  154. OrganizationName SXMLText `xml:"OrganizationName"`
  155. OrganizationDisplayName SXMLText `xml:"OrganizationDisplayName"`
  156. OrganizationURL SXMLText `xml:"OrganizationURL"`
  157. }
  158. type EntityDescriptor struct {
  159. XMLName xml.Name
  160. // Id *string `xml:"ID,attr"`
  161. EntityId string `xml:"entityID,attr"`
  162. Extensions *Extensions `xml:"Extensions"`
  163. Signature *Signature `xml:"Signature"`
  164. SPSSODescriptor *SSODescriptor `xml:"SPSSODescriptor"`
  165. IDPSSODescriptor *SSODescriptor `xml:"IDPSSODescriptor"`
  166. Organization *Organization `xml:"Organization"`
  167. }
  168. type SIdpRedirectLoginInput struct {
  169. SAMLRequest string `json:"SAMLRequest,ignoreempty"`
  170. RelayState string `json:"RelayState,ignoreempty"`
  171. SigAlg string `json:"SigAlg,ignoreempty"`
  172. Signature string `json:"Signature,ignoreempty"`
  173. }
  174. type SIdpInitiatedLoginInput struct {
  175. EntityID string `json:"EntityID"`
  176. IdpId string `json:"IdpId"`
  177. }
  178. type Issuer struct {
  179. XMLName xml.Name
  180. Format *string `xml:"Format,attr"`
  181. Issuer string `xml:",innerxml"`
  182. }
  183. type NameIDPolicy struct {
  184. XMLName xml.Name
  185. AllowCreate string `xml:"AllowCreate,attr"`
  186. Format string `xml:"Format,attr"`
  187. SPNameQualifier *string `xml:"SPNameQualifier,attr"`
  188. }
  189. type AuthnRequest struct {
  190. XMLName xml.Name
  191. AssertionConsumerServiceURL string `xml:"AssertionConsumerServiceURL,attr"`
  192. Destination string `xml:"Destination,attr"`
  193. ForceAuthn string `xml:"ForceAuthn,attr"`
  194. ID string `xml:"ID,attr"`
  195. IsPassive string `xml:"IsPassive,attr"`
  196. IssueInstant string `xml:"IssueInstant,attr"`
  197. ProtocolBinding string `xml:"ProtocolBinding,attr"`
  198. Version string `xml:"Version,attr"`
  199. Issuer Issuer `xml:"Issuer"`
  200. NameIDPolicy NameIDPolicy `xml:"NameIDPolicy"`
  201. }
  202. type StatusCode struct {
  203. XMLName xml.Name
  204. Value string `xml:"Value,attr"`
  205. }
  206. type StatusMessage struct {
  207. XMLName xml.Name
  208. Message string `xml:",innerxml"`
  209. }
  210. type Status struct {
  211. XMLName xml.Name
  212. StatusCode StatusCode `xml:"StatusCode"`
  213. StatusMessage *StatusMessage `xml:"StatusMessage"`
  214. }
  215. type Response struct {
  216. XMLName xml.Name
  217. ID string `xml:"ID,attr"`
  218. InResponseTo *string `xml:"InResponseTo,attr"`
  219. Version string `xml:"Version,attr"`
  220. IssueInstant string `xml:"IssueInstant,attr"`
  221. Destination string `xml:"Destination,attr"`
  222. Issuer Issuer `xml:"Issuer"`
  223. Status Status `xml:"Status"`
  224. Assertion *Assertion `xml:"Assertion"`
  225. EncryptedAssertion *EncryptedAssertion `xml:"EncryptedAssertion"`
  226. }
  227. type Assertion struct {
  228. XMLName xml.Name
  229. ID string `xml:"ID,attr"`
  230. Version string `xml:"Version,attr"`
  231. IssueInstant string `xml:"IssueInstant,attr"`
  232. Issuer Issuer `xml:"Issuer"`
  233. Signature *Signature `xml:"Signature"`
  234. Subject Subject `xml:"Subject"`
  235. Conditions Conditions `xml:"Conditions"`
  236. AttributeStatement *AttributeStatement `xml:"AttributeStatement"`
  237. AuthnStatement AuthnStatement `xml:"AuthnStatement"`
  238. }
  239. type Subject struct {
  240. XMLName xml.Name
  241. NameID NameID `xml:"NameID"`
  242. SubjectConfirmation SubjectConfirmation `xml:"SubjectConfirmation"`
  243. }
  244. type NameID struct {
  245. XMLName xml.Name
  246. Format string `xml:"Format,attr"`
  247. NameQualifier *string `xml:"NameQualifier,attr"`
  248. Value string `xml:",innerxml"`
  249. }
  250. type SubjectConfirmation struct {
  251. XMLName xml.Name
  252. Method string `xml:"Method,attr"`
  253. SubjectConfirmationData SubjectConfirmationData `xml:"SubjectConfirmationData"`
  254. }
  255. type SubjectConfirmationData struct {
  256. XMLName xml.Name
  257. InResponseTo *string `xml:"InResponseTo,attr"`
  258. Recipient string `xml:"Recipient,attr"`
  259. NotBefore *string `xml:"NotBefore,attr"`
  260. NotOnOrAfter string `xml:"NotOnOrAfter,attr"`
  261. }
  262. type Conditions struct {
  263. XMLName xml.Name
  264. NotBefore *string `xml:"NotBefore,attr"`
  265. NotOnOrAfter string `xml:"NotOnOrAfter,attr"`
  266. AudienceRestrictions []AudienceRestriction `xml:"AudienceRestriction"`
  267. }
  268. type AudienceRestriction struct {
  269. XMLName xml.Name
  270. Audience Audience `xml:"Audience"`
  271. }
  272. type Audience struct {
  273. XMLName xml.Name
  274. Value string `xml:",innerxml"`
  275. }
  276. type AttributeStatement struct {
  277. XMLName xml.Name
  278. Attributes []Attribute `xml:"Attribute"`
  279. }
  280. type Attribute struct {
  281. XMLName xml.Name
  282. FriendlyName *string `xml:"FriendlyName,attr"`
  283. Name string `xml:"Name,attr"`
  284. NameFormat *string `xml:"NameFormat,attr"`
  285. AttributeValues []AttributeValue `xml:"AttributeValue"`
  286. }
  287. type AttributeValue struct {
  288. XMLName xml.Name
  289. Type string `xml:"type,attr"`
  290. Value string `xml:",innerxml"`
  291. }
  292. type AuthnStatement struct {
  293. XMLName xml.Name
  294. AuthnInstant string `xml:"AuthnInstant,attr"`
  295. SessionIndex string `xml:"SessionIndex,attr"`
  296. SubjectLocality *SubjectLocality `xml:"SubjectLocality"`
  297. AuthnContext AuthnContext `xml:"AuthnContext"`
  298. }
  299. type SubjectLocality struct {
  300. XMLName xml.Name
  301. Address string `xml:"Address,attr"`
  302. }
  303. type AuthnContext struct {
  304. XMLName xml.Name
  305. AuthnContextClassRef AuthnContextClassRef `xml:"AuthnContextClassRef"`
  306. }
  307. type AuthnContextClassRef struct {
  308. XMLName xml.Name
  309. Value string `xml:",innerxml"`
  310. }
  311. type SSpInitiatedLoginInput struct {
  312. EntityID string `json:"EntityID"`
  313. }
  314. type EncryptedAssertion struct {
  315. XMLName xml.Name
  316. EncryptedData EncryptedData `xml:"EncryptedData"`
  317. }
  318. type EncryptedData struct {
  319. XMLName xml.Name
  320. Id string `xml:"Id,attr"`
  321. Type string `xml:"Type,attr"`
  322. EncryptionMethod EncryptionMethod `xml:"EncryptionMethod"`
  323. KeyInfo KeyInfo `xml:"KeyInfo"`
  324. CipherData CipherData `xml:"CipherData"`
  325. }
  326. type CipherData struct {
  327. XMLName xml.Name
  328. CipherValue CipherValue `xml:"CipherValue"`
  329. }
  330. type CipherValue struct {
  331. XMLName xml.Name
  332. Value string `xml:",innerxml"`
  333. }
  334. type EncryptedKey struct {
  335. XMLName xml.Name
  336. Id string `xml:"Id,attr"`
  337. Recipient string `xml:"Recipient,attr"`
  338. EncryptionMethod EncryptionMethod `xml:"EncryptionMethod"`
  339. KeyInfo KeyInfo `xml:"KeyInfo"`
  340. CipherData CipherData `xml:"CipherData"`
  341. }