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

PoC new Module system to SSP 2.0 #1294

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sgomez
Copy link
Contributor

@sgomez sgomez commented Feb 26, 2020

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
Contributor Author

Choose a reason for hiding this comment

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

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
Contributor Author

Choose a reason for hiding this comment

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

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

/**
* @param string $module
*/
public function __construct(string $module)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New Kernel is not just for one module.

$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
Contributor Author

Choose a reason for hiding this comment

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

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.


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

Choose a reason for hiding this comment

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

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

* @return void
*/
private function registerModuleControllers(ContainerBuilder $container): void
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Contributor Author

Choose a reason for hiding this comment

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

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
Contributor Author

Choose a reason for hiding this comment

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

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
Contributor Author

Choose a reason for hiding this comment

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

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.

@@ -162,12 +162,12 @@ public function asset(string $asset, string $module = null): string
{
$baseDir = $this->configuration->getBaseDir();
if (is_null($module)) {
$file = $baseDir . 'www/assets/' . $asset;
$file = $baseDir . 'www/' . $asset;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

sgomez commented Feb 26, 2020

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 tvdijen marked this pull request as ready for review May 1, 2020 17:08
@tvdijen
Copy link
Member

tvdijen commented May 1, 2020

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
Copy link
Contributor Author

sgomez commented May 4, 2020

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 added a commit to tvdijen/simplesamlphp-module-expirycheck that referenced this pull request Sep 8, 2021
Copy link
Member

@tvdijen tvdijen left a comment

Choose a reason for hiding this comment

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

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 tvdijen force-pushed the master branch 2 times, most recently from 7a53fc8 to d73ae47 Compare September 26, 2021 13:03
@tvdijen tvdijen force-pushed the master branch 4 times, most recently from 29f7b69 to 1a911ce Compare May 12, 2023 16:07
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from c7c8357 to fdbe001 Compare June 12, 2023 14:28
@tvdijen tvdijen force-pushed the master branch 8 times, most recently from 3b5f5ba to 96357ee Compare July 19, 2023 12:37
@tvdijen tvdijen force-pushed the master branch 5 times, most recently from 7587851 to d523b31 Compare August 2, 2023 11:58
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from 8c90121 to d534e3b Compare September 5, 2023 08:09
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from bc1c5c8 to d0a5974 Compare October 17, 2023 21:17
@tvdijen tvdijen force-pushed the master branch 3 times, most recently from ccb9b02 to 120a100 Compare December 1, 2023 14:34
@tvdijen tvdijen force-pushed the master branch 2 times, most recently from 6004a77 to 58bf8db Compare May 4, 2024 23:45
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.

None yet

2 participants