|
7 | 7 |
|
8 | 8 | import satosa.micro_services.base
|
9 | 9 | from satosa.logging_util import satosa_logging
|
| 10 | +from satosa.response import Redirect |
10 | 11 |
|
11 | 12 | import copy
|
12 | 13 | import logging
|
13 | 14 | import ldap3
|
| 15 | +import urllib |
14 | 16 |
|
15 | 17 | logger = logging.getLogger(__name__)
|
16 | 18 |
|
@@ -137,6 +139,12 @@ def process(self, context, data):
|
137 | 139 | user_id_from_attrs = self.config['user_id_from_attrs']
|
138 | 140 | else:
|
139 | 141 | user_id_from_attrs = []
|
| 142 | + if 'on_ldap_search_result_empty' in config: |
| 143 | + on_ldap_search_result_empty = config['on_ldap_search_result_empty'] |
| 144 | + elif 'on_ldap_search_result_empty' in self.config: |
| 145 | + on_ldap_search_result_empty = self.config['on_ldap_search_result_empty'] |
| 146 | + else: |
| 147 | + on_ldap_search_result_empty = None |
140 | 148 |
|
141 | 149 | except KeyError as err:
|
142 | 150 | satosa_logging(logger, logging.ERROR, "{} Configuration '{}' is missing".format(logprefix, err), context.state)
|
@@ -244,6 +252,15 @@ def process(self, context, data):
|
244 | 252 |
|
245 | 253 | else:
|
246 | 254 | satosa_logging(logger, logging.WARN, "{} No record found in LDAP so no attributes will be added".format(logprefix), context.state)
|
| 255 | + if on_ldap_search_result_empty: |
| 256 | + # Redirect to the configured URL with |
| 257 | + # the entityIDs for the target SP and IdP used by the user |
| 258 | + # as query string parameters (URL encoded). |
| 259 | + encodedSpEntityID = urllib.parse.quote_plus(spEntityID) |
| 260 | + encodedIdpEntityID = urllib.parse.quote_plus(data.to_dict()['auth_info']['issuer']) |
| 261 | + url = "{}?sp={}&idp={}".format(on_ldap_search_result_empty, encodedSpEntityID, encodedIdpEntityID) |
| 262 | + satosa_logging(logger, logging.INFO, "{} Redirecting to {}".format(logprefix, url), context.state) |
| 263 | + return Redirect(url) |
247 | 264 |
|
248 | 265 | satosa_logging(logger, logging.DEBUG, "{} returning data.attributes {}".format(logprefix, str(data.attributes)), context.state)
|
249 | 266 | return super().process(context, data)
|
0 commit comments