Skip to content

Commit 0edeb3d

Browse files
committed
Allow service tickets on proxyValidate
1 parent adc89cd commit 0edeb3d

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/Controller/Traits/TicketValidatorTrait.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,7 @@ public function validate(
7474
$message = '';
7575
// Below, we do not have a ticket or the ticket does not meet the very basic criteria that allow
7676
// any further handling
77-
if (empty($serviceTicket)) {
78-
// No ticket
79-
$message = 'Ticket ' . var_export($ticket, true) . ' not recognized';
80-
$failed = true;
81-
} elseif ($method === 'proxyValidate' && !$this->ticketFactory->isProxyTicket($serviceTicket)) {
82-
// proxyValidate but not a proxy ticket
83-
$message = 'Ticket ' . var_export($ticket, true) . ' is not a proxy ticket.';
84-
$failed = true;
85-
} elseif ($method === 'serviceValidate' && !$this->ticketFactory->isServiceTicket($serviceTicket)) {
86-
// serviceValidate but not a service ticket
87-
$message = 'Ticket ' . var_export($ticket, true) . ' is not a service ticket.';
88-
$failed = true;
89-
}
90-
91-
if ($failed) {
77+
if ($message = $this->validateServiceTicket($serviceTicket, $ticket, $method)) {
9278
$finalMessage = 'casserver:validate: ' . $message;
9379
Logger::error(__METHOD__ . '::' . $finalMessage);
9480

@@ -185,4 +171,27 @@ public function validate(
185171
Response::HTTP_OK,
186172
);
187173
}
174+
175+
/**
176+
* @param array|null $serviceTicket
177+
*
178+
* @return ?string Message on failure, null on success
179+
*/
180+
private function validateServiceTicket(?array $serviceTicket, string $ticket, string $method): ?string
181+
{
182+
if (empty($serviceTicket)) {
183+
return 'Ticket ' . var_export($ticket, true) . ' not recognized';
184+
}
185+
186+
$isServiceTicket = $this->ticketFactory->isServiceTicket($serviceTicket);
187+
if ($method === 'serviceValidate' && !$isServiceTicket) {
188+
return 'Ticket ' . var_export($ticket, true) . ' is not a service ticket.';
189+
}
190+
191+
if ($method === 'proxyValidate' && !$isServiceTicket && !$this->ticketFactory->isProxyTicket($serviceTicket)) {
192+
return 'Ticket ' . var_export($ticket, true) . ' is not a proxy ticket.';
193+
}
194+
195+
return null;
196+
}
188197
}

tests/src/Controller/Cas20ControllerTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,6 @@ public static function validateOnDifferentQueryParameterCombinationsProxyValidat
565565
"Ticket 'PT-{$sessionId}' has expired",
566566
'PT-' . $sessionId,
567567
],
568-
'Returns Bad Request on Ticket is A Service Ticket' => [
569-
[
570-
'ticket' => 'ST-' . $sessionId,
571-
'service' => 'https://myservice.com/abcd',
572-
],
573-
"Ticket 'ST-{$sessionId}' is not a proxy ticket.",
574-
'ST-' . $sessionId,
575-
],
576568
'Returns Bad Request on Ticket Issued By Single SignOn Session' => [
577569
[
578570
'ticket' => 'PT-' . $sessionId,
@@ -583,7 +575,7 @@ public static function validateOnDifferentQueryParameterCombinationsProxyValidat
583575
'PT-' . $sessionId,
584576
9999999999,
585577
],
586-
'Returns Success' => [
578+
'Returns Success with Proxy Ticket' => [
587579
[
588580
'ticket' => 'PT-' . $sessionId,
589581
'service' => 'https://myservice.com/abcd',
@@ -592,6 +584,15 @@ public static function validateOnDifferentQueryParameterCombinationsProxyValidat
592584
'PT-' . $sessionId,
593585
9999999999,
594586
],
587+
'Returns Success with Service Ticket' => [
588+
[
589+
'ticket' => 'ST-' . $sessionId,
590+
'service' => 'https://myservice.com/abcd',
591+
],
592+
'username@google.com',
593+
'ST-' . $sessionId,
594+
9999999999,
595+
],
595596
];
596597
}
597598

0 commit comments

Comments
 (0)