1
1
import re
2
+ import logging
2
3
3
4
from .base import ResponseMicroService
5
+ from ..context import Context
4
6
from ..exception import SATOSAError
5
7
8
+ logger = logging .getLogger (__name__ )
6
9
7
10
class AddStaticAttributes (ResponseMicroService ):
8
11
"""
@@ -57,6 +60,14 @@ def _apply_filters(self, attributes, attribute_filters, context, target_provider
57
60
58
61
if filter_type == "regexp" :
59
62
filter_func = re .compile (filter_value ).search
63
+ elif filter_type == "shibmdscope_match_scope" :
64
+ mdstore = context .get_decoration (Context .KEY_METADATA_STORE )
65
+ md_scopes = list (mdstore .shibmd_scopes (target_provider ,"idpsso_descriptor" ))
66
+ filter_func = lambda v : self ._shibmdscope_match_scope (v , md_scopes )
67
+ elif filter_type == "shibmdscope_match_value" :
68
+ mdstore = context .get_decoration (Context .KEY_METADATA_STORE )
69
+ md_scopes = list (mdstore .shibmd_scopes (target_provider ,"idpsso_descriptor" ))
70
+ filter_func = lambda v : self ._shibmdscope_match_value (v , md_scopes )
60
71
else :
61
72
raise SATOSAError ("Unknown filter type" )
62
73
@@ -65,3 +76,19 @@ def _apply_filters(self, attributes, attribute_filters, context, target_provider
65
76
attributes [attribute ] = list (filter (filter_func , attributes [attribute ]))
66
77
elif attribute_name in attributes :
67
78
attributes [attribute_name ] = list (filter (filter_func , attributes [attribute_name ]))
79
+
80
+ def _shibmdscope_match_value (self , value , md_scopes ):
81
+ for md_scope in md_scopes :
82
+ if not md_scope ['regexp' ] and md_scope ['text' ] == value :
83
+ return True
84
+ elif md_scope ['regexp' ] and re .compile (md_scope ['text' ]).match (value ):
85
+ return True
86
+ return False
87
+
88
+ def _shibmdscope_match_scope (self , value , md_scopes ):
89
+ split_value = value .split ('@' )
90
+ if len (split_value ) != 2 :
91
+ logger .info (f"Discarding invalid scoped value { value } " )
92
+ return False
93
+ value_scope = split_value [1 ]
94
+ return self ._shibmdscope_match_value (value_scope , md_scopes )
0 commit comments