Skip to content
Snippets Groups Projects
Unverified Commit c90d80ca authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo
Browse files

Start using the authentication factory.

parent 56c6228a
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace SimpleSAML; namespace SimpleSAML;
use SimpleSAML\Auth\AuthenticationFactory;
use SimpleSAML\Error\Exception; use SimpleSAML\Error\Exception;
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException; use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
...@@ -60,6 +61,7 @@ class ModuleControllerResolver extends ControllerResolver implements ArgumentRes ...@@ -60,6 +61,7 @@ class ModuleControllerResolver extends ControllerResolver implements ArgumentRes
$this->argFactory = new ArgumentMetadataFactory(); $this->argFactory = new ArgumentMetadataFactory();
$this->container = new ContainerBuilder(); $this->container = new ContainerBuilder();
$this->container->autowire(AuthenticationFactory::class, AuthenticationFactory::class);
try { try {
$this->routes = $loader->load('routes.yaml'); $this->routes = $loader->load('routes.yaml');
......
...@@ -21,6 +21,9 @@ class Controller ...@@ -21,6 +21,9 @@ class Controller
/** @var \SimpleSAML\Configuration */ /** @var \SimpleSAML\Configuration */
protected $config; protected $config;
/** @var \SimpleSAML\Auth\AuthenticationFactory */
protected $factory;
/** @var \SimpleSAML\Session */ /** @var \SimpleSAML\Session */
protected $session; protected $session;
...@@ -33,14 +36,19 @@ class Controller ...@@ -33,14 +36,19 @@ class Controller
* *
* It initializes the global configuration and auth source configuration for the controllers implemented here. * It initializes the global configuration and auth source configuration for the controllers implemented here.
* *
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers. * @param \SimpleSAML\Configuration $config The configuration to use by the controllers.
* @param \SimpleSAML\Session $session The session to use by the controllers. * @param \SimpleSAML\Session $session The session to use by the controllers.
* @param \SimpleSAML\Auth\AuthenticationFactory $factory A factory to instantiate \SimpleSAML\Auth\Simple objects.
* *
* @throws \Exception * @throws \Exception
*/ */
public function __construct(\SimpleSAML\Configuration $config, \SimpleSAML\Session $session) public function __construct(
{ \SimpleSAML\Configuration $config,
\SimpleSAML\Session $session,
\SimpleSAML\Auth\AuthenticationFactory $factory
) {
$this->config = $config; $this->config = $config;
$this->factory = $factory;
$this->sources = $config::getOptionalConfig('authsources.php')->toArray(); $this->sources = $config::getOptionalConfig('authsources.php')->toArray();
$this->session = $session; $this->session = $session;
} }
...@@ -62,7 +70,7 @@ class Controller ...@@ -62,7 +70,7 @@ class Controller
throw new Exception('Invalid authentication source'); throw new Exception('Invalid authentication source');
} }
$auth = new \SimpleSAML\Auth\Simple($as); $auth = $this->factory->create($as);
if (!$auth->isAuthenticated()) { if (!$auth->isAuthenticated()) {
// not authenticated, start auth with specified source // not authenticated, start auth with specified source
return new RedirectResponse(\SimpleSAML\Module::getModuleURL('core/login/'.urlencode($as))); return new RedirectResponse(\SimpleSAML\Module::getModuleURL('core/login/'.urlencode($as)));
...@@ -122,7 +130,7 @@ class Controller ...@@ -122,7 +130,7 @@ class Controller
} }
// at this point, we have a valid auth source selected, start auth // at this point, we have a valid auth source selected, start auth
$auth = new \SimpleSAML\Auth\Simple($as); $auth = $this->factory->create($as);
$as = urlencode($as); $as = urlencode($as);
if ($request->get(\SimpleSAML\Auth\State::EXCEPTION_PARAM, false) !== false) { if ($request->get(\SimpleSAML\Auth\State::EXCEPTION_PARAM, false) !== false) {
...@@ -160,7 +168,7 @@ class Controller ...@@ -160,7 +168,7 @@ class Controller
*/ */
public function logout($as) public function logout($as)
{ {
$as = new \SimpleSAML\Auth\Simple($as); $auth = new \SimpleSAML\Auth\Simple($as);
return new RunnableResponse([$as, 'logout'], [$this->config->getBasePath().'logout.php']); return new RunnableResponse([$auth, 'logout'], [$this->config->getBasePath().'logout.php']);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment