44
55namespace SimpleSAML \Module \perun \Auth \Process ;
66
7+ use SimpleSAML \Auth \ProcessingFilter ;
78use SimpleSAML \Configuration ;
8- use SimpleSAML \Error \Exception ;
9+ use SimpleSAML \Error \UnserializableException ;
910use SimpleSAML \Logger ;
11+ use SimpleSAML \Module ;
1012
1113/**
1214 * Class sspmod_perun_Auth_Process_ProxyFilter.
1315 *
14- * This filter allows to disable/enable nested filters for particular SP or for users with one of (black/white)listed
15- * attribute values. Based on the mode of operation, the nested filters ARE (whitelist) or ARE NOT (blacklist) run when
16- * any of the attribute values matches. SPs are defined by theirs entityID in property 'filterSPs'. User attributes are
17- * defined as a map 'attrName'=>['value1','value2'] in property 'filterAttributes'. Nested filters are defined in the
18- * authproc property in the same format as in config. If only one filter is needed, it can be specified in the config
19- * property.
20- *
21- * example usage:
22- *
23- * 10 => [ 'class' => 'perun:ProxyFilter', 'filterSPs' => ['disableSpEntityId01', 'disableSpEntityId02'],
24- * 'filterAttributes' => [ 'eduPersonPrincipalName' => ['[email protected] '], 'eduPersonAffiliation' => 25- * ['affiliate','member'], ], 'config' => [ 'class' => 'perun:NestedFilter', // ... ], ], 20 => [ 'class' =>
26- * 'perun:ProxyFilter', 'mode' => 'whitelist', 'filterSPs' => ['enableSpEntityId01', 'enableSpEntityId02'], 'authproc'
27- * => [ [ 'class' => 'perun:NestedFilter1', // ... ], [ 'class' => 'perun:NestedFilter2', // ... ], ], ],
16+ * This filter allows to disable/enable nested filters for particular SP or for users with one of denied/allowed
17+ * attribute values. Based on the mode of operation, the nested filters are enabled (allowlist) or disabled (denylist)
18+ * when any of the attribute values matches.
2819 */
29- class ProxyFilter extends \ SimpleSAML \ Auth \ ProcessingFilter
20+ class ProxyFilter extends ProcessingFilter
3021{
22+ public const MODE_DENYLIST = 'denylist ' ;
23+
24+ public const MODE_ALLOWLIST = 'allowlist ' ;
25+
3126 public const MODE_BLACKLIST = 'blacklist ' ;
3227
3328 public const MODE_WHITELIST = 'whitelist ' ;
3429
35- public const MODES = [self ::MODE_BLACKLIST , self ::MODE_WHITELIST ];
30+ public const MODES = [self ::MODE_DENYLIST , self ::MODE_ALLOWLIST , MODE_BLACKLIST , MODE_WHITELIST ];
3631
3732 private $ authproc ;
3833
@@ -53,7 +48,17 @@ public function __construct($config, $reserved)
5348 $ conf = Configuration::loadFromArray ($ config );
5449 $ this ->filterSPs = $ conf ->getArray ('filterSPs ' , []);
5550 $ this ->filterAttributes = $ conf ->getArray ('filterAttributes ' , []);
56- $ this ->mode = $ conf ->getValueValidate ('mode ' , self ::MODES , self ::MODE_BLACKLIST );
51+
52+ // TODO: remove
53+ $ mode = $ conf ->getValueValidate ('mode ' , self ::MODES , self ::MODE_DENYLIST );
54+ if (in_array ($ mode , [self ::MODE_BLACKLIST , self ::MODE_WHITELIST ], true )) {
55+ Logger::warn (
56+ 'perun:ProxyFilter: You are using a deprecated value for the option "mode". Please switch to "allowlist" or "denylist". '
57+ );
58+ $ this ->mode = $ mode === self ::MODE_BLACKLIST ? self ::MODE_DENYLIST : self ::MODE_ALLOWLIST ;
59+ } else {
60+ $ this ->mode = $ mode ;
61+ }
5762
5863 $ this ->authproc = $ conf ->getArray ('authproc ' , []);
5964 $ this ->authproc [] = $ conf ->getArray ('config ' , []);
@@ -72,15 +77,15 @@ public function process(&$request)
7277 {
7378 assert (is_array ($ request ));
7479
75- $ default = $ this ->mode === self ::MODE_BLACKLIST ;
80+ $ default = $ this ->mode === self ::MODE_DENYLIST ;
7681 $ shouldRun = $ this ->shouldRunForSP ($ request ['Destination ' ]['entityid ' ], $ default );
7782 if ($ shouldRun === $ default ) {
7883 $ shouldRun = $ this ->shouldRunForAttribute ($ request ['Attributes ' ], $ default );
7984 }
8085
8186 if ($ shouldRun ) {
8287 $ this ->processState ($ request );
83- } elseif ($ this ->mode === self ::MODE_WHITELIST ) {
88+ } elseif ($ this ->mode === self ::MODE_ALLOWLIST ) {
8489 Logger::info (
8590 sprintf (
8691 'perun.ProxyFilter: Not running filter %s for SP %s ' ,
@@ -191,11 +196,7 @@ private static function parseFilter($config, $priority)
191196 throw new \Exception ('Authentication processing filter without name given. ' );
192197 }
193198
194- $ className = \SimpleSAML \Module::resolveClass (
195- $ config ['class ' ],
196- 'Auth\Process ' ,
197- '\SimpleSAML\Auth\ProcessingFilter '
198- );
199+ $ className = Module::resolveClass ($ config ['class ' ], 'Auth\Process ' , '\SimpleSAML\Auth\ProcessingFilter ' );
199200 $ config ['%priority ' ] = $ priority ;
200201 unset($ config ['class ' ]);
201202
@@ -239,7 +240,7 @@ private function processState(&$state)
239240 * To be consistent with the exception we return after an redirect,
240241 * we convert this exception before returning it.
241242 */
242- throw new \ SimpleSAML \ Error \ UnserializableException ($ e );
243+ throw new UnserializableException ($ e );
243244 }
244245
245246 // Completed
0 commit comments