diff --git a/internal/api/samlassertion.go b/internal/api/samlassertion.go index 0d7c363bb..75cdfdb4f 100644 --- a/internal/api/samlassertion.go +++ b/internal/api/samlassertion.go @@ -128,9 +128,18 @@ func (a *SAMLAssertion) Process(mapping models.SAMLAttributeMapping) map[string] for _, name := range names { for _, attr := range a.Attribute(name) { if attr.Value != "" { - ret[key] = attr.Value setKey = true - break + + if mapper.Array { + if ret[key] == nil { + ret[key] = []string{} + } + + ret[key] = append(ret[key].([]string), attr.Value) + } else { + ret[key] = attr.Value + break + } } } diff --git a/internal/api/samlassertion_test.go b/internal/api/samlassertion_test.go index 9ec061f49..47992a214 100644 --- a/internal/api/samlassertion_test.go +++ b/internal/api/samlassertion_test.go @@ -204,6 +204,42 @@ func TestSAMLAssertionProcessing(t *tst.T) { "email": "soap@example.com", }, }, + { + xml: ` + + + + group1 + group2 + + + soap@example.com + + + +`, + mapping: models.SAMLAttributeMapping{ + Keys: map[string]models.SAMLAttribute{ + "email": { + Names: []string{ + "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", + "http://schemas.xmlsoap.org/claims/EmailAddress", + }, + }, + "groups": { + Name: "groups", + Array: true, + }, + }, + }, + expected: map[string]interface{}{ + "email": "soap@example.com", + "groups": []string{ + "group1", + "group2", + }, + }, + }, } for i, example := range examples { diff --git a/internal/models/sso.go b/internal/models/sso.go index bbdd138ce..1cf982604 100644 --- a/internal/models/sso.go +++ b/internal/models/sso.go @@ -36,6 +36,7 @@ type SAMLAttribute struct { Name string `json:"name,omitempty"` Names []string `json:"names,omitempty"` Default interface{} `json:"default,omitempty"` + Array bool `json:"array,omitempty"` } type SAMLAttributeMapping struct { @@ -78,6 +79,10 @@ func (m *SAMLAttributeMapping) Equal(o *SAMLAttributeMapping) bool { if mvalue.Default != value.Default { return false } + + if mvalue.Array != value.Array { + return false + } } return true