@@ -1027,6 +1027,7 @@ class SAMLUnsolicitedFrontend(SAMLFrontend):
1027
1027
unsolicted SAML flows. The unsolicited SAML flows are not part of any
1028
1028
SAML standard.
1029
1029
"""
1030
+
1030
1031
KEY_ENDPOINT = "endpoint"
1031
1032
KEY_DISCO_URL_WHITE = "discovery_service_url_whitelist"
1032
1033
KEY_DISCO_POLICY_WHITE = "discovery_service_policy_whitelist"
@@ -1037,15 +1038,15 @@ class SAMLUnsolicitedFrontend(SAMLFrontend):
1037
1038
KEY_QUERY_DISCO_URL = "discoveryURL"
1038
1039
KEY_QUERY_DISCO_POLICY = "discoveryPolicy"
1039
1040
KEY_SAML_DISCOVERY_SERVICE_URL = SAMLBackend .KEY_SAML_DISCOVERY_SERVICE_URL
1040
- KEY_SAML_DISCOVERY_SERVICE_POLICY = (
1041
- SAMLBackend .KEY_SAML_DISCOVERY_SERVICE_POLICY
1042
- )
1041
+ KEY_SAML_DISCOVERY_SERVICE_POLICY = SAMLBackend .KEY_SAML_DISCOVERY_SERVICE_POLICY
1043
1042
KEY_UNSOLICITED = "unsolicited"
1044
1043
1045
- def __init__ (self , auth_req_callback_func , internal_attributes , config ,
1046
- base_url , name ):
1047
- super ().__init__ (auth_req_callback_func , internal_attributes , config ,
1048
- base_url , name )
1044
+ def __init__ (
1045
+ self , auth_req_callback_func , internal_attributes , config , base_url , name
1046
+ ):
1047
+ super ().__init__ (
1048
+ auth_req_callback_func , internal_attributes , config , base_url , name
1049
+ )
1049
1050
1050
1051
def register_endpoints (self , backend_names ):
1051
1052
"""
@@ -1060,12 +1061,10 @@ def register_endpoints(self, backend_names):
1060
1061
"""
1061
1062
url_map = super ().register_endpoints (backend_names )
1062
1063
1063
- path = urlparse (
1064
- self .config [self .KEY_UNSOLICITED ]
1065
- .get (self .KEY_ENDPOINT )).path
1064
+ path = urlparse (self .config [self .KEY_UNSOLICITED ].get (self .KEY_ENDPOINT )).path
1066
1065
1067
1066
for backend in backend_names :
1068
- pat = ' (^{})/{}$' .format (backend , path )
1067
+ pat = " (^{})/{}$" .format (backend , path )
1069
1068
url_map .append ((pat , self .unsolicited_endpoint ))
1070
1069
1071
1070
logger .debug ("URL maps to be registered are {}" .format (url_map ))
@@ -1092,16 +1091,14 @@ def unsolicited_endpoint(self, context):
1092
1091
requested_disco_url = request .get (self .KEY_QUERY_DISCO_URL , None )
1093
1092
requested_disco_policy = request .get (self .KEY_QUERY_DISCO_POLICY , None )
1094
1093
1095
- logger .debug ("Unsolicited target authenticating IdP is {}" .format (
1096
- target_idp_entity_id ))
1094
+ logger .debug (
1095
+ "Unsolicited target authenticating IdP is {}" .format (target_idp_entity_id )
1096
+ )
1097
1097
logger .debug ("Unsolicited target SP is {}" .format (target_sp_entity_id ))
1098
1098
logger .debug ("Unsolicited ACS URL is {}" .format (target_sp_acs_url ))
1099
- logger .debug ("Unsolicited relay state is {}" .format (
1100
- target_sp_relay_state_url ))
1101
- logger .debug ("Unsolicted discovery URL is {}" .format (
1102
- requested_disco_url ))
1103
- logger .debug ("Unsolicted discovery policy is {}" .format (
1104
- requested_disco_policy ))
1099
+ logger .debug ("Unsolicited relay state is {}" .format (target_sp_relay_state_url ))
1100
+ logger .debug ("Unsolicted discovery URL is {}" .format (requested_disco_url ))
1101
+ logger .debug ("Unsolicted discovery policy is {}" .format (requested_disco_policy ))
1105
1102
1106
1103
# We only proceed with known federated SPs.
1107
1104
try :
@@ -1114,9 +1111,10 @@ def unsolicited_endpoint(self, context):
1114
1111
1115
1112
# The SP ACS URL if input must match one from the trusted metadata.
1116
1113
# We assume the SP only has one SPSSODescriptor element in metadata.
1117
- acs_ob_list = (target_sp_metadata .get ("spsso_descriptor" , [{}])[0 ]
1118
- .get ("assertion_consumer_service" , [{}]))
1119
- acs_locations = [acs_ob ['location' ] for acs_ob in acs_ob_list ]
1114
+ acs_ob_list = target_sp_metadata .get ("spsso_descriptor" , [{}])[0 ].get (
1115
+ "assertion_consumer_service" , [{}]
1116
+ )
1117
+ acs_locations = [acs_ob ["location" ] for acs_ob in acs_ob_list ]
1120
1118
1121
1119
if target_sp_acs_url :
1122
1120
if target_sp_acs_url not in acs_locations :
@@ -1128,10 +1126,11 @@ def unsolicited_endpoint(self, context):
1128
1126
for acs_ob in acs_ob_list :
1129
1127
# We assume the SP has HTTP_POST binding and we simply
1130
1128
# take the first one we find.
1131
- if acs_ob ['binding' ] == BINDING_HTTP_POST :
1132
- target_sp_acs_url = acs_ob ['location' ]
1133
- logger .debug ("Unsolicited found SP ACS URL {}" .format (
1134
- target_sp_acs_url ))
1129
+ if acs_ob ["binding" ] == BINDING_HTTP_POST :
1130
+ target_sp_acs_url = acs_ob ["location" ]
1131
+ logger .debug (
1132
+ "Unsolicited found SP ACS URL {}" .format (target_sp_acs_url )
1133
+ )
1135
1134
break
1136
1135
1137
1136
if not target_sp_acs_url :
@@ -1144,8 +1143,11 @@ def unsolicited_endpoint(self, context):
1144
1143
if target_sp_relay_state_url :
1145
1144
target = urlparse (target_sp_relay_state_url )
1146
1145
acs = urlparse (target_sp_acs_url )
1147
- if not (target .scheme == acs .scheme and
1148
- target .netloc == acs .netloc and target .port == acs .port ):
1146
+ if not (
1147
+ target .scheme == acs .scheme
1148
+ and target .netloc == acs .netloc
1149
+ and target .port == acs .port
1150
+ ):
1149
1151
msg = "RelayState {} is not permitted"
1150
1152
msg = msg .format (target_sp_relay_state_url )
1151
1153
satosa_logging (logger , logging .ERROR , msg , context .state )
@@ -1155,14 +1157,8 @@ def unsolicited_endpoint(self, context):
1155
1157
acs = [[target_sp_acs_url , BINDING_HTTP_POST ]]
1156
1158
sp_config_dict = {
1157
1159
"entityid" : target_sp_entity_id ,
1158
- "service" : {
1159
- "sp" : {
1160
- "endpoints" : {
1161
- "assertion_consumer_service" : acs
1162
- }
1163
- }
1164
- }
1165
- }
1160
+ "service" : {"sp" : {"endpoints" : {"assertion_consumer_service" : acs }}},
1161
+ }
1166
1162
sp_config = SPConfig ().load (sp_config_dict , False )
1167
1163
1168
1164
# Create a temporary SP object and use it to create a authn request
@@ -1171,16 +1167,18 @@ def unsolicited_endpoint(self, context):
1171
1167
target_sp = Base (sp_config )
1172
1168
1173
1169
destination = None
1174
- endpoints = self .idp .config .getattr (' endpoints' )
1175
- sso_service_list = endpoints [' single_sign_on_service' ]
1170
+ endpoints = self .idp .config .getattr (" endpoints" )
1171
+ sso_service_list = endpoints [" single_sign_on_service" ]
1176
1172
for location , binding in sso_service_list :
1177
1173
if binding == BINDING_HTTP_POST :
1178
1174
destination = location
1179
1175
break
1180
1176
1181
1177
if not destination :
1182
- msg = ("Could not determine location for SingleSignOnService "
1183
- "with HTTP-POST binding" )
1178
+ msg = (
1179
+ "Could not determine location for SingleSignOnService "
1180
+ "with HTTP-POST binding"
1181
+ )
1184
1182
satosa_logging (logger , logging .ERROR , msg , context .state )
1185
1183
raise SATOSAError (msg )
1186
1184
@@ -1190,9 +1188,8 @@ def unsolicited_endpoint(self, context):
1190
1188
1191
1189
# Convert the authn request object to an encoded set of bytes.
1192
1190
authn_request_str = "{}" .format (authn_request )
1193
- logger .debug ("Unsolicted authn request is {}" .format (
1194
- authn_request_str ))
1195
- authn_request_bytes = authn_request_str .encode ('utf-8' )
1191
+ logger .debug ("Unsolicted authn request is {}" .format (authn_request_str ))
1192
+ authn_request_bytes = authn_request_str .encode ("utf-8" )
1196
1193
authn_request_encoded = b64encode (authn_request_bytes )
1197
1194
1198
1195
# Add the authn request to the context as if it arrived through
@@ -1205,29 +1202,27 @@ def unsolicited_endpoint(self, context):
1205
1202
1206
1203
# If provided and is whitelisted set the discovery service to use.
1207
1204
if requested_disco_url :
1208
- allowed = (self .config [self .KEY_UNSOLICITED ]
1209
- .get (self .KEY_DISCO_URL_WHITE ))
1205
+ allowed = self .config [self .KEY_UNSOLICITED ].get (self .KEY_DISCO_URL_WHITE )
1210
1206
if requested_disco_url not in allowed :
1211
1207
msg = "Discovery service URL {} not allowed"
1212
1208
msg = msg .format (requested_disco_url )
1213
1209
satosa_logging (logger , logging .ERROR , msg , context .state )
1214
1210
raise SATOSAError (msg )
1215
1211
1216
- context .decorate (self .KEY_SAML_DISCOVERY_SERVICE_URL ,
1217
- requested_disco_url )
1212
+ context .decorate (self .KEY_SAML_DISCOVERY_SERVICE_URL , requested_disco_url )
1218
1213
1219
1214
# If provided and is whitelisted set the discovery policy to use.
1220
1215
if requested_disco_policy :
1221
- allowed = (self .config [self .KEY_UNSOLICITED ]
1222
- .get (self .KEY_DISCO_POLICY_WHITE ))
1216
+ allowed = self .config [self .KEY_UNSOLICITED ].get (self .KEY_DISCO_POLICY_WHITE )
1223
1217
if requested_disco_policy not in allowed :
1224
1218
msg = "Discovery service policy {} not allowed"
1225
1219
msg = msg .format (requested_disco_policy )
1226
1220
satosa_logging (logger , logging .ERROR , msg , context .state )
1227
1221
raise SATOSAError (msg )
1228
1222
1229
- context .decorate (self .KEY_SAML_DISCOVERY_SERVICE_POLICY ,
1230
- requested_disco_policy )
1223
+ context .decorate (
1224
+ self .KEY_SAML_DISCOVERY_SERVICE_POLICY , requested_disco_policy
1225
+ )
1231
1226
1232
1227
# If provided and known in the SAML metadata set the entityID for
1233
1228
# the IdP to use for authentication.
0 commit comments