Element returns an etree.Element representing the object in XML form.
()
| 500 | |
| 501 | // Element returns an etree.Element representing the object in XML form. |
| 502 | func (r *Response) Element() *etree.Element { |
| 503 | el := etree.NewElement("samlp:Response") |
| 504 | el.CreateAttr("xmlns:saml", "urn:oasis:names:tc:SAML:2.0:assertion") |
| 505 | el.CreateAttr("xmlns:samlp", "urn:oasis:names:tc:SAML:2.0:protocol") |
| 506 | |
| 507 | // Note: This namespace is not used by any element or attribute name, but |
| 508 | // is required so that the AttributeValue type element can have a value like |
| 509 | // "xs:string". If we don't declare it here, then it will be stripped by the |
| 510 | // cannonicalizer. This could be avoided by providing a prefix list to the |
| 511 | // cannonicalizer, but prefix lists do not appear to be implemented correctly |
| 512 | // in some libraries, so the safest action is to always produce XML that is |
| 513 | // (a) in canonical form and (b) does not require prefix lists. |
| 514 | el.CreateAttr("xmlns:xs", "http://www.w3.org/2001/XMLSchema") |
| 515 | |
| 516 | el.CreateAttr("ID", r.ID) |
| 517 | if r.InResponseTo != "" { |
| 518 | el.CreateAttr("InResponseTo", r.InResponseTo) |
| 519 | } |
| 520 | el.CreateAttr("Version", r.Version) |
| 521 | el.CreateAttr("IssueInstant", r.IssueInstant.Format(timeFormat)) |
| 522 | if r.Destination != "" { |
| 523 | el.CreateAttr("Destination", r.Destination) |
| 524 | } |
| 525 | if r.Consent != "" { |
| 526 | el.CreateAttr("Consent", r.Consent) |
| 527 | } |
| 528 | if r.Issuer != nil { |
| 529 | el.AddChild(r.Issuer.Element()) |
| 530 | } |
| 531 | if r.Signature != nil { |
| 532 | el.AddChild(r.Signature) |
| 533 | } |
| 534 | el.AddChild(r.Status.Element()) |
| 535 | if r.EncryptedAssertion != nil { |
| 536 | el.AddChild(r.EncryptedAssertion) |
| 537 | } |
| 538 | if r.Assertion != nil { |
| 539 | el.AddChild(r.Assertion.Element()) |
| 540 | } |
| 541 | return el |
| 542 | } |
| 543 | |
| 544 | // MarshalXML implements xml.Marshaler |
| 545 | func (r *Response) MarshalXML(e *xml.Encoder, start xml.StartElement) error { |