FederationMetadata::manage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 16
rs 9.4286
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace AerialShip\SamlSPBundle\Bridge;
4
5
use AerialShip\LightSaml\Meta\SerializationContext;
6
use AerialShip\SamlSPBundle\Config\ServiceInfoCollection;
7
use AerialShip\SamlSPBundle\RelyingParty\RelyingPartyInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Security\Http\HttpUtils;
11
12
class FederationMetadata implements RelyingPartyInterface
13
{
14
    /** @var \AerialShip\SamlSPBundle\Config\ServiceInfoCollection */
15
    protected $serviceInfoCollection;
16
17
    /** @var \Symfony\Component\Security\Http\HttpUtils  */
18
    protected $httpUtils;
19
20
21
22
    /**
23
     * @param ServiceInfoCollection $serviceInfoCollection
24
     * @param \Symfony\Component\Security\Http\HttpUtils $httpUtils
25
     */
26
    public function __construct(ServiceInfoCollection $serviceInfoCollection, HttpUtils $httpUtils)
27
    {
28
        $this->serviceInfoCollection = $serviceInfoCollection;
29
        $this->httpUtils = $httpUtils;
30
    }
31
32
33
    /**
34
     * @param \Symfony\Component\HttpFoundation\Request $request
35
     * @return bool
36
     */
37
    function supports(Request $request)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
38
    {
39
        $result = $request->attributes->get('metadata_path') == $request->getPathInfo();
40
        return $result;
41
    }
42
43
44
    /**
45
     * @param \Symfony\Component\HttpFoundation\Request $request
46
     * @throws \Symfony\Component\Process\Exception\RuntimeException
47
     * @return \Symfony\Component\HttpFoundation\Response|SamlSpInfo
48
     */
49
    function manage(Request $request)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
    {
51
        $serviceInfo = $this->serviceInfoCollection->findByAS($request->query->get('as'));
52
        if (!$serviceInfo) {
53
            return $this->httpUtils->createRedirectResponse($request, $request->attributes->get('discovery_path').'?type=metadata');
54
        }
55
56
        $serviceInfo->getSpProvider()->setRequest($request);
57
        $ed = $serviceInfo->getSpProvider()->getEntityDescriptor();
58
59
        $context = new SerializationContext();
60
        $ed->getXml($context->getDocument(), $context);
61
        $result = new Response($context->getDocument()->saveXML());
62
        $result->headers->set('Content-Type', 'application/samlmetadata+xml');
63
        return $result;
64
    }
65
}
66