@@ -26,15 +26,44 @@ private static function eppnToOrg($eppn)
2626 return strtolower ($ org );
2727 }
2828
29+ // shibboleth service provider writes attributes into "server variables"
30+ // shibboleth service provider does not garuntee attributes are set, even REMOTE_USER
31+ // https://shibboleth.atlassian.net/wiki/spaces/SP3/pages/2065335257/AttributeAccess
32+ // I have observed attributes to be set to empty strings while shibd complains of bad config
33+ private static function getAttributeRaw ($ attributeName , $ fallbackAttributeName = null )
34+ {
35+ if (isset ($ _SERVER [$ attributeName ]) && $ _SERVER [$ attributeName ] != "" ) {
36+ return $ _SERVER [$ attributeName ];
37+ }
38+ if (is_null ($ fallbackAttributeName )) {
39+ throw new SSOException ("\$_SERVER[ \"$ attributeName \"] is unset or empty! " );
40+ }
41+ if (isset ($ _SERVER [$ fallbackAttributeName ]) && $ _SERVER [$ fallbackAttributeName ] != "" ) {
42+ return $ _SERVER [$ fallbackAttributeName ];
43+ }
44+ throw new SSOException (
45+ "\$_SERVER[ \"$ attributeName \"] and \$_SERVER[ \"$ fallbackAttributeName \"] "
46+ . " are both unset or empty! "
47+ );
48+ }
49+
50+ private static function getAttribute ($ attributeName , $ fallbackAttributeName = null )
51+ {
52+ $ attribute_raw = self ::getAttributeRaw ($ attributeName , $ fallbackAttributeName );
53+ // attributes may have multiple values, by default they are split by ';'
54+ // see SPConfig setting attributeValueDelimiter
55+ return explode ("; " , $ attribute_raw )[0 ];
56+ }
57+
2958 public static function getSSO ()
3059 {
3160 return array (
32- "user " => self ::eppnToUID ($ _SERVER [ "REMOTE_USER " ] ),
33- "org " => self ::eppnToOrg ($ _SERVER [ "REMOTE_USER " ] ),
34- "firstname " => $ _SERVER [ "givenName " ] ,
35- "lastname " => $ _SERVER [ "sn " ] ,
36- "name " => $ _SERVER [ "givenName " ] . " " . $ _SERVER [ "sn " ] ,
37- "mail " => isset ( $ _SERVER [ "mail " ]) ? $ _SERVER [ " mail " ] : $ _SERVER [ " eppn "]
61+ "user " => self ::eppnToUID (self :: getAttribute ( "REMOTE_USER " ) ),
62+ "org " => self ::eppnToOrg (self :: getAttribute ( "REMOTE_USER " ) ),
63+ "firstname " => self :: getAttribute ( "givenName " ) ,
64+ "lastname " => self :: getAttribute ( "sn " ) ,
65+ "name " => self :: getAttribute ( "givenName " ) . " " . self :: getAttribute ( "sn " ) ,
66+ "mail " => self :: getAttribute ( "mail " , " eppn ")
3867 );
3968 }
4069}
0 commit comments