From 6ae2d7f97252d9325a0245e26a13d74d35edcd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez=20Crespo?= <jaime.perez@uninett.no> Date: Wed, 17 Oct 2018 15:48:06 +0200 Subject: [PATCH] Create an AuthenticationFactory that allows us to create SimpleSAML\Auth\Simple objects. This is needed to allow dependency injection in that class. Since the first parameter of the constructor is the ID of the auth source to use, we don't know the value it must take during compilation of the container. We only know what auth source to use when we are in the controller, becase at that point the URL as been parsed and the auth source ID has been passed to the controller as an argument. Therefore, we need to add this factory class as a service to the container, and once we have the auth source ID, we can call the create() method of the factory to obtain a relevant instance of \SimpleSAML\Auth\Simple. --- lib/SimpleSAML/Auth/AuthenticationFactory.php | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/SimpleSAML/Auth/AuthenticationFactory.php diff --git a/lib/SimpleSAML/Auth/AuthenticationFactory.php b/lib/SimpleSAML/Auth/AuthenticationFactory.php new file mode 100644 index 000000000..7335bc2d5 --- /dev/null +++ b/lib/SimpleSAML/Auth/AuthenticationFactory.php @@ -0,0 +1,37 @@ +<?php + +namespace SimpleSAML\Auth; + +/** + * Factory class to get instances of \SimpleSAML\Auth\Simple for a given authentication source. + */ +class AuthenticationFactory +{ + + /** @var \SimpleSAML\Configuration */ + protected $config; + + /** @var \SimpleSAML\Session */ + protected $session; + + + public function __construct(\SimpleSAML\Configuration $config, \SimpleSAML\Session $session) + { + $this->config = $config; + $this->session = $session; + } + + + /** + * Create a new instance of \SimpleSAML\Auth\Simple for the given authentication source. + * + * @param string $as The identifier of the authentication source, as indexed in the authsources.php configuration + * file. + * + * @return \SimpleSAML\Auth\Simple + */ + public function create($as) + { + return new Simple($as, $this->config, $this->session); + } +} \ No newline at end of file -- GitLab