Skip to content

Commit d623ee8

Browse files
committed
maintain config backwards compat
1 parent c69da93 commit d623ee8

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace StudentAffairsUwm\Shibboleth;
4+
5+
class ConfigurationBackwardsCompatabilityMapper
6+
{
7+
public static function map()
8+
{
9+
foreach ([
10+
'entitlement' => 'idp_login_entitlement',
11+
'user.email' => 'idp_login_email',
12+
'user.name' => 'idp_login_name',
13+
'user.first_name' => 'idp_login_first_name',
14+
'user.last_name' => 'idp_login_last_name',
15+
] as $new => $old) {
16+
config(["shibboleth.$new" => config("shibboleth.$old")]);
17+
}
18+
}
19+
}

src/StudentAffairsUwm/Shibboleth/Controllers/ShibbolethController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use JWTAuth;
1616
use Illuminate\Database\Eloquent\ModelNotFoundException;
1717
use StudentAffairsUwm\Shibboleth\Entitlement;
18+
use StudentAffairsUwm\Shibboleth\ConfigurationBackwardsCompatabilityMapper;
1819

1920
class ShibbolethController extends Controller
2021
{
@@ -78,6 +79,10 @@ public function login()
7879
*/
7980
public function idpAuthenticate()
8081
{
82+
if (empty(config('shibboleth.user'))) {
83+
ConfigurationBackwardsCompatabilityMapper::map();
84+
}
85+
8186
foreach (config('shibboleth.user') as $local => $server) {
8287
$map[$local] = $this->getServerVariable($server);
8388
}

tests/ShibbolethControllerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,30 @@ public function test_creates_user()
2929

3030
$this->assertSame('100000001', $getJeff()->student_id);
3131
}
32+
33+
public function test_handles_backwards_compatability_config()
34+
{
35+
$backup = config('shibboleth.user');
36+
config(['shibboleth.user' => null]);
37+
38+
config([
39+
'shibboleth.idp_login_email' => 'mail',
40+
'shibboleth.idp_login_name' => 'displayName',
41+
'shibboleth.idp_login_first_name' => 'givenName',
42+
'shibboleth.idp_login_last_name' => 'sn',
43+
'shibboleth.idp_login_entitlement' => 'entitlement',
44+
]);
45+
46+
$getJeff = function(){
47+
return User::where('email', '[email protected]')->first();
48+
};
49+
50+
$this->assertEmpty($getJeff());
51+
52+
(new ShibbolethController)->idpAuthenticate();
53+
54+
$this->assertSame('Puckett', $getJeff()->last_name);
55+
56+
config(['shibboleth.user' => $backup]);
57+
}
3258
}

0 commit comments

Comments
 (0)