Skip to content

Commit 32e4124

Browse files
committed
Merge pull request #3 from yp-engineering/attributes_extras
Update XML Service Response support for latest CAS SAML extra attributes. The [specification][spec] for the SAML CAS response attributes has been changed such that the `cas:attributes` XML element no longer mentions the `cas:userAttributes` element. The contents of the `cas:userAttributes` element can now be located directly in the `cas:attributes` element. [spec]: http://jasig.github.io/cas/4.1.x/protocol/CAS-Protocol-Specification.html#saml-cas-response-attributes
2 parents 922a636 + c3b5675 commit 32e4124

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

service_response.go

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ func ParseServiceResponse(data []byte) (*AuthenticationResponse, error) {
113113
r.Attributes.Add(ea.XMLName.Local, strings.TrimSpace(ea.Value))
114114
}
115115
}
116+
117+
if a.ExtraAttributes != nil {
118+
for _, ea := range a.ExtraAttributes {
119+
r.Attributes.Add(ea.XMLName.Local, strings.TrimSpace(ea.Value))
120+
}
121+
}
116122
}
117123

118124
for _, ea := range x.Success.ExtraAttributes {

service_response_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ func TestUnmarshalSuccessfulServiceResponseWithUserAttributesXmlAnyForm(t *testi
182182
<cas:memberOf>Group1</cas:memberOf>
183183
<cas:memberOf>Group2</cas:memberOf>
184184
<cas:memberOf>Group3</cas:memberOf>
185+
<cas:reportsTo>theboss</cas:reportsTo>
185186
<cas:userAttributes>
186187
<cas:firstname>John</cas:firstname>
187188
<cas:lastname>Doe</cas:lastname>
@@ -208,8 +209,8 @@ func TestUnmarshalSuccessfulServiceResponseWithUserAttributesXmlAnyForm(t *testi
208209
}
209210
}
210211

211-
if len(sr.Attributes) != 5 {
212-
t.Errorf("Expected Attributes to have 5 items, got %v: %v",
212+
if len(sr.Attributes) != 6 {
213+
t.Errorf("Expected Attributes to have 6 items, got %v: %v",
213214
len(sr.Attributes), sr.Attributes)
214215
}
215216

@@ -233,6 +234,10 @@ func TestUnmarshalSuccessfulServiceResponseWithUserAttributesXmlAnyForm(t *testi
233234
t.Errorf("Expected affiliation attribute to be <staff>, got <%v>", v)
234235
}
235236

237+
if v := sr.Attributes.Get("reportsTo"); v != "theboss" {
238+
t.Errorf("Expected reportsTo attribute to be <theboss>, got <%v>", v)
239+
}
240+
236241
expectedAffiliations := []string{"staff", "faculty"}
237242
if affiliations, ok := sr.Attributes["affiliation"]; ok {
238243
for i, affiliation := range affiliations {

xml_service_response.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type xmlAttributes struct {
4343
IsFromNewLogin bool `xml:"isFromNewLogin"`
4444
MemberOf []string `xml:"memberOf"`
4545
UserAttributes *xmlUserAttributes
46+
ExtraAttributes []*xmlAnyAttribute `xml:",any"`
4647
}
4748

4849
type xmlUserAttributes struct {

0 commit comments

Comments
 (0)