@@ -139,15 +139,15 @@ private function generatePNhash(&$state)
139139 }
140140
141141 /* calculate a hash */
142- if (isset ($ uid ) and is_string ($ uid )) {
142+ if (isset ($ uid ) && is_string ($ uid )) {
143143 $ userdata = $ this ->federation ;
144144 if (array_key_exists ('saml:sp:IdP ' , $ state )) {
145- $ userdata .= strlen ($ state ['saml:sp:IdP ' ]). ': ' . $ state ['saml:sp:IdP ' ];
145+ $ userdata .= strlen ($ state ['saml:sp:IdP ' ]) . ': ' . $ state ['saml:sp:IdP ' ];
146146 } else {
147- $ userdata .= strlen ($ state ['Source ' ]['entityid ' ]). ': ' . $ state ['Source ' ]['entityid ' ];
147+ $ userdata .= strlen ($ state ['Source ' ]['entityid ' ]) . ': ' . $ state ['Source ' ]['entityid ' ];
148148 }
149- $ userdata .= strlen ($ state ['Destination ' ]['entityid ' ]). ': ' . $ state ['Destination ' ]['entityid ' ];
150- $ userdata .= strlen ($ uid ). ': ' . $ uid ;
149+ $ userdata .= strlen ($ state ['Destination ' ]['entityid ' ]) . ': ' . $ state ['Destination ' ]['entityid ' ];
150+ $ userdata .= strlen ($ uid ) . ': ' . $ uid ;
151151 $ userdata .= $ this ->salt ;
152152
153153 return hash ($ this ->algorithm , $ userdata );
@@ -187,17 +187,17 @@ public function __construct($config, $reserved)
187187 if (is_string ($ config ['federation ' ])) {
188188 $ this ->federation = $ config ['federation ' ];
189189 } else {
190- throw new Exception ('Federation identifier must be a string ' );
190+ throw new \ Exception ('Federation identifier must be a string ' );
191191 }
192192 } else {
193- throw new Exception ('Federation identifier must be set ' );
193+ throw new \ Exception ('Federation identifier must be set ' );
194194 }
195195
196196 if (array_key_exists ('salt ' , $ config )) {
197197 if (is_string ($ config ['salt ' ])) {
198198 $ this ->salt = $ config ['salt ' ];
199199 } else {
200- throw new Exception ('Salt must be a string ' );
200+ throw new \ Exception ('Salt must be a string ' );
201201 }
202202 } else {
203203 $ this ->salt = Utils \Config::getSecretSalt ();
@@ -207,25 +207,26 @@ public function __construct($config, $reserved)
207207 if (is_string ($ config ['userId ' ])) {
208208 $ this ->userId = $ config ['userId ' ];
209209 } else {
210- throw new Exception ('UserId must be a string ' );
210+ throw new \ Exception ('UserId must be a string ' );
211211 }
212212 }
213213
214214 if (array_key_exists ('realm ' , $ config )) {
215215 if (is_string ($ config ['realm ' ])) {
216216 $ this ->realm = $ config ['realm ' ];
217217 } else {
218- throw new Exception ('realm must be a string ' );
218+ throw new \ Exception ('realm must be a string ' );
219219 }
220220 }
221221
222222 if (array_key_exists ('algorithm ' , $ config )) {
223- if (is_string ($ config ['algorithm ' ])
224- and in_array ($ config ['algorithm ' ], hash_algos ())
223+ if (
224+ is_string ($ config ['algorithm ' ])
225+ && in_array ($ config ['algorithm ' ], hash_algos ())
225226 ) {
226227 $ this ->algorithm = $ config ['algorithm ' ];
227228 } else {
228- throw new Exception ('algorithm must be a hash algorithm listed in hash_algos() ' );
229+ throw new \ Exception ('algorithm must be a hash algorithm listed in hash_algos() ' );
229230 }
230231 }
231232
@@ -235,41 +236,59 @@ public function __construct($config, $reserved)
235236 } elseif (is_string ($ config ['exclude ' ])) {
236237 $ this ->exclude = [$ config ['exclude ' ]];
237238 } else {
238- throw new Exception ('F-ticks exclude must be an array ' );
239+ throw new \ Exception ('F-ticks exclude must be an array ' );
239240 }
240241 }
241242
242243 if (array_key_exists ('logdest ' , $ config )) {
243- if (is_string ($ config ['logdest ' ]) and
244+ if (
245+ is_string ($ config ['logdest ' ]) &&
244246 in_array ($ config ['logdest ' ], ['local ' , 'syslog ' , 'remote ' , 'stdout ' , 'errorlog ' , 'simplesamlphp ' ])
245247 ) {
246248 $ this ->logdest = $ config ['logdest ' ];
247249 } else {
248- throw new Exception ('F-ticks log destination must be one of [local, remote, stdout, errorlog, simplesamlphp] ' );
250+ throw new \Exception (
251+ 'F-ticks log destination must be one of [local, remote, stdout, errorlog, simplesamlphp] '
252+ );
249253 }
250254 }
251255
252256 /* match SSP config or we risk mucking up the openlog call */
253257 $ globalConfig = Configuration::getInstance ();
254- $ defaultFacility = $ globalConfig ->getInteger ('logging.facility ' , defined ('LOG_LOCAL5 ' ) ? constant ('LOG_LOCAL5 ' ) : LOG_USER );
258+ $ defaultFacility = $ globalConfig ->getInteger (
259+ 'logging.facility ' ,
260+ defined ('LOG_LOCAL5 ' ) ? constant ('LOG_LOCAL5 ' ) : LOG_USER
261+ );
255262 $ defaultProcessName = $ globalConfig ->getString ('logging.processname ' , 'SimpleSAMLphp ' );
256263 if (array_key_exists ('logconfig ' , $ config )) {
257264 if (is_array ($ config ['logconfig ' ])) {
258265 $ this ->logconfig = $ config ['logconfig ' ];
259266 } else {
260- throw new Exception ('F-ticks logconfig must be an array ' );
267+ throw new \ Exception ('F-ticks logconfig must be an array ' );
261268 }
262269 } else {
263270 $ this ->logconfig ['facility ' ] = $ defaultFacility ;
264271 $ this ->logconfig ['processname ' ] = $ defaultProcessName ;
265272 }
266273 /* warn if we risk mucking up the openlog call (doesn't matter for remote syslog) */
267274 if (in_array ($ this ->logdest , ['local ' , 'syslog ' ])) {
268- if (array_key_exists ('facility ' , $ this ->logconfig ) and $ this ->logconfig ['facility ' ] !== $ defaultFacility ) {
269- Logger::warning ('F-ticks syslog facility differs from global config which may cause SimpleSAMLphp \'s logging to behave inconsistently ' );
275+ if (
276+ array_key_exists ('facility ' , $ this ->logconfig )
277+ && ($ this ->logconfig ['facility ' ] !== $ defaultFacility )
278+ ) {
279+ Logger::warning (
280+ 'F-ticks syslog facility differs from global config which may cause '
281+ . ' SimpleSAMLphp \'s logging to behave inconsistently '
282+ );
270283 }
271- if (array_key_exists ('processname ' , $ this ->logconfig ) and $ this ->logconfig ['processname ' ] !== $ defaultProcessName ) {
272- Logger::warning ('F-ticks syslog processname differs from global config which may cause SimpleSAMLphp \'s logging to behave inconsistently ' );
284+ if (
285+ array_key_exists ('processname ' , $ this ->logconfig )
286+ && ($ this ->logconfig ['processname ' ] !== $ defaultProcessName )
287+ ) {
288+ Logger::warning (
289+ 'F-ticks syslog processname differs from global config which may cause '
290+ . ' SimpleSAMLphp \'s logging to behave inconsistently '
291+ );
273292 }
274293 }
275294 }
@@ -308,9 +327,15 @@ public function process(&$state)
308327 $ fticks ['CSI ' ] = $ session ->getTrackID ();
309328
310329 /* Authentication method identifier */
311- if (array_key_exists ('saml:sp:State ' , $ state ) and array_key_exists ('saml:sp:AuthnContext ' , $ state ['saml:sp:State ' ])) {
330+ if (
331+ array_key_exists ('saml:sp:State ' , $ state )
332+ && array_key_exists ('saml:sp:AuthnContext ' , $ state ['saml:sp:State ' ])
333+ ) {
312334 $ fticks ['AM ' ] = $ state ['saml:sp:State ' ]['saml:sp:AuthnContext ' ];
313- } elseif (array_key_exists ('SimpleSAML_Auth_State.stage ' , $ state ) and preg_match ('/UserPass/ ' , $ state ['SimpleSAML_Auth_State.stage ' ])) {
335+ } elseif (
336+ array_key_exists ('SimpleSAML_Auth_State.stage ' , $ state )
337+ && preg_match ('/UserPass/ ' , $ state ['SimpleSAML_Auth_State.stage ' ])
338+ ) {
314339 /* hack to try identify LDAP et al as Password */
315340 $ fticks ['AM ' ] = Constants::AC_PASSWORD ;
316341 }
@@ -322,7 +347,10 @@ public function process(&$state)
322347 }
323348
324349 /* timestamp */
325- if (array_key_exists ('saml:sp:State ' , $ state ) and array_key_exists ('saml:AuthnInstant ' , $ state ['saml:sp:State ' ])) {
350+ if (
351+ array_key_exists ('saml:sp:State ' , $ state )
352+ && array_key_exists ('saml:AuthnInstant ' , $ state ['saml:sp:State ' ])
353+ ) {
326354 $ fticks ['TS ' ] = $ state ['saml:sp:State ' ]['saml:AuthnInstant ' ];
327355 } else {
328356 $ fticks ['TS ' ] = time ();
@@ -357,20 +385,19 @@ function ($k) {
357385
358386 /* assemble an F-ticks log string */
359387 $ this ->log (
360- 'F-TICKS/ ' . $ this ->federation . '/ ' . self ::$ fticksVersion. '# ' .
388+ 'F-TICKS/ ' . $ this ->federation . '/ ' . self ::$ fticksVersion . '# ' .
361389 implode ('# ' , array_map (
362390 /**
363391 * @param string $k
364392 * @param string $v
365393 * @return string
366394 */
367395 function ($ k , $ v ) {
368- return $ k. '= ' . $ this ->escapeFticks ($ v );
396+ return $ k . '= ' . $ this ->escapeFticks ($ v );
369397 },
370398 array_keys ($ fticks ),
371399 $ fticks
372- )) .
373- '# '
400+ )) . '# '
374401 );
375402 }
376403}
0 commit comments