Completed
Push — master ( d5bbb9...ab4758 )
by Milos
04:50 queued 02:32
created

SamlSPBundle/Bridge/FederationMetadata.php (2 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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