77 *
88 * This filter allows you to add attributes from a SQL datasource
99 *
10- * @author Guy Halse http://orcid.org/0000-0002-9388-8592
10+ * @author Guy Halse, http://orcid.org/0000-0002-9388-8592
1111 * @copyright Copyright (c) 2019, SAFIRE - South African Identity Federation
12- * @license https://github.com/safire-ac-za/simplesamlphp-module-sqlattribs/blob/master/LICENSE MIT License
13- * @package SimpleSAMLphp
12+ * @license https://github.com/safire-ac-za/simplesamlphp-module-sqlattribs/blob/master/LICENSE MIT License
13+ * @package SimpleSAMLphp
1414 */
1515class AttributeFromSQL extends \SimpleSAML \Auth \ProcessingFilter
1616{
@@ -106,7 +106,8 @@ private function connect()
106106 $ db = new \PDO ($ this ->dsn , $ this ->username , $ this ->password );
107107 } catch (\PDOException $ e ) {
108108 throw new \SimpleSAML \Error \Exception ('AttributeFromSQL: Failed to connect to \'' .
109- $ this ->dsn . '\': ' . $ e ->getMessage ());
109+ $ this ->dsn . '\': ' . $ e ->getMessage ()
110+ );
110111 }
111112 $ db ->setAttribute (\PDO ::ATTR_ERRMODE , \PDO ::ERRMODE_EXCEPTION );
112113
@@ -132,6 +133,7 @@ private function connect()
132133 * Logic is largely the same as (and lifted from) sqlauth:sql
133134 * @param mixed &$request
134135 * @throws \SimpleSAML\Error\Exception
136+ * @return void
135137 */
136138 public function process (&$ request )
137139 {
@@ -149,16 +151,24 @@ public function process(&$request)
149151 $ db = $ this ->connect ();
150152
151153 try {
152- $ sth = $ db ->prepare ('SELECT `attribute`,`value` FROM ' . $ this ->table . ' WHERE `uid`=? AND (`sp`= \'% \' OR `sp`=?) ' . ($ this ->ignoreExpiry ? '' : ' AND `expires`>CURRENT_DATE ' ) . '; ' );
154+ $ sth = $ db ->prepare (
155+ 'SELECT `attribute`,`value` FROM ' .
156+ $ this ->table .
157+ ' WHERE `uid`=? AND (`sp`= \'% \' OR `sp`=?) ' .
158+ ($ this ->ignoreExpiry ? '' : ' AND `expires`>CURRENT_DATE ' ) .
159+ '; '
160+ );
153161 } catch (\PDOException $ e ) {
154162 throw new \SimpleSAML \Error \Exception ('AttributeFromSQL: prepare() failed: ' . $ e ->getMessage ());
155163 }
156164
157165 try {
158166 $ res = $ sth ->execute ([$ attributes [$ this ->attribute ][0 ], $ request ["Destination " ]["entityid " ]]);
159167 } catch (\PDOException $ e ) {
160- throw new \SimpleSAML \Error \Exception ('AttributeFromSQL: execute( ' . $ attributes [$ this ->attribute ][0 ] .
161- ', ' . $ request ["Destination " ]["entityid " ] . ') failed: ' . $ e ->getMessage ());
168+ throw new \SimpleSAML \Error \Exception (
169+ 'AttributeFromSQL: execute( ' . $ attributes [$ this ->attribute ][0 ] .
170+ ', ' . $ request ["Destination " ]["entityid " ] . ') failed: ' . $ e ->getMessage ()
171+ );
162172 }
163173
164174 try {
@@ -169,7 +179,10 @@ public function process(&$request)
169179 }
170180
171181 if (count ($ data ) === 0 ) {
172- \SimpleSAML \Logger::info ('AttributeFromSQL: no additional attributes for ' . $ this ->attribute . '= \'' . $ attributes [$ this ->attribute ][0 ] . '\'' );
182+ \SimpleSAML \Logger::info (
183+ 'AttributeFromSQL: no additional attributes for ' .
184+ $ this ->attribute . '= \'' . $ attributes [$ this ->attribute ][0 ] . '\''
185+ );
173186 return ;
174187 }
175188
@@ -188,7 +201,10 @@ public function process(&$request)
188201
189202 /* Limit the attribute set returned */
190203 if ($ this ->limit !== null && !in_array ($ name , $ this ->limit , true )) {
191- \SimpleSAML \Logger::notice ('AttributeFromSQL: skipping unwanted attribute ' . $ name . ' [limited to: ' . var_export ($ this ->limit , true ) . '] ' );
204+ \SimpleSAML \Logger::notice (
205+ 'AttributeFromSQL: skipping unwanted attribute ' .
206+ $ name . ' [limited to: ' . var_export ($ this ->limit , true ) . '] '
207+ );
192208 continue ;
193209 }
194210
@@ -198,7 +214,10 @@ public function process(&$request)
198214
199215 if (in_array ($ value , $ attributes [$ name ], true )) {
200216 /* Value already exists in attribute. */
201- \SimpleSAML \Logger::debug ('AttributeFromSQL: skipping duplicate attribute/value tuple ' . $ name . '= \'' . $ value . '\'' );
217+ \SimpleSAML \Logger::debug (
218+ 'AttributeFromSQL: skipping duplicate attribute/value tuple ' .
219+ $ name . '= \'' . $ value . '\''
220+ );
202221 continue ;
203222 }
204223
0 commit comments