Skip to content

Commit 3d953b1

Browse files
committed
Updates for docker testing; phpstan; consolidate gateway methods
1 parent 1ee4594 commit 3d953b1

5 files changed

Lines changed: 16 additions & 46 deletions

File tree

config/module_casserver.php.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ $config = [
117117
'proxy_granting_ticket_expire_time' => 600,
118118
// how many seconds proxy tickets are valid for, defaults to 5
119119
'proxy_ticket_expire_time' => 5,
120-
// OPTIONAL, enable CAS passive mode, defaults to false
120+
// OPTIONAL, if `gateway=true` is requested and user has no session, invoke the authsource with `isPassive=true`.
121+
// defaults to false
121122
//'enable_passive_mode' => true,
122123

123124
// If query param debugMode=true is sent to the login endpoint then print cas ticket xml. Default false

docker/ssp/authsources.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'users' => [
1515
'student:studentpass' => [
1616
'uid' => ['student'],
17+
'cn' => ['Firsty Lasty'],
1718
'eduPersonAffiliation' => ['member', 'student'],
1819
'eduPersonNickname' => 'Sir_Nickname',
1920
'displayName' => 'Some User',

docker/ssp/module_casserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
url query parameter to CAS logout mandatory for obvious reasons.*/
116116

117117
// how many seconds service tickets are valid for, defaults to 5
118-
'service_ticket_expire_time' => 5,
118+
'service_ticket_expire_time' => 60,
119119
// how many seconds proxy granting tickets are valid for at most, defaults to 3600
120120
'proxy_granting_ticket_expire_time' => 600,
121121
//how many seconds proxy tickets are valid for, defaults to 5

src/Controller/LoginController.php

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,18 @@ public function login(
165165
$returnToUrl = $this->getReturnUrl($request, $sessionTicket);
166166

167167
// renew=true and gateway=true are incompatible → prefer interactive login (disable passive)
168-
// Protocol: gateway and renew are incompatible; behavior is undefined if both are set.
169-
// OPTIONAL (implementation policy): Prefer renew (interactive, non-passive) by disabling gateway.
170-
// OPTIONAL alternative: Reject with 400 to signal incompatible parameters.
171168
if ($gateway && $forceAuthn) {
172169
$gateway = false;
173170
}
174171

175-
// Handle passive authentication
172+
// Handle passive authentication if service url defined
176173
// Protocol (gateway set): CAS MUST NOT prompt for credentials during this branch.
177-
if ($gateway && !$this->authSource->isAuthenticated() && !$requestForceAuthenticate) {
178-
$response = $this->handleUnauthenticatedGateway(
174+
if ($serviceUrl && $gateway && !$this->authSource->isAuthenticated() && !$requestForceAuthenticate) {
175+
return $this->handleUnauthenticatedGateway(
179176
$serviceUrl,
180177
$entityId,
181178
$returnToUrl,
182179
);
183-
if ($response !== null) {
184-
return $response;
185-
}
186180
}
187181

188182
// Handle interactive authentication
@@ -254,9 +248,6 @@ public function login(
254248
}
255249

256250
// User has SSO or non-interactive auth succeeded → redirect/POST to service WITH a ticket
257-
// Protocol: With gateway and a successful non-interactive auth (or existing SSO), CAS MAY redirect to the
258-
// service and append a ticket.
259-
// Protocol: CAS MAY interpose an advisory page indicating that authentication took place.
260251
$ticketName = $this->calculateTicketName($service);
261252
$this->postAuthUrlParameters[$ticketName] = $serviceTicket['id'];
262253

@@ -502,20 +493,19 @@ private function handleInteractiveAuthenticate(
502493
* - null to indicate: proceed with interactive login (non-passive).
503494
*/
504495
private function handleUnauthenticatedGateway(
505-
?string $serviceUrl,
496+
string $serviceUrl,
506497
?string $entityId,
507498
string $returnToUrl,
508-
): ?RunnableResponse {
499+
): RunnableResponse {
509500
$passiveAllowed = $this->casConfig->getOptionalBoolean('enable_passive_mode', false);
510501

511-
// Passive mode is not enabled by configuration.
512-
// Protocol: If non-interactive auth cannot be established:
513-
// - If service is present, CAS MUST redirect to the service URL WITHOUT a ticket parameter.
514-
// - If service is absent, behavior is undefined; it is RECOMMENDED
515-
// to request credentials as if neither parameter was specified.
502+
// Passive mode is not enabled by configuration
503+
// CAS MUST redirect to the service URL WITHOUT a ticket parameter.
516504
if (!$passiveAllowed) {
517-
// Passive attempt already performed and still not authenticated.
518-
return $this->gatewayFallback($serviceUrl);
505+
return new RunnableResponse(
506+
[$this->httpUtils, 'redirectTrustedURL'],
507+
[$serviceUrl, []],
508+
);
519509
}
520510

521511
// Passive mode enabled: attempt a passive (non-interactive) authentication.
@@ -566,26 +556,4 @@ private function handleAuthenticate(
566556
[$params],
567557
);
568558
}
569-
570-
/**
571-
* Gateway fallback per CAS gateway semantics:
572-
* - Protocol (MUST): If a service is provided and non-interactive auth cannot be established,
573-
* redirect to the service WITHOUT any CAS parameters (no "ticket").
574-
* - Protocol (Undefined, RECOMMENDED): If no service is provided, proceed with interactive login
575-
* (request credentials).
576-
* @param string|null $serviceUrl
577-
* @return RunnableResponse|null
578-
*/
579-
private function gatewayFallback(?string $serviceUrl): ?RunnableResponse
580-
{
581-
if ($serviceUrl !== null) {
582-
// MUST: Redirect to service WITHOUT a "ticket" parameter (and without other CAS params).
583-
return new RunnableResponse(
584-
[$this->httpUtils, 'redirectTrustedURL'],
585-
[$serviceUrl, []],
586-
);
587-
}
588-
// RECOMMENDED: No service specified; proceed with interactive login as if neither parameter was specified.
589-
return null;
590-
}
591559
}

tests/src/Controller/LoginControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public function testValidServiceUrl(string $serviceParam, string $redirectURL, b
331331
/**
332332
* @return array<array{0:string}>
333333
*/
334-
public function serviceUrlsProvider(): array
334+
public static function serviceUrlsProvider(): array
335335
{
336336
return [
337337
['https://example.com/ssp/module.php/cas/linkback.php'],

0 commit comments

Comments
 (0)