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