Commit 279a6e87 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Revert "Merge remote-tracking branch 'origin/master'"

This reverts commit cb5d0bbf
parent cb5d0bbf
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
<?php

use UnicaenAuth\Authentication\Adapter\ShibSimulatorAdapter;
use UnicaenAuth\Authentication\Storage\ShibSimulatorStorage;
use UnicaenAuth\Controller\AuthControllerFactory;
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\ShibServiceFactory;
use UnicaenAuth\Service\UserContextFactory;
use UnicaenAuth\View\Helper\ShibConnectViewHelperFactory;
use UnicaenAuth\View\Helper\UserUsurpationHelperFactory;

$settings = [
    /**
@@ -376,7 +373,6 @@ return [
            'UnicaenAuth\Authentication\Storage\Db'   => 'UnicaenAuth\Authentication\Storage\Db',
            'UnicaenAuth\Authentication\Storage\Ldap' => 'UnicaenAuth\Authentication\Storage\Ldap',
            'UnicaenAuth\Authentication\Storage\Shib' => 'UnicaenAuth\Authentication\Storage\Shib',
            'UnicaenAuth\Authentication\Storage\ShibSimulatorStorage' => ShibSimulatorStorage::class,
            'UnicaenAuth\View\RedirectionStrategy'    => 'UnicaenAuth\View\RedirectionStrategy',
            'UnicaenAuth\Service\User'                => 'UnicaenAuth\Service\User',
            'UnicaenAuth\Service\CategoriePrivilege'  => 'UnicaenAuth\Service\CategoriePrivilegeService',
@@ -436,7 +432,6 @@ return [
            'userInfo'                   => 'UnicaenAuth\View\Helper\UserInfoFactory',
            'userProfileSelect'          => 'UnicaenAuth\View\Helper\UserProfileSelectFactory',
            'userProfileSelectRadioItem' => 'UnicaenAuth\View\Helper\UserProfileSelectRadioItemFactory',
            'userUsurpation'             => UserUsurpationHelperFactory::class,
            'shibConnect'                => ShibConnectViewHelperFactory::class,
        ],
        'invokables' => [
+2 −39
Original line number Diff line number Diff line
<?php

namespace UnicaenAuth\Authentication\Adapter;

use phpCAS;
use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper;
use UnicaenApp\Exception;
use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\User;
use Zend\Authentication\Exception\UnexpectedValueException;
use Zend\Authentication\Result as AuthenticationResult;
use Zend\EventManager\EventManager;
@@ -50,11 +48,6 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event
     */
    protected $casClient;

    /**
     * @var LdapPeopleMapper
     */
    protected $ldapPeopleMapper;

    /**
     * Réalise l'authentification.
     *
@@ -101,12 +94,7 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event
        $e->setCode(AuthenticationResult::SUCCESS)
          ->setMessages(['Authentication successful.']);

        // recherche de l'individu dans l'annuaire LDAP (il existe forcément puisque l'auth CAS a réussi)
        $ldapPeople = $this->getLdapPeopleMapper()->findOneByUsername($identity);

        /* @var $userService User */
        $userService = $this->getServiceManager()->get('unicaen-auth_user_service');
        $userService->userAuthenticated($ldapPeople);
        $this->getEventManager()->trigger('userAuthenticated', $e);
    }

    /**
@@ -198,31 +186,6 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event
        return $this->options;
    }

    /**
     * get ldap people mapper
     *
     * @return LdapPeopleMapper
     */
    public function getLdapPeopleMapper()
    {
        if (null === $this->ldapPeopleMapper) {
            $this->ldapPeopleMapper = $this->getServiceManager()->get('ldap_people_mapper');
        }
        return $this->ldapPeopleMapper;
    }

    /**
     * set ldap people mapper
     *
     * @param LdapPeopleMapper $mapper
     * @return self
     */
    public function setLdapPeopleMapper(LdapPeopleMapper $mapper)
    {
        $this->ldapPeopleMapper = $mapper;
        return $this;
    }

    /**
     * Get service manager
     *
+2 −9
Original line number Diff line number Diff line
@@ -12,15 +12,11 @@ use Zend\ServiceManager\ServiceLocatorInterface;
 */
class ChainServiceFactory implements FactoryInterface
{
    private $mandatoryStorages = [
    protected $storages = [
        200 => 'UnicaenAuth\Authentication\Storage\Ldap',
        100 => 'UnicaenAuth\Authentication\Storage\Db',
        76  => 'UnicaenAuth\Authentication\Storage\ShibSimulatorStorage',
        75  => 'UnicaenAuth\Authentication\Storage\Shib',
    ];

    protected $storages = [];

    /**
     * Create service
     *
@@ -31,10 +27,7 @@ class ChainServiceFactory implements FactoryInterface
    {
        $chain = new Chain();

        $storages = $this->mandatoryStorages + $this->storages;
        krsort($storages);

        foreach ($storages as $priority => $name) {
        foreach ($this->storages as $priority => $name) {
            $storage = $serviceLocator->get($name);
            $chain->getEventManager()->attach('read', [$storage, 'read'], $priority);
            $chain->getEventManager()->attach('write', [$storage, 'write'], $priority);
+9 −18
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace UnicaenAuth\Authentication\Storage;

use UnicaenAuth\Entity\Shibboleth\ShibUser;
use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\ShibService;
use Zend\Authentication\Storage\Session;
use Zend\Authentication\Storage\StorageInterface;
@@ -24,6 +25,11 @@ class Shib implements ChainableStorage, ServiceLocatorAwareInterface
     */
    protected $storage;
    
    /**
     * @var ModuleOptions
     */
    protected $options;

    /**
     * @var ShibUser
     */
@@ -45,28 +51,13 @@ class Shib implements ChainableStorage, ServiceLocatorAwareInterface
     */
    public function read(ChainEvent $e)
    {
        $shibUser = $this->getAuthenticatedUser();

        $e->addContents('shib', $shibUser);
        
        return $shibUser;
    }

    /**
     * @return null|ShibUser
     */
    private function getAuthenticatedUser()
    {
        if (null !== $this->resolvedIdentity) {
            return $this->resolvedIdentity;
        }

        /** @var ShibService $shib */
        $shib = $this->getServiceLocator()->get(ShibService::class);
        $shibUser = $shib->getAuthenticatedUser();

        $this->resolvedIdentity = $shib->getAuthenticatedUser();
        $e->addContents('shib', $shibUser);
        
        return $this->resolvedIdentity;
        return $shibUser;
    }

    /**
+0 −70
Original line number Diff line number Diff line
<?php

namespace UnicaenAuth\Authentication\Storage;

use UnicaenAuth\Service\ShibService;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorAwareTrait;

/**
 * Storage permettant de simuler un utilisateur authentifié via Shibboleth.
 *
 * @author Unicaen
 */
class ShibSimulatorStorage implements ChainableStorage, ServiceLocatorAwareInterface
{
    use ServiceLocatorAwareTrait;

    /**
     * @var ShibService
     */
    protected $shibService;

    /**
     * @var array
     */
    protected $shibbolethOptions;

    /**
     * {@inheritdoc}
     */
    public function read(ChainEvent $e)
    {
        if (! $this->getShibService()->isShibbolethEnabled()) {
            return;
        }
        if (! $this->getShibService()->isSimulationActive()) {
            return;
        }

        $this->getShibService()->handleSimulation();
    }

    /**
     * {@inheritdoc}
     */
    public function write(ChainEvent $e)
    {
        // nop
    }

    /**
     * {@inheritdoc}
     */
    public function clear(ChainEvent $e)
    {
        // nop
    }

    /**
     * @return ShibService
     */
    private function getShibService()
    {
        if ($this->shibService === null) {
            $this->shibService = $this->serviceLocator->get(ShibService::class);
        }

        return $this->shibService;
    }
}
 No newline at end of file
Loading