ShibbolethAuthenticationEntryPoint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A start() 0 14 3
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