1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\casserver\Controller\Traits; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Configuration; |
8
|
|
|
use SimpleSAML\Module\casserver\Cas\ServiceValidator; |
9
|
|
|
use SimpleSAML\Module\casserver\Cas\TicketValidator; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
|
12
|
|
|
trait UrlTrait |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @deprecated |
16
|
|
|
* @see ServiceValidator |
17
|
|
|
* @param string $service |
18
|
|
|
* @param array $legal_service_urls |
19
|
|
|
* @return bool |
20
|
|
|
*/ |
21
|
|
|
public function checkServiceURL(string $service, array $legal_service_urls): bool |
22
|
|
|
{ |
23
|
|
|
//delegate to ServiceValidator until all references to this can be cleaned up |
24
|
|
|
$config = Configuration::loadFromArray(['legal_service_urls' => $legal_service_urls]); |
25
|
|
|
$serviceValidator = new ServiceValidator($config); |
26
|
|
|
return $serviceValidator->checkServiceURL($service) !== null; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $parameter |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
|
|
public function sanitize(string $parameter): string |
34
|
|
|
{ |
35
|
|
|
return TicketValidator::sanitize($parameter); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Parse the query Parameters from $_GET global and return them in an array. |
40
|
|
|
* |
41
|
|
|
* @param Request $request |
42
|
|
|
* @param array|null $sessionTicket |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function parseQueryParameters(Request $request, ?array $sessionTicket): array |
47
|
|
|
{ |
48
|
|
|
$forceAuthn = $this->getRequestParam($request, 'renew'); |
49
|
|
|
$sessionRenewId = !empty($sessionTicket['renewId']) ? $sessionTicket['renewId'] : null; |
50
|
|
|
|
51
|
|
|
$queryParameters = $request->query->all(); |
52
|
|
|
$requestParameters = $request->request->all(); |
53
|
|
|
|
54
|
|
|
$query = array_merge($requestParameters, $queryParameters); |
55
|
|
|
|
56
|
|
|
if ($sessionRenewId && $forceAuthn) { |
57
|
|
|
$query['renewId'] = $sessionRenewId; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (isset($query['language'])) { |
61
|
|
|
$query['language'] = is_string($query['language']) ? $query['language'] : null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $query; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Request $request |
69
|
|
|
* @param string $paramName |
70
|
|
|
* |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
|
|
public function getRequestParam(Request $request, string $paramName): mixed |
74
|
|
|
{ |
75
|
|
|
return $request->query->get($paramName) ?? $request->request->get($paramName) ?? null; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|