diff --git a/src/Control/SAMLController.php b/src/Control/SAMLController.php index c4e617b..8373a50 100644 --- a/src/Control/SAMLController.php +++ b/src/Control/SAMLController.php @@ -203,14 +203,6 @@ public function acs() $member->$field = $attributes[$claim][0]; } - $mapUserGroup = Config::inst()->get(SAMLConfiguration::class, 'map_user_group'); - // Map user groups - if ($mapUserGroup) { - $mapper = SAMLUserGroupMapper::singleton(); - - $member = $mapper->map($attributes, $member); - } - $member->SAMLSessionIndex = $auth->getSessionIndex(); // This will trigger LDAP update through LDAPMemberExtension::memberLoggedIn, if the LDAP module is installed. @@ -219,6 +211,14 @@ public function acs() // Both SAML and LDAP identify Members by the same GUID field. $member->write(); + $mapUserGroup = Config::inst()->get(SAMLConfiguration::class, 'map_user_group'); + // Map user groups + if ($mapUserGroup) { + $mapper = SAMLUserGroupMapper::singleton(); + + $member = $mapper->map($attributes, $member); + } + // Hook for modifying login behaviour $this->extend('updateLogin'); diff --git a/src/Helpers/SAMLUserGroupMapper.php b/src/Helpers/SAMLUserGroupMapper.php index e6dc4fe..d58b5a8 100644 --- a/src/Helpers/SAMLUserGroupMapper.php +++ b/src/Helpers/SAMLUserGroupMapper.php @@ -57,11 +57,6 @@ public function map($attributes, $member): Member $group->write(); } - // Add group to user and make sure user has been created - if (!$member->exists()) { - $member->write(); - } - $member->Groups()->add($group); }