Skip to content

Commit

Permalink
Merge pull request #3 from yp-engineering/attributes_extras
Browse files Browse the repository at this point in the history
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
  • Loading branch information
geoffgarside committed Sep 30, 2015
2 parents 922a636 + c3b5675 commit 32e4124
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions service_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func ParseServiceResponse(data []byte) (*AuthenticationResponse, error) {
r.Attributes.Add(ea.XMLName.Local, strings.TrimSpace(ea.Value))
}
}

if a.ExtraAttributes != nil {
for _, ea := range a.ExtraAttributes {
r.Attributes.Add(ea.XMLName.Local, strings.TrimSpace(ea.Value))
}
}
}

for _, ea := range x.Success.ExtraAttributes {
Expand Down
9 changes: 7 additions & 2 deletions service_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func TestUnmarshalSuccessfulServiceResponseWithUserAttributesXmlAnyForm(t *testi
<cas:memberOf>Group1</cas:memberOf>
<cas:memberOf>Group2</cas:memberOf>
<cas:memberOf>Group3</cas:memberOf>
<cas:reportsTo>theboss</cas:reportsTo>
<cas:userAttributes>
<cas:firstname>John</cas:firstname>
<cas:lastname>Doe</cas:lastname>
Expand All @@ -208,8 +209,8 @@ func TestUnmarshalSuccessfulServiceResponseWithUserAttributesXmlAnyForm(t *testi
}
}

if len(sr.Attributes) != 5 {
t.Errorf("Expected Attributes to have 5 items, got %v: %v",
if len(sr.Attributes) != 6 {
t.Errorf("Expected Attributes to have 6 items, got %v: %v",
len(sr.Attributes), sr.Attributes)
}

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

if v := sr.Attributes.Get("reportsTo"); v != "theboss" {
t.Errorf("Expected reportsTo attribute to be <theboss>, got <%v>", v)
}

expectedAffiliations := []string{"staff", "faculty"}
if affiliations, ok := sr.Attributes["affiliation"]; ok {
for i, affiliation := range affiliations {
Expand Down
1 change: 1 addition & 0 deletions xml_service_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type xmlAttributes struct {
IsFromNewLogin bool `xml:"isFromNewLogin"`
MemberOf []string `xml:"memberOf"`
UserAttributes *xmlUserAttributes
ExtraAttributes []*xmlAnyAttribute `xml:",any"`
}

type xmlUserAttributes struct {
Expand Down

0 comments on commit 32e4124

Please sign in to comment.