File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
src/StudentAffairsUwm/Shibboleth Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1515use JWTAuth ;
1616use Illuminate \Database \Eloquent \ModelNotFoundException ;
1717use StudentAffairsUwm \Shibboleth \Entitlement ;
18+ use StudentAffairsUwm \Shibboleth \ConfigurationBackwardsCompatabilityMapper ;
1819
1920class 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 }
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments