SamlInteractionProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 90
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A isSamlAuthenticationInitiated() 0 4 1
A initiateSamlRequest() 0 11 1
A processSamlResponse() 0 13 1
A reset() 0 4 1
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\ProfileBundle\Security\Authentication;
20
21
use OpenConext\ProfileBundle\Saml\StateHandler;
22
use Surfnet\SamlBundle\Entity\IdentityProvider;
23
use Surfnet\SamlBundle\Entity\ServiceProvider;
24
use Surfnet\SamlBundle\Http\PostBinding;
25
use Surfnet\SamlBundle\Http\RedirectBinding;
26
use Surfnet\SamlBundle\SAML2\AuthnRequestFactory;
27
use Symfony\Component\HttpFoundation\Request;
28
29
class SamlInteractionProvider
30
{
31
    /**
32
     * @var \Surfnet\SamlBundle\Entity\ServiceProvider
33
     */
34
    private $serviceProvider;
35
36
    /**
37
     * @var \Surfnet\SamlBundle\Entity\IdentityProvider
38
     */
39
    private $identityProvider;
40
41
    /**
42
     * @var \Surfnet\SamlBundle\Http\RedirectBinding
43
     */
44
    private $redirectBinding;
45
46
    /**
47
     * @var \Surfnet\SamlBundle\Http\PostBinding
48
     */
49
    private $postBinding;
50
51
    /**
52
     * @var \OpenConext\ProfileBundle\Saml\StateHandler
53
     */
54
    private $stateHandler;
55
56
    public function __construct(
57
        ServiceProvider $serviceProvider,
58
        IdentityProvider $identityProvider,
59
        RedirectBinding $redirectBinding,
60
        PostBinding $postBinding,
61
        StateHandler $sessionHandler
62
    ) {
63
        $this->serviceProvider = $serviceProvider;
64
        $this->identityProvider = $identityProvider;
65
        $this->redirectBinding = $redirectBinding;
66
        $this->postBinding = $postBinding;
67
        $this->stateHandler = $sessionHandler;
68
    }
69
70
    /**
71
     * @return bool
72
     */
73
    public function isSamlAuthenticationInitiated()
74
    {
75
        return $this->stateHandler->hasRequestId();
76
    }
77
78
    /**
79
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
80
     */
81
    public function initiateSamlRequest()
82
    {
83
        $authnRequest = AuthnRequestFactory::createNewRequest(
84
            $this->serviceProvider,
85
            $this->identityProvider
86
        );
87
88
        $this->stateHandler->setRequestId($authnRequest->getRequestId());
89
90
        return $this->redirectBinding->createRedirectResponseFor($authnRequest);
0 ignored issues
show
Deprecated Code introduced by
The method Surfnet\SamlBundle\Http\...teRedirectResponseFor() has been deprecated with message: Please use the `createResponseFor` method instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
91
    }
92
93
    /**
94
     * @param Request $request
95
     * @return \SAML2\Assertion
96
     */
97
    public function processSamlResponse(Request $request)
98
    {
99
        /** @var \SAML2\Assertion $assertion */
100
        $assertion = $this->postBinding->processResponse(
101
            $request,
102
            $this->identityProvider,
103
            $this->serviceProvider
104
        );
105
106
        $this->stateHandler->clearRequestId();
107
108
        return $assertion;
109
    }
110
111
    /**
112
     * Resets the SAML flow.
113
     */
114
    public function reset()
115
    {
116
        $this->stateHandler->clearRequestId();
117
    }
118
}
119