-
Notifications
You must be signed in to change notification settings - Fork 15
/
response.go
81 lines (65 loc) · 2.11 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package core
import (
"github.com/russellhaering/gosaml2/types"
)
// Response is a SAML Response element.
// See 3.3.3 http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type Response struct {
types.Response
}
// Assertions returns the assertions in the Response.
func (r *Response) Assertions() []Assertion {
assertions := make([]Assertion, 0, len(r.Response.Assertions))
for _, assertion := range r.Response.Assertions {
assertions = append(assertions, Assertion{Assertion: assertion})
}
return assertions
}
// Issuer returns the issuer of the Response if it exists.
// Otherwise, it returns an empty string.
func (r *Response) Issuer() string {
if r.Response.Issuer == nil {
return ""
}
return r.Response.Issuer.Value
}
// Assertion is a SAML Assertion element.
// See 2.3.3 http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type Assertion struct {
types.Assertion
}
// Attribute is a SAML Attribute element.
// See 2.7.3.1 http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
type Attribute struct {
types.Attribute
}
// Issuer returns the issuer of the Assertion if it exists.
// Otherwise, it returns an empty string.
func (a *Assertion) Issuer() string {
if a.Assertion.Issuer == nil {
return ""
}
return a.Assertion.Issuer.Value
}
// SubjectNameID returns the value of the NameID element if it exists in
// the Subject of the Assertion. Otherwise, it returns an empty string.
func (a *Assertion) SubjectNameID() string {
if a.Subject == nil || a.Subject.NameID == nil {
return ""
}
return a.Subject.NameID.Value
}
// Attributes returns the attributes of the Assertion. If there is no
// AttributeStatement or no contained Attributes, an empty list is returned.
func (a *Assertion) Attributes() []Attribute {
if a.AttributeStatement == nil {
return []Attribute{}
}
attributes := make([]Attribute, 0, len(a.AttributeStatement.Attributes))
for _, attribute := range a.AttributeStatement.Attributes {
attributes = append(attributes, Attribute{Attribute: attribute})
}
return attributes
}