-
Notifications
You must be signed in to change notification settings - Fork 2
Idp manager #32
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
Open
nworr
wants to merge
4
commits into
jelix:accounts
Choose a base branch
from
nworr:idp-manager
base: accounts
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Idp manager #32
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <?php | ||
|
|
||
| use Jelix\Authentication\AuthAdmin\IdpFinder; | ||
| use Jelix\IniFile\IniModifier; | ||
|
|
||
| class idpadminCtrl extends jController | ||
| { | ||
| public $pluginParams = [ | ||
| '*' => array('auth.required' => false, 'jacl2.right' => 'auth.idpadmin.view'), | ||
| 'save' => array('jacl2.right' => 'auth.idpadmin.edit'), | ||
| ]; | ||
|
|
||
| private $idpList ; | ||
|
|
||
| public function __construct(jRequest $req) | ||
| { | ||
| $idpFinder = new IdpFinder(); | ||
| $this->idpList = $idpFinder->findAllIDP(); | ||
| parent::__construct($req); | ||
| } | ||
|
|
||
| public function index() | ||
| { | ||
| $resp = $this->getResponse('html'); | ||
| // build form | ||
| $form = jForms::create('authadmin~idp'); | ||
| $this->buildForm($form); | ||
| foreach($this->idpList as $idpInfo) { | ||
| $form->setData('chck_'.$idpInfo[0], $idpInfo[1]); | ||
| } | ||
| $tpl = new jTpl(); | ||
| $tpl->assign('idps', $this->idpList); | ||
| $tpl->assign('form', $form); | ||
| $resp->body->assign('MAIN', $tpl->fetch('idp.list')); | ||
|
|
||
| return $resp; | ||
| } | ||
|
|
||
| public function prepareEdit() | ||
| { | ||
| $form = jForms::create('authadmin~idp'); | ||
| $this->buildForm($form); | ||
| foreach($this->idpList as $idpInfo) { | ||
| $form->setData('chck_'.$idpInfo[0], $idpInfo[1]); | ||
| } | ||
| return $this->redirect('authadmin~idpadmin:showEdit'); | ||
| } | ||
|
|
||
| public function showEdit() | ||
| { | ||
| $form = jForms::get('authadmin~idp'); | ||
| if(is_null($form)) { | ||
| return $this->redirect('authadmin~idpadmin:prepareEdit'); | ||
| } | ||
| $this->buildForm($form); | ||
| $resp = $this->getResponse('html'); | ||
|
|
||
| $tpl = new jTpl(); | ||
| $tpl->assign('idps', $this->idpList); | ||
| $tpl->assign('form', $form); | ||
| $resp->body->assign('MAIN', $tpl->fetch('idp.edit')); | ||
|
|
||
| return $resp; | ||
| } | ||
|
|
||
| public function save() | ||
| { | ||
| $modif = new IniModifier(jApp::varConfigPath('liveconfig.ini.php')); | ||
|
|
||
| // build form | ||
| $form = jForms::get('authadmin~idp'); | ||
| $this->buildForm($form); | ||
| $form->initFromRequest(); | ||
|
|
||
| if(!$form->check()) { | ||
| return $this->redirect('authadmin~idpadmin:showEdit'); | ||
| } | ||
|
|
||
| $enabledIdp = []; | ||
| foreach($this->idpList as $idp) { | ||
| $name = $idp[0]; | ||
| if ($form->getData('chck_'.$name) == 1) { | ||
| $enabledIdp[] = $name; | ||
| } | ||
| } | ||
| $sessionIdp = jAuthentication::session()->getIdentityProviderId(); | ||
| if (!in_array($sessionIdp, $enabledIdp)) { | ||
| $form->setErrorOn('chck_'.$name, jLocale::get('default.form.error.session.idp.disabling.forbidden')); | ||
| return $this->redirect('authadmin~idpadmin:showEdit'); | ||
| } | ||
| $modif->setValues(['idp' => $enabledIdp], 'authentication'); | ||
| $modif->save(); | ||
| jForms::destroy('authadmin~idp'); | ||
|
|
||
| return $this->redirect('authadmin~idpadmin:index'); | ||
| } | ||
|
|
||
| protected function buildForm(jFormsBase $form) | ||
| { | ||
| foreach($this->idpList as $idpInfo) { | ||
| $name = $idpInfo[0]; | ||
| $ctrlStatus = new jFormsControlCheckbox('chck_'.$name); | ||
| $ctrlStatus->label = $name; | ||
| $ctrlStatus->valueLabelOnCheck = jLocale::get('jelix~ui.buttons.enabled'); | ||
| $ctrlStatus->valueLabelOnUncheck = jLocale::get('jelix~ui.buttons.disabled'); | ||
| $form->addControl($ctrlStatus); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <events xmlns="http://jelix.org/ns/events/1.0"> | ||
| <listener name="\Jelix\Authentication\AuthAdmin\AdminUiEventListener"> | ||
| <event name="adminui.loading" /> | ||
| </listener> | ||
| </events> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <form xmlns="http://jelix.org/ns/forms/1.1"> | ||
| <submit ref="submit"> | ||
| <label locale="account~account.profile.button.modify"/> | ||
| </submit> | ||
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| use Jelix\Installer\Module\API\InstallHelpers; | ||
| use Jelix\Installer\Module\Installer; | ||
|
|
||
| class authadminModuleInstaller extends Installer | ||
| { | ||
| public function install(InstallHelpers $helpers) | ||
| { | ||
| $groupName = 'auth.idpadmin.subject.group'; | ||
| // Add rights group | ||
| jAcl2DbManager::createRightGroup($groupName, 'authadmin~default.rights.group.name'); | ||
|
|
||
| // Add right subject | ||
| jAcl2DbManager::createRight('auth.idpadmin.view', 'authadmin~default.idp.view', $groupName); | ||
| jAcl2DbManager::createRight('auth.idpadmin.edit', 'authadmin~default.idp.edit', $groupName); | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| namespace Jelix\Authentication\AuthAdmin; | ||
|
|
||
| use jAcl2; | ||
| use Jelix\AdminUI\SideBar\SubMenu; | ||
| use jEventListener; | ||
| use jLocale; | ||
|
|
||
| class AdminUiEventListener extends jEventListener | ||
| { | ||
| protected $eventMapping = array( | ||
| 'adminui.loading' => 'onAdminUILoading', | ||
| ); | ||
|
|
||
| /** | ||
| * @param jEvent $event | ||
| */ | ||
| public function onAdminUILoading($event) | ||
| { | ||
| if(jAcl2::check('auth.idpadmin.view')) { | ||
| /** @var \Jelix\AdminUI\UIManager $uim */ | ||
| $uim = $event->uiManager; | ||
|
|
||
| $adminMenu = new SubMenu('admin', 'Authentification', 10); | ||
| $adminMenu->addJelixLinkItem(jLocale::get('authadmin~default.navigation.menu.idp'), 'authadmin~idpadmin:index', array(), 'address-book'); | ||
| $uim->sidebar()->addMenuItem($adminMenu); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| namespace Jelix\Authentication\AuthAdmin; | ||
|
|
||
| use jAuthentication; | ||
| use Jelix\Authentication\Core\IdentityProviderInterface; | ||
| use jEvent; | ||
|
|
||
| class IdpFinder | ||
| { | ||
| public function findAllIDP() | ||
| { | ||
| // use event to find all existing idp plugin | ||
| $allIdpResponse = jEvent::notify('AuthAdminGetIDPPlugin')->getResponse(); | ||
| $authManager = jAuthentication::manager(); | ||
| $enabledIdps = $authManager->getIdpList(); | ||
| $enabledIdpNames = array_map(function (IdentityProviderInterface $idp) {return $idp->getId();}, $enabledIdps); | ||
| $allIdpName = []; | ||
| foreach($allIdpResponse as $idpInfo) { | ||
| if (array_key_exists('pluginName', $idpInfo)) { | ||
| $pluginName = $idpInfo['pluginName']; | ||
| $idpEnabled = (false !== array_search($pluginName, $enabledIdpNames)); | ||
| $allIdpName[] = [$pluginName, $idpEnabled]; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return $allIdpName; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| rights.group.name=Identity providers | ||
| idp.view=View Identity providers | ||
| idp.edit=Edit Identity providers | ||
| navigation.menu.idp=Identity providers | ||
| idp.list.page.title=Installed identity providers | ||
| idp.edit.page.title=Edit identity providers | ||
| form.error.session.idp.disabling.forbidden=You can't disable the idp uses by current session | ||
| table.th.name=Nom | ||
| table.th.status=Status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| rights.group.name=Fournisseurs d'identité | ||
| idp.view=Voir les fournisseurs d'identité | ||
| idp.edit=Modifier les fournisseurs d'identité | ||
| navigation.menu.idp=Fournisseurs d'identité | ||
| idp.list.page.title=Fournisseurs d'identité installés | ||
| idp.edit.page.title=Modifier les fournisseurs d'identité | ||
| form.error.session.idp.disabling.forbidden=Vous ne pouvez pas désactiver le fournisseur utilisé par la session en cours | ||
| table.th.name=Nom | ||
| table.th.status=Status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <module xmlns="http://jelix.org/ns/module/1.0"> | ||
| <info id="authadmin@modules.jelix.org" name="authadmin" createdate="2025-09-08"> | ||
| <version date="2025-06-16">0.0.1</version> | ||
| <label lang="en_US">JelixAuth AuthAdmin</label> | ||
| <description lang="en_US">Module adding administration page for IDP</description> | ||
| <license>MIT</license> | ||
| <copyright>2019-2025 Laurent Jouanneau</copyright> | ||
| <creator name="Laurent Jouanneau" email="laurent@jelix.org"/> | ||
| <homepageURL>https://jelix.org</homepageURL> | ||
| </info> | ||
| <dependencies> | ||
| <jelix minversion="1.8.0" maxversion="1.9.0-beta.1"/> | ||
| <module name="jacl2"/> | ||
| </dependencies> | ||
| <autoload> | ||
| <namespacePathMap name="Jelix\Authentication\AuthAdmin" dir="lib" /> | ||
| </autoload> | ||
| </module> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <h2>{@authadmin~default.idp.edit.page.title@}</h2> | ||
|
|
||
| <div class="card"> | ||
| <div class="card-body"> | ||
| {form $form, 'authadmin~idpadmin:save', [], 'adminlte'} | ||
|
|
||
| {formcontrols} | ||
|
|
||
| <table class="table table-bordered table-striped"> | ||
| <thead> | ||
| <tr><th>{@authadmin~default.table.th.name@}</th> | ||
| <th>{@authadmin~default.table.th.status@}</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {foreach $idps as $idp} | ||
| {assign $ctlName = 'chck_'.$idp[0]} | ||
| <tr> | ||
| <td class="col-sm-4"> | ||
| {$idp[0]} | ||
| </td> | ||
| <td class="col-sm-4"> | ||
| {ctrl_control $ctlName} | ||
| </td> | ||
| </tr> | ||
| {/foreach} | ||
| </tbody> | ||
| </table> | ||
|
|
||
| {/formcontrols} | ||
|
|
||
| <div class="form-group row"> | ||
| <div class="col-sm-10 offset-sm-2 ">{formsubmit}</div> | ||
| </div> | ||
| {/form} | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
|
|
||
| <h2>{@authadmin~default.idp.list.page.title@}</h2> | ||
| <div class="card"> | ||
| <div class="card-body"> | ||
|
|
||
| {formcontrols $form} | ||
|
|
||
| <table class="table table-bordered table-striped"> | ||
| <thead> | ||
| <tr> | ||
| <th>{@authadmin~default.table.th.name@}</th> | ||
| <th>{@authadmin~default.table.th.status@}</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
|
|
||
| {foreach $idps as $idp} | ||
| {assign $ctlName = 'chck_'.$idp[0]} | ||
| <tr> | ||
| <td class="col-sm-4"> | ||
| {$idp[0]} | ||
| </td> | ||
| <td class="col-sm-4"> | ||
| {ctrl_value $ctlName} | ||
| </td> | ||
| </tr> | ||
| {/foreach} | ||
| </tbody> | ||
| </table> | ||
|
|
||
| {/formcontrols} | ||
| {ifacl2 'auth.idpadmin.edit'} | ||
| <a href='{jurl 'authadmin~idpadmin:prepareEdit'}' class='btn btn-primary' >{@jelix~ui.buttons.update@}</a> | ||
| {/ifacl2} | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <suburls xmlns="http://jelix.org/ns/suburls/1.0"> | ||
| <url pathinfo="/list" action="idpadmin:index" /> | ||
| <url pathinfo="/pre" action="idpadmin:prepareEdit" /> | ||
| <url pathinfo="/edit" action="idpadmin:showEdit" /> | ||
| <url pathinfo="/save" action="idpadmin:save" /> | ||
| </suburls> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <events xmlns="http://jelix.org/ns/events/1.0"> | ||
| <listener name="\Jelix\Authentication\LoginPass\AuthCoreEventListener"> | ||
| <event name="AuthAdminGetIDPPlugin" /> | ||
| </listener> | ||
| </events> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| namespace jelix\Authentication\LoginPass; | ||
|
|
||
| use jEventListener; | ||
|
|
||
| class AuthCoreEventListener extends jEventListener | ||
| { | ||
| /** | ||
| * @param jEvent $event | ||
| */ | ||
| public function onAuthAdminGetIDPPlugin($event) | ||
| { | ||
| $event->add(['pluginName' => 'loginpass']); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
je propose de nommer le module
authadminau lieu de idpadmin. Il portera d'autres pages de configuration générale pour l'authentification. Le contrôleur pourrait être nommé idpadmin plutôt que default (à terme default sera plutôt une sorte de page d'accueil de l'admin auth)