Files
Phraseanet/lib/Alchemy/Phrasea/Authentication/Provider/Factory.php
jygaulier 7e7435469d PHRAS-2995_phr-as-auth-idp-BIS (#4180)
* WIP ; allow multiple instances of some auth clients (migrate conf) ; add ps-oauth ; remove google+

* WIP ; fix ps-oauth ; fix tests

* WIP ; add api-auth to extra_hosts

* WIP ; fix yaml syntax error

* WIP ; fix yaml syntax error ; better conf sample

* WIP ; add "everyone-group"

* WIP ; add the provider-id in session

* WIP ; add getOptions() to providers (so phr/expose can filter providers)

* WIP ; add auto-logout option so logout from phr also logouts from ps-auth

* connect to expose using IDP from connected user

* WIP ; auto-logout redirects to phr home

* unnecessary session var

* unused

* fix

* catch some error

* fix navigation in train thumbnail

* update file version

* pass params in session to have constant redirect_uri ; add debug

* invalidate session --> parade test ok

* cleanup
2022-12-01 16:27:54 +01:00

93 lines
2.6 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Authentication\Provider;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Model\Manipulator\UserManipulator;
use Alchemy\Phrasea\Model\Repositories\UserRepository;
use appbox;
use RandomLib\Generator as RandomGenerator;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGenerator;
class Factory
{
private $generator;
private $session;
/**
* @var UserManipulator
*/
private $userManipulator;
/**
* @var UserRepository
*/
private $userRepository;
/**
* @var ACLProvider
*/
private $ACLProvider;
/**
* @var appbox
*/
private $appbox;
/**
* @var RandomGenerator
*/
private $randomGenerator;
public function __construct(UrlGenerator $generator, SessionInterface $session,
UserManipulator $userManipulator, UserRepository $userRepository,
ACLProvider $ACLProvider, appbox $appbox, RandomGenerator $randomGenerator
)
{
$this->generator = $generator;
$this->session = $session;
$this->userManipulator = $userManipulator;
$this->userRepository = $userRepository;
$this->ACLProvider = $ACLProvider;
$this->appbox = $appbox;
$this->randomGenerator = $randomGenerator;
}
public function build(string $id, string $type, bool $display, string $title, array $options = [])
{
$type = implode('', array_map(function ($chunk) {
return ucfirst(strtolower($chunk));
}, explode('-', $type)));
$class_name = sprintf('%s\\%s', __NAMESPACE__, $type);
if (!class_exists($class_name)) {
throw new InvalidArgumentException(sprintf('Invalid provider %s', $type));
}
/** @var AbstractProvider $o */
$o = $class_name::create($this->generator, $this->session, $options); // v1 bc compat : can't change
$o->setId($id);
$o->setDisplay($display);
$o->setTitle($title);
$o->setOptions($options);
$o->setUserManipulator($this->userManipulator);
$o->setUserRepository($this->userRepository);
$o->setACLProvider($this->ACLProvider);
$o->setAppbox($this->appbox);
$o->setRandomGenerator($this->randomGenerator);
return $o;
}
}