Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHRAS-4106_ignore-openid-groups #4561

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/configuration.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ authentication:
realm-name: phrasea
exclusive: false
icon-uri: null
usegroups: false
birth-group: _firstlog
everyone-group: _everyone
metamodel: _metamodel
Expand Down
11 changes: 6 additions & 5 deletions lib/Alchemy/Phrasea/Authentication/Provider/Openid.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,14 @@ public function onCallback(Request $request)
$userName = $data['email'];// login to be an email
}

$usegroups = isset($this->config['usegroups']) ? $this->config['usegroups'] : false;
$userUA = $this->CreateUser([
'id' => $distantUserId = $data['sub'],
'login' => $userName,
'firstname' => isset($data['given_name']) ? $data['given_name'] : '',
'lastname' => isset($data['family_name']) ? $data['family_name'] : '' ,
'email' => isset($data['email']) ? $data['email'] : '',
'_groups' => isset($data['groups']) ? $data['groups'] : ''
'_groups' => isset($data['groups']) && $usegroups ? $data['groups'] : ''
]);

$userAuthProviderRepository = $this->getUsrAuthProviderRepository();
Expand Down Expand Up @@ -488,8 +489,8 @@ private function CreateUser(Array $data)
$this->debug(sprintf("found user \"%s\" with id=%s \n", $login, $userUA->getId()));

// if the id provider does NOT return groups, the new user will get "birth" privileges
if (!is_array($data['_groups']) && array_key_exists('birth-group', $this->config)) {
$data['_groups'] = [$this->config['birth-group']];
if (!is_array($data['_groups']) && array_key_exists('birth-group', $this->config) && trim($this->config['birth-group']) !== '') {
$data['_groups'] = [trim($this->config['birth-group'])];
}
}
else {
Expand Down Expand Up @@ -534,8 +535,8 @@ private function CreateUser(Array $data)
}

// add "everyone-group"
if(array_key_exists('everyone-group', $this->config)) {
$models[] = ['name' => $this->config['model-gpfx'] . $this->config['everyone-group'], 'autocreate' => true];
if(array_key_exists('everyone-group', $this->config) && trim($this->config['everyone-group']) !== '') {
$models[] = ['name' => $this->config['model-gpfx'] . trim($this->config['everyone-group']), 'autocreate' => true];
}

// add a specific model for the user
Expand Down
65 changes: 65 additions & 0 deletions lib/classes/patch/4111PHRAS4106.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;

class patch_4111PHRAS4106 implements patchInterface
{
/** @var string */
private $release = '4.1.11';

/** @var array */
private $concern = [base::APPLICATION_BOX];

/**
* Returns the release version.
*
* @return string
*/
public function get_release()
{
return $this->release;
}
/**
* {@inheritdoc}
*/
public function concern()
{
return $this->concern;
}
/**
* {@inheritdoc}
*/
public function require_all_upgrades()
{
return false;
}
/**
* {@inheritdoc}
*/
public function getDoctrineMigrations()
{
return [];
}
/**
* {@inheritdoc}
*/
public function apply(base $appbox, Application $app)
{
/** @var PropertyAccess $conf */
$conf = $app['conf'];
foreach ($app['conf']->get(['authentication', 'providers'], []) as $providerId => $data) {
if ($data['type'] === "openid") {
if(!isset($data['options']['usegroups'])) {
$data['options']['usegroups'] = false;

$providerConfig[$providerId] = $data;

$conf->merge(['authentication', 'providers'], $providerConfig);
}
}
}

return true;
}
}
1 change: 1 addition & 0 deletions lib/conf.d/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ authentication:
realm-name: phrasea
exclusive: false
icon-uri: null
usegroups: false
birth-group: _firstlog
everyone-group: _everyone
metamodel: _metamodel
Expand Down
Loading