1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace drupol\ecas; |
||
6 | |||
7 | use drupol\psrcas\Cas; |
||
8 | use drupol\psrcas\CasInterface; |
||
9 | use drupol\psrcas\Configuration\Properties; |
||
10 | use drupol\psrcas\Configuration\PropertiesInterface; |
||
11 | use Psr\Cache\CacheItemPoolInterface; |
||
12 | use Psr\Http\Client\ClientInterface; |
||
13 | use Psr\Http\Message\RequestFactoryInterface; |
||
14 | use Psr\Http\Message\ResponseFactoryInterface; |
||
15 | use Psr\Http\Message\ResponseInterface; |
||
16 | use Psr\Http\Message\ServerRequestInterface; |
||
17 | use Psr\Http\Message\StreamFactoryInterface; |
||
18 | use Psr\Http\Message\UriFactoryInterface; |
||
19 | use Psr\Log\LoggerInterface; |
||
20 | |||
21 | /** |
||
22 | * Class Ecas. |
||
23 | */ |
||
24 | final class Ecas implements CasInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var \drupol\psrcas\CasInterface |
||
28 | */ |
||
29 | private $cas; |
||
30 | |||
31 | /** |
||
32 | * @var \Psr\Http\Message\StreamFactoryInterface |
||
33 | */ |
||
34 | private $streamFactory; |
||
35 | |||
36 | /** |
||
37 | * Ecas constructor. |
||
38 | * |
||
39 | * @param \Psr\Http\Message\ServerRequestInterface $serverRequest |
||
40 | * @param \drupol\psrcas\Configuration\PropertiesInterface $properties |
||
41 | * @param \Psr\Http\Client\ClientInterface $client |
||
42 | * @param \Psr\Http\Message\UriFactoryInterface $uriFactory |
||
43 | * @param \Psr\Http\Message\ResponseFactoryInterface $responseFactory |
||
44 | * @param \Psr\Http\Message\RequestFactoryInterface $requestFactory |
||
45 | * @param \Psr\Http\Message\StreamFactoryInterface $streamFactory |
||
46 | * @param \Psr\Cache\CacheItemPoolInterface $cache |
||
47 | * @param \Psr\Log\LoggerInterface $logger |
||
48 | */ |
||
49 | 1 | public function __construct( |
|
50 | ServerRequestInterface $serverRequest, |
||
51 | PropertiesInterface $properties, |
||
52 | ClientInterface $client, |
||
53 | UriFactoryInterface $uriFactory, |
||
54 | ResponseFactoryInterface $responseFactory, |
||
55 | RequestFactoryInterface $requestFactory, |
||
56 | StreamFactoryInterface $streamFactory, |
||
57 | CacheItemPoolInterface $cache, |
||
58 | LoggerInterface $logger |
||
59 | ) { |
||
60 | 1 | $ecasProperties = $properties->all(); |
|
61 | |||
62 | 1 | $ecasProperties['protocol']['serviceValidate']['allowed_parameters'][] = 'userDetails'; |
|
63 | 1 | $ecasProperties['protocol']['proxyValidate']['allowed_parameters'][] = 'userDetails'; |
|
64 | 1 | $ecasProperties['protocol']['serviceValidate']['default_parameters']['format'] = 'XML'; |
|
65 | 1 | $ecasProperties['protocol']['proxyValidate']['default_parameters']['format'] = 'XML'; |
|
66 | |||
67 | 1 | $this->cas = new Cas( |
|
68 | 1 | $serverRequest, |
|
69 | 1 | new Properties($ecasProperties), |
|
70 | $client, |
||
71 | $uriFactory, |
||
72 | $responseFactory, |
||
73 | $requestFactory, |
||
74 | $streamFactory, |
||
75 | $cache, |
||
76 | $logger |
||
77 | ); |
||
78 | |||
79 | 1 | $this->streamFactory = $streamFactory; |
|
80 | 1 | } |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function authenticate(): ?array |
||
86 | { |
||
87 | return $this->cas->authenticate(); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function getProperties(): PropertiesInterface |
||
94 | { |
||
95 | return $this->cas->getProperties(); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 1 | public function handleProxyCallback( |
|
102 | array $parameters = [], |
||
103 | ?ResponseInterface $response = null |
||
104 | ): ?ResponseInterface { |
||
105 | 1 | $body = '<?xml version="1.0" encoding="utf-8"?><proxySuccess xmlns="http://www.yale.edu/tp/casClient" />'; |
|
106 | |||
107 | $response = $this |
||
108 | 1 | ->cas |
|
109 | 1 | ->handleProxyCallback($parameters, $response); |
|
110 | |||
111 | 1 | if (null !== $response) { |
|
112 | 1 | return $response->withBody( |
|
113 | $this |
||
114 | 1 | ->streamFactory |
|
115 | 1 | ->createStream($body) |
|
116 | ); |
||
117 | } |
||
118 | |||
119 | return $response; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function login(array $parameters = []): ?ResponseInterface |
||
126 | { |
||
127 | return $this->cas->login($parameters); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | public function logout(array $parameters = []): ResponseInterface |
||
134 | { |
||
135 | return $this->cas->logout($parameters); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
136 | } |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | public function requestProxyTicket( |
||
142 | array $parameters = [], |
||
143 | ?ResponseInterface $response = null |
||
144 | ): ?ResponseInterface { |
||
145 | return $this->cas->requestProxyTicket($parameters, $response); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function requestProxyValidate( |
||
152 | array $parameters = [], |
||
153 | ?ResponseInterface $response = null |
||
154 | ): ?ResponseInterface { |
||
155 | return $this->cas->requestProxyValidate($parameters, $response); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | public function requestServiceValidate( |
||
162 | array $parameters = [], |
||
163 | ?ResponseInterface $response = null |
||
164 | ): ?ResponseInterface { |
||
165 | return $this->cas->requestServiceValidate($parameters, $response); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | public function requestTicketValidation( |
||
172 | array $parameters = [], |
||
173 | ?ResponseInterface $response = null |
||
174 | ): ?ResponseInterface { |
||
175 | return $this->cas->requestTicketValidation($parameters, $response); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * {@inheritdoc} |
||
180 | */ |
||
181 | public function supportAuthentication(): bool |
||
182 | { |
||
183 | return $this->cas->supportAuthentication(); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | 1 | public function withServerRequest(ServerRequestInterface $serverRequest): CasInterface |
|
190 | { |
||
191 | 1 | $clone = clone $this; |
|
192 | 1 | $clone->cas = $clone->cas->withServerRequest($serverRequest); |
|
193 | |||
194 | 1 | return $clone; |
|
195 | } |
||
196 | } |
||
197 |