Completed
Push — 0.3.x ( a1e88e...6a8754 )
by Dmitry
31:13 queued 28:43
created

SingleSignOnController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 9
Bugs 2 Features 5
Metric Value
wmc 8
c 9
b 2
f 5
lcom 1
cbo 5
dl 0
loc 53
ccs 25
cts 25
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B ssoLoginAction() 0 29 6
A ssoLogoutAction() 0 12 2
1
<?php
2
3
namespace Krtv\Bundle\SingleSignOnIdentityProviderBundle\Controller;
4
5
use Krtv\Bundle\SingleSignOnIdentityProviderBundle\Event\SsoAuthorizedEvent;
6
use Krtv\Bundle\SingleSignOnIdentityProviderBundle\Event\SsoEvents;
7
use Krtv\Bundle\SingleSignOnIdentityProviderBundle\Manager\ServiceManager;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
12
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
13
14
/**
15
 * Class SingleSignOnController
16
 * @package Krtv\Bundle\SingleSignOnIdentityProviderBundle\Controller
17
 */
18
class SingleSignOnController extends Controller
19
{
20
    /**
21
     * @param Request $request
22
     * @return RedirectResponse
23
     */
24 5
    public function ssoLoginAction(Request $request)
25
    {
26 5
        $httpUtils = $this->get('krtv_single_sign_on_identity_provider.security.http_utils');
27
28 5
        if (!$httpUtils->hasTargetPath($request)) {
29 1
            throw new BadRequestHttpException('Target path not specified');
30
        }
31
32 4
        if (false === $httpUtils->checkUrl($request->getSchemeAndHttpHost().$request->getRequestUri())) {
33 1
            throw new BadRequestHttpException('Malformed uri');
34
        }
35
36 3
        if (false === $this->get('security.authorization_checker')->isGranted('ROLE_USER') && $request->get('_failure_path')) {
37 1
            return $httpUtils->createRedirectResponse($request, $request->get('_failure_path'));
38 2
        } elseif (false === $this->get('security.authorization_checker')->isGranted('ROLE_USER')) {
39 1
            throw new AccessDeniedException();
40
        }
41
42 1
        $this->get('event_dispatcher')->dispatch(SsoEvents::SSO_AUTHORIZED, new SsoAuthorizedEvent());
43
44 1
        $otpOrmManager = $this->get('krtv_single_sign_on_identity_provider.security.authentication.otp_manager.orm');
45 1
        $otpEncoder = $this->get('krtv_single_sign_on_identity_provider.security.authentication.encoder');
46
47 1
        $otp = $otpOrmManager->create(
48 1
            $otpEncoder->generateOneTimePasswordValue($this->getUser()->getUsername(), microtime(true) + 300)
49 1
        );
50
51 1
        return $httpUtils->createSignedRedirectResponse($request, $httpUtils->createWrappedTargetPath($request, $otp));
52
    }
53
54
    /**
55
     * @param Request $request
56
     * @return RedirectResponse
57
     */
58 3
    public function ssoLogoutAction(Request $request)
59
    {
60 3
        $serviceManager = $this->get('krtv_single_sign_on_identity_provider.manager.service_manager');
61 3
        $logoutManager = $this->get('krtv_single_sign_on_identity_provider.manager.logout_manager');
62 3
        $httpUtils = $this->get('krtv_single_sign_on_identity_provider.security.http_utils');
63
64 3
        if (!$serviceManager->getRequestService()) {
65 1
            $serviceManager->setDefaults();
66 1
        }
67
 
68 3
        return $httpUtils->createRedirectResponse($request, $logoutManager->getNextLogoutUrl());
69
    }
70
}
71