FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

PoC new Module system to SSP 2.0 by sgomez · Pull Request #1294 · simplesamlphp/simplesamlphp · GitHub

PoC new Module system to SSP 2.0 - #1294

Open
sgomez wants to merge 3 commits into
simplesamlphp:masterfrom
sgomez:module-base
Open

PoC new Module system to SSP 2.0#1294
sgomez wants to merge 3 commits into
simplesamlphp:masterfrom
sgomez:module-base

Conversation

sgomez commented Feb 26, 2020

Copy link
Copy Markdown
Contributor

This PR is related to #1286 issue.

Changes:

  • www/new.php is created to load new kernel. Also console has been changed to load the new kernel.
  • Old kernel renamed to ModuleKernel.php to indicate than only works with one module.
  • New kernel to load all modules and core application.

Instructions:

  1. APP_ENV=dev environment variable must be configured
  2. Run composer install. This will install [a demo module](https://packagist.org/packages/sgomez/simplesamlphp-module-expirycheck.
  3. Copy modules.php inside config-templates to config directory.

I have this authsource to check the module:

    'example-static' => [
        'exampleauth:StaticSource',
        'uid' => ['testuser'],
        'eduPersonAffiliation' => ['member', 'employee'],
        'cn' => ['Test User'],
        'schacExpiryDate' => '20051231235959Z'
    ],

And this filter:

        10 => array(
            'class' => SimpleSAML\Modules\ExpiryCheckModule\Auth\Process\ExpiryDate::class,
            'netid_attr' => 'eduPersonPrincipalName',
            'expirydate_attr' => 'schacExpiryDate',
            'warndaysbefore' => '60',
            'date_format' => 'd.m.Y', # php date syntax
        ),

The idea is to run the ExpiredController and load templates and translation from vendor without install the modules inside simplesamlphp directory.

More explanations in the code.

@@ -0,0 +1,11 @@
<?php

return [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This file returns all modules/bundles to be loaded. The kernel supports environments, so we can indicate if they should be loaded in all or just in a few of them.


return [
// Don't remove this bundles
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Probably FrameworkBundle is too huge to be used and we can create a custom one.

Comment thread lib/SimpleSAML/Kernel.php Outdated
/**
* @param string $module
*/
public function __construct(string $module)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

New Kernel is not just for one module.

Comment thread lib/SimpleSAML/Kernel.php
$confDir = Module::getModuleDir($this->module) . '/routing/services';
if (is_dir($confDir)) {
$loader->load($confDir . '/**/*' . self::CONFIG_EXTS, 'glob');
foreach ($this->bundles as $bundle) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This iterator search in all bundles the ones that are SSP Modules and checks if they have a routes directory (and load the route files). The module name is used a prefix to the url.

Comment thread lib/SimpleSAML/Kernel.php
}
$confDir = __DIR__ . '/Resources/config';

$routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Load routes required by simplesaml to work. For example the route required to have the debug toolbar.

Comment thread lib/SimpleSAML/Kernel.php Outdated
* @return void
*/
private function registerModuleControllers(ContainerBuilder $container): void
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Load services required by the core of simplesaml (modules services are loaded inside the Module loader class).

use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\HttpKernel\Bundle\Bundle;

abstract class Module extends Bundle

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This abstract class extends from Symfony Bundle abstract class. So a module is a bundle. Probably we can create a thin abstract class because we don't require all the logic inside the base class.

{
abstract public function getShortName(): string;

public function build(ContainerBuilder $container)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This method is called when the cache is warmed. Here we can define the services this module will use.

* @param ContainerBuilder $container
* @return void
*/
private function registerModuleControllers(ContainerBuilder $container): void

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We register controller services. The idea is to create similar methods for each service we want to define automatically (hooks/events, admin menus, etc.). The possibility to use a services.yml to load custom services will be available. But this methods exists to do the module development easiest.

$baseDir = $this->configuration->getBaseDir();
if (is_null($module)) {
$file = $baseDir . 'www/assets/' . $asset;
$file = $baseDir . 'www/' . $asset;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I use symfony/asset module that implements asset function in twig. This modification is to have the same behaviour in the old a new way to read templates.

sgomez commented Feb 26, 2020

Copy link
Copy Markdown
Contributor Author

Translations in symfony supports a lot of loaders (po, yaml, xliff, csv, ...). Gettext loader (po files) does not require gettext php module (apparently, I will investigate more about this).

There are a difference. The structure of translations files change from locales/LANGCODE/LC_MESSAGES/module.po to translations/module.LANGCODE.po. With a script is easy to move files. But trans function in yaml files requires that we indicate the module if it is differente from default (messages).

tvdijen marked this pull request as ready for review May 1, 2020 17:08

tvdijen commented May 1, 2020

Copy link
Copy Markdown
Member

Oops, I did not intend to do this, but @sgomez should this be merged at some point? Let's not let this go to waste..

sgomez commented May 4, 2020

Copy link
Copy Markdown
Contributor Author

Hi @tvdijen

This is just a PoC. This requires a lot of discussion because is a huge change in the way modules are loaded.

tvdijen force-pushed the master branch 3 times, most recently from 1c686ab to eb20457 Compare August 17, 2020 20:43
tvdijen force-pushed the master branch 2 times, most recently from 08ebb9c to 64fca25 Compare July 2, 2021 14:12
tvdijen added a commit to tvdijen/simplesamlphp-module-expirycheck that referenced this pull request Sep 8, 2021

tvdijen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The RouteCollectionBuilder was deprecated by Symfony in favour of the RoutingConfigurator.
Unfortunately I can't get it to work with the new class and I don't know what to do with the $prefix variable.

tvdijen force-pushed the master branch 2 times, most recently from 7a53fc8 to d73ae47 Compare September 26, 2021 13:03
tvdijen force-pushed the master branch 11 times, most recently from 7b173cf to 3326beb Compare March 20, 2023 22:59
tvdijen force-pushed the master branch 2 times, most recently from 8ac729b to a16cf6e Compare April 25, 2023 08:33
tvdijen force-pushed the master branch 2 times, most recently from fc454de to 7ac76ae Compare May 3, 2023 08:31
tvdijen force-pushed the master branch 6 times, most recently from 29f7b69 to 1a911ce Compare May 12, 2023 16:07
tvdijen force-pushed the master branch 3 times, most recently from c7c8357 to fdbe001 Compare June 12, 2023 14:28
tvdijen force-pushed the master branch 6 times, most recently from b639fc0 to a6df6e9 Compare July 19, 2023 12:19
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL