Skip to content
Snippets Groups Projects
Commit 5ace1db2 authored by Sergio Gómez's avatar Sergio Gómez Committed by Tim van Dijen
Browse files

Refactorized core module controller and routes

parent 9edb0a7b
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="false"/>
<service id="SimpleSAML\Configuration">
<factory class="SimpleSAML\Configuration" method="getInstance" />
</service>
<service id="SimpleSAML\Session">
<factory class="SimpleSAML\Session" method="getSessionFromRequest" />
</service>
<service class="SimpleSAML\Auth\AuthenticationFactory">
<argument type="service" id="SimpleSAML\Configuration"/>
</service>
</services>
</container>
core-login: core-login:
path: /login/{as} path: /login/{as}
defaults: { _controller: 'SimpleSAML\Module\core\Controller::login', as: null } defaults: { _controller: 'SimpleSAML\Module\core\Controller\LoginController:login', as: null }
core-account: core-account:
path: /account/{as} path: /account/{as}
defaults: { _controller: 'SimpleSAML\Module\core\Controller::account' } defaults: { _controller: 'SimpleSAML\Module\core\Controller\LoginController:account' }
core-logout: core-logout:
path: /logout/{as} path: /logout/{as}
defaults: { _controller: 'SimpleSAML\Module\core\Controller::logout' } defaults: { _controller: 'SimpleSAML\Module\core\Controller\LoginController:logout' }
<?php <?php
namespace SimpleSAML\Module\core; namespace SimpleSAML\Module\core\Controller;
use SimpleSAML\Auth; use SimpleSAML\Auth;
use SimpleSAML\Auth\AuthenticationFactory; use SimpleSAML\Auth\AuthenticationFactory;
...@@ -21,7 +21,7 @@ use Symfony\Component\HttpFoundation\Request; ...@@ -21,7 +21,7 @@ use Symfony\Component\HttpFoundation\Request;
* *
* @package SimpleSAML\Module\core * @package SimpleSAML\Module\core
*/ */
class Controller class LoginController
{ {
/** @var \SimpleSAML\Configuration */ /** @var \SimpleSAML\Configuration */
protected $config; protected $config;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<ul class="pure-menu-list auth_methods"> <ul class="pure-menu-list auth_methods">
{% for id, config in sources -%} {% for id, config in sources -%}
<li class="pure-menu-item"> <li class="pure-menu-item">
<a href="/{{ baseurlpath }}module.php/core/login/{{ id|url_encode }}" class="pure-menu-link"> <a href="{{ moduleURL('core/login/' ~ id|url_encode ) }}" class="pure-menu-link">
{{ config.name|translateFromArray|default(id) }} {{ config.name|translateFromArray|default(id) }}
</a> </a>
</li> </li>
......
<?php <?php
namespace SimpleSAML\Test\Module\core; namespace SimpleSAML\Test\Module\core\Controller;
use SimpleSAML\Auth\Simple; use SimpleSAML\Auth\Simple;
use SimpleSAML\Auth\AuthenticationFactory; use SimpleSAML\Auth\AuthenticationFactory;
...@@ -8,7 +8,7 @@ use SimpleSAML\Configuration; ...@@ -8,7 +8,7 @@ use SimpleSAML\Configuration;
use SimpleSAML\Error\Exception; use SimpleSAML\Error\Exception;
use SimpleSAML\HTTP\RunnableResponse; use SimpleSAML\HTTP\RunnableResponse;
use SimpleSAML\Locale\Localization; use SimpleSAML\Locale\Localization;
use SimpleSAML\Module\core\Controller; use SimpleSAML\Module\core\Controller\LoginController;
use SimpleSAML\Session; use SimpleSAML\Session;
use SimpleSAML\Test\Utils\ClearStateTestCase; use SimpleSAML\Test\Utils\ClearStateTestCase;
use SimpleSAML\XHTML\Template; use SimpleSAML\XHTML\Template;
...@@ -23,7 +23,7 @@ use Symfony\Component\HttpFoundation\Request; ...@@ -23,7 +23,7 @@ use Symfony\Component\HttpFoundation\Request;
* *
* @package SimpleSAML\Test * @package SimpleSAML\Test
*/ */
class ControllerTest extends ClearStateTestCase class LoginControllerTest extends ClearStateTestCase
{ {
/** @var array */ /** @var array */
protected $authSources; protected $authSources;
...@@ -34,10 +34,6 @@ class ControllerTest extends ClearStateTestCase ...@@ -34,10 +34,6 @@ class ControllerTest extends ClearStateTestCase
/** @var \SimpleSAML\Configuration[] */ /** @var \SimpleSAML\Configuration[] */
protected $loadedConfigs; protected $loadedConfigs;
/** @var \SimpleSAML\HTTP\Router */
protected $router;
/** /**
* Set up for each test. * Set up for each test.
* @return void * @return void
...@@ -83,8 +79,8 @@ class ControllerTest extends ClearStateTestCase ...@@ -83,8 +79,8 @@ class ControllerTest extends ClearStateTestCase
$session = Session::getSessionFromRequest(); $session = Session::getSessionFromRequest();
$factory = new AuthenticationFactory($this->config, $session); $factory = new AuthenticationFactory($this->config, $session);
$c = new Controller($this->config, $session, $factory);
/** @var \SimpleSAML\HTTP\RunnableResponse $response */ /** @var \SimpleSAML\HTTP\RunnableResponse $response */
$c = new LoginController($this->config, $session, $factory);
$response = $c->login($request); $response = $c->login($request);
$this->assertInstanceOf(RunnableResponse::class, $response); $this->assertInstanceOf(RunnableResponse::class, $response);
...@@ -122,8 +118,8 @@ class ControllerTest extends ClearStateTestCase ...@@ -122,8 +118,8 @@ class ControllerTest extends ClearStateTestCase
$session = Session::getSessionFromRequest(); $session = Session::getSessionFromRequest();
$factory = new AuthenticationFactory($this->config, $session); $factory = new AuthenticationFactory($this->config, $session);
$c = new Controller($this->config, $session, $factory);
/** @var \SimpleSAML\XHTML\Template $response */ /** @var \SimpleSAML\XHTML\Template $response */
$c = new LoginController($this->config, $session, $factory);
$response = $c->login($request); $response = $c->login($request);
$this->assertInstanceOf(Template::class, $response); $this->assertInstanceOf(Template::class, $response);
...@@ -145,8 +141,8 @@ class ControllerTest extends ClearStateTestCase ...@@ -145,8 +141,8 @@ class ControllerTest extends ClearStateTestCase
$request = new Request(); $request = new Request();
$session = Session::getSessionFromRequest(); $session = Session::getSessionFromRequest();
$factory = new AuthenticationFactory($this->config, $session); $factory = new AuthenticationFactory($this->config, $session);
$c = new Controller($this->config, $session, $factory); $c = new LoginController($this->config, $session, $factory);
$this->expectException(Exception::class); $this->setExpectedException(Exception::class);
$c->login($request, 'invalid-auth-source'); $c->login($request, 'invalid-auth-source');
} }
...@@ -178,10 +174,10 @@ class ControllerTest extends ClearStateTestCase ...@@ -178,10 +174,10 @@ class ControllerTest extends ClearStateTestCase
]); ]);
$factory = new AuthenticationFactory($this->config, $session); $factory = new AuthenticationFactory($this->config, $session);
$c = new Controller($this->config, $session, $factory);
$request = new Request(); $request = new Request();
/** @var \Symfony\Component\HttpFoundation\RedirectResponse $response */ /** @var \Symfony\Component\HttpFoundation\RedirectResponse $response */
$c = new LoginController($this->config, $session, $factory);
$response = $c->login($request); $response = $c->login($request);
$this->assertInstanceOf(RedirectResponse::class, $response); $this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertEquals( $this->assertEquals(
...@@ -201,7 +197,7 @@ class ControllerTest extends ClearStateTestCase ...@@ -201,7 +197,7 @@ class ControllerTest extends ClearStateTestCase
Configuration::setPreLoadedConfig($asConfig, 'authsources.php'); Configuration::setPreLoadedConfig($asConfig, 'authsources.php');
$session = Session::getSessionFromRequest(); $session = Session::getSessionFromRequest();
$factory = new AuthenticationFactory($this->config, $session); $factory = new AuthenticationFactory($this->config, $session);
$c = new Controller($this->config, $session, $factory); $c = new LoginController($this->config, $session, $factory);
$response = $c->logout('example-userpass'); $response = $c->logout('example-userpass');
$this->assertInstanceOf(RunnableResponse::class, $response); $this->assertInstanceOf(RunnableResponse::class, $response);
list($object, $method) = $response->getCallable(); list($object, $method) = $response->getCallable();
...@@ -222,7 +218,7 @@ class ControllerTest extends ClearStateTestCase ...@@ -222,7 +218,7 @@ class ControllerTest extends ClearStateTestCase
Configuration::setPreLoadedConfig($asConfig, 'authsources.php'); Configuration::setPreLoadedConfig($asConfig, 'authsources.php');
$session = Session::getSessionFromRequest(); $session = Session::getSessionFromRequest();
$factory = new AuthenticationFactory($this->config, $session); $factory = new AuthenticationFactory($this->config, $session);
$c = new Controller($this->config, $session, $factory); $c = new LoginController($this->config, $session, $factory);
/** @var RedirectResponse $response */ /** @var RedirectResponse $response */
$response = $c->account('example-userpass'); $response = $c->account('example-userpass');
$this->assertInstanceOf(RedirectResponse::class, $response); $this->assertInstanceOf(RedirectResponse::class, $response);
...@@ -255,7 +251,7 @@ class ControllerTest extends ClearStateTestCase ...@@ -255,7 +251,7 @@ class ControllerTest extends ClearStateTestCase
] ]
]); ]);
$factory = new AuthenticationFactory($this->config, $session); $factory = new AuthenticationFactory($this->config, $session);
$c = new Controller($this->config, $session, $factory); $c = new LoginController($this->config, $session, $factory);
/** @var \SimpleSAML\XHTML\Template $response */ /** @var \SimpleSAML\XHTML\Template $response */
$response = $c->account('example-userpass'); $response = $c->account('example-userpass');
$this->assertInstanceOf(Template::class, $response); $this->assertInstanceOf(Template::class, $response);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment