|
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
|
|
|
use function array_merge; |
|
13
|
|
|
use function is_string; |
|
14
|
|
|
|
|
15
|
|
|
trait UrlTrait |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param string $service |
|
19
|
|
|
* @param string[] $legal_service_urls |
|
20
|
|
|
* |
|
21
|
|
|
* @return bool |
|
22
|
|
|
* @throws \ErrorException |
|
23
|
|
|
* @see \SimpleSAML\Module\casserver\Cas\ServiceValidator |
|
24
|
|
|
*/ |
|
25
|
|
|
public function checkServiceURL(string $service, array $legal_service_urls): bool |
|
26
|
|
|
{ |
|
27
|
|
|
//delegate to ServiceValidator until all references to this can be cleaned up |
|
28
|
|
|
$config = Configuration::loadFromArray(['legal_service_urls' => $legal_service_urls]); |
|
29
|
|
|
$serviceValidator = new ServiceValidator($config); |
|
30
|
|
|
return $serviceValidator->checkServiceURL($service) !== null; |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $parameter |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
|
|
public function sanitize(string $parameter): string |
|
38
|
|
|
{ |
|
39
|
|
|
return TicketValidator::sanitize($parameter); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Parse the query Parameters from $_GET global and return them in an array. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
46
|
|
|
* @param string[]|null $sessionTicket |
|
47
|
|
|
* |
|
48
|
|
|
* @return string[] |
|
49
|
|
|
*/ |
|
50
|
|
|
public function parseQueryParameters(Request $request, ?array $sessionTicket): array |
|
51
|
|
|
{ |
|
52
|
|
|
$forceAuthn = $this->getRequestParam($request, 'renew'); |
|
53
|
|
|
$sessionRenewId = !empty($sessionTicket['renewId']) ? $sessionTicket['renewId'] : null; |
|
54
|
|
|
|
|
55
|
|
|
$queryParameters = $request->query->all(); |
|
56
|
|
|
$requestParameters = $request->request->all(); |
|
57
|
|
|
|
|
58
|
|
|
$query = array_merge($requestParameters, $queryParameters); |
|
59
|
|
|
|
|
60
|
|
|
if ($sessionRenewId && $forceAuthn) { |
|
61
|
|
|
$query['renewId'] = $sessionRenewId; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (isset($query['language'])) { |
|
65
|
|
|
$query['language'] = is_string($query['language']) ? $query['language'] : null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $query; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
73
|
|
|
* @param string $paramName |
|
74
|
|
|
* |
|
75
|
|
|
* @return mixed |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getRequestParam(Request $request, string $paramName): mixed |
|
78
|
|
|
{ |
|
79
|
|
|
return $request->query->get($paramName) ?? $request->request->get($paramName) ?? null; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.