Skip to content

Commit ba41a9e

Browse files
committed
Show an error message to the user when eppn is invalid
1 parent 69d6c15 commit ba41a9e

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

resources/init.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use UnityWebPortal\lib\UnityRedis;
1414
use UnityWebPortal\lib\UnityWebhook;
1515
use UnityWebPortal\lib\UnityGithub;
16+
use UnityWebPortal\lib\UnitySite;
17+
use UnityWebPortal\lib\exceptions\SSOException;
1618

1719
//
1820
// Initialize Session
@@ -92,7 +94,14 @@
9294
// SSO Init
9395
//
9496

95-
$SSO = UnitySSO::getSSO();
97+
try {
98+
$SSO = UnitySSO::getSSO();
99+
} catch (SSOException $e) {
100+
$errorid = uniqid("sso-");
101+
$eppn = $_SERVER["REMOTE_USER"];
102+
UnitySite::errorLog("SSO Failure", "{$e} ($errorid)");
103+
UnitySite::die("Invalid eppn: '$eppn'. Please contact {$CONFIG["mail"]["support"]} (id: $errorid)", true);
104+
}
96105
if (!is_null($SSO)) {
97106
// SSO is available
98107
$_SESSION["SSO"] = $SSO;

resources/lib/UnitySSO.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace UnityWebPortal\lib;
44

55
use Exception;
6+
use UnityWebPortal\lib\exceptions\SSOException;
67

78
class UnitySSO
89
{
@@ -17,7 +18,7 @@ private static function eppnToOrg($eppn)
1718
{
1819
$parts = explode("@", $eppn);
1920
if (count($parts) != 2) {
20-
throw new Exception("Malformed remote user detected: '$eppn'");
21+
throw new SSOException("Malformed remote user detected: '$eppn'");
2122
}
2223

2324
$org = $parts[1];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace UnityWebPortal\lib\exceptions;
3+
4+
class SSOException extends \Exception
5+
{
6+
}

0 commit comments

Comments
 (0)