|
@@ -56,6 +56,26 @@ module.exports = {
|
|
|
picture: _.get(profile, conf.mappingPicture, '')
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ // map users provider groups to wiki groups with the same name, and remove any groups that don't match
|
|
|
+ // Code copied from the LDAP implementation with a slight variation on the field we extract the value from
|
|
|
+ // In SAML v2 groups come in profile.attributes and can be 1 string or an array of strings
|
|
|
+ if (conf.mapGroups) {
|
|
|
+ const maybeArrayOfGroups = _.get(profile.attributes, conf.mappingGroups)
|
|
|
+ const groups = (maybeArrayOfGroups && !_.isArray(maybeArrayOfGroups)) ? [maybeArrayOfGroups] : maybeArrayOfGroups
|
|
|
+
|
|
|
+ if (groups && _.isArray(groups)) {
|
|
|
+ const currentGroups = (await user.$relatedQuery('groups').select('groups.id')).map(g => g.id)
|
|
|
+ const expectedGroups = Object.values(WIKI.auth.groups).filter(g => groups.includes(g.name)).map(g => g.id)
|
|
|
+ for (const groupId of _.difference(expectedGroups, currentGroups)) {
|
|
|
+ await user.$relatedQuery('groups').relate(groupId)
|
|
|
+ }
|
|
|
+ for (const groupId of _.difference(currentGroups, expectedGroups)) {
|
|
|
+ await user.$relatedQuery('groups').unrelate().where('groupId', groupId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
cb(null, user)
|
|
|
} catch (err) {
|
|
|
cb(err, null)
|