11import re
2+ import logging
23
34from .base import ResponseMicroService
5+ from ..context import Context
46from ..exception import SATOSAError
57
8+ logger = logging .getLogger (__name__ )
69
710class AddStaticAttributes (ResponseMicroService ):
811 """
@@ -57,6 +60,14 @@ def _apply_filters(self, attributes, attribute_filters, context, target_provider
5760
5861 if filter_type == "regexp" :
5962 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 )
6071 else :
6172 raise SATOSAError ("Unknown filter type" )
6273
@@ -65,3 +76,19 @@ def _apply_filters(self, attributes, attribute_filters, context, target_provider
6576 attributes [attribute ] = list (filter (filter_func , attributes [attribute ]))
6677 elif attribute_name in attributes :
6778 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