Skip to content

Commit

Permalink
Add group filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ullriti authored Apr 29, 2020
1 parent 863cd51 commit 5b386c0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Template/config/integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<?= $this->form->text('oauth2_key_groups', $values) ?>
<p class="form-help"><?= t('Leave empty, when no group mapping is wanted') ?></p>

<?= $this->form->label(t('Group Filter'), 'oauth2_key_group_filter') ?>
<?= $this->form->text('oauth2_key_group_filter', $values) ?>
<p class="form-help"><?= t('Use a comma to enter multiple useable groups: group1,group2') ?></p>

<div class="form-actions">
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
</div>
Expand Down
33 changes: 31 additions & 2 deletions User/GenericOAuth2UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ public function getEmail()
return $this->getKey('oauth2_key_email');
}

/**
* Check if group is in filter
*
* @access protected
* @param string $group
* @return boolean
*/
protected function isGroupInFilter(string $group, array $filter)
{
if (empty($filter)) {
$this->logger->debug('OAuth2: No group specified in filter. All provided groups will be used.');
return true;
} else {
if (in_array($group, $filter)) {
return true;
} else {
return false;
}
}
}

/**
* Get external group ids
*
Expand Down Expand Up @@ -173,11 +194,19 @@ public function getExternalGroupIds()
$groups = array_unique($groups);
$this->logger->debug('OAuth2: '.$this->getUsername().' groups are '. join(',', $groups));

$filteredGroups = array();
$groupFilter = explode(',',$this->configModel->get('oauth2_key_group_filter'));

foreach ($groups as $group) {
$this->groupModel->getOrCreateExternalGroupId($group, $group);
if ( $this->isGroupInFilter($group, $groupFilter)) {
$this->groupModel->getOrCreateExternalGroupId($group, $group);
array_push($filteredGroups, $group);
} else {
$this->logger->debug('OAuth2: '.$group.' will be ignored.');
}
}

return $groups;
return $filteredGroups;
}

/**
Expand Down

0 comments on commit 5b386c0

Please sign in to comment.