ShibbolethAuthenticationEntryPoint::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Kuleuven\AuthenticationBundle\Security;
4
5
use Kuleuven\AuthenticationBundle\Service\ShibbolethServiceProvider;
6
use Kuleuven\AuthenticationBundle\Traits\LoggerTrait;
7
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\Security\Core\Exception\AuthenticationException;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11
12
class ShibbolethAuthenticationEntryPoint implements AuthenticationEntryPointInterface
13
{
14
    use LoggerTrait;
15
16
    private $shibbolethServiceProvider;
17
18
    public function __construct(ShibbolethServiceProvider $shibbolethServiceProvider)
19
    {
20
        $this->shibbolethServiceProvider = $shibbolethServiceProvider;
21
    }
22
23
    public function start(Request $request, AuthenticationException $authException = null)
24
    {
25
        if (!$this->shibbolethServiceProvider->isAuthenticated()) {
26
            $this->log('Shibboleth has not authenticated your request.');
27
            throw new AuthenticationException('Shibboleth has not authenticated your request.');
28
        }
29
        $url = $this->shibbolethServiceProvider->getLoginUrl($request->getUri());
30
        if (!$this->shibbolethServiceProvider->isReachable($url)) {
31
            $this->log(sprintf('Shibboleth login is not available at "%s".', $url));
32
            throw new AuthenticationException('Shibboleth login is not available.');
33
        }
34
        $this->log(sprintf('Redirecting to login at "%s"...', $url));
35
        return new RedirectResponse($url);
36
    }
37
}
38