Skip to content

Commit 90c16d7

Browse files
skorandac00kiemon5ter
authored andcommitted
Redirect if no record returned from LDAP
Add capability to configure a URL to which the browswer will be redirected if no record is returned from LDAP. The default is no redirect.
1 parent 47e2845 commit 90c16d7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

example/plugins/microservices/ldap_attribute_store.yaml.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ config:
3939
# NameID.
4040
user_id_from_attrs:
4141
- employeeNumber
42+
# Where to redirect the browser if no record is returned
43+
# from LDAP. The default is not to redirect.
44+
on_ldap_search_result_empty: https://my.vo.org/please/go/enroll
4245
# Configuration may also be done per-SP with any
4346
# missing parameters taken from the default if any.
4447
# The configuration key is the entityID of the SP.

src/satosa/micro_services/ldap_attribute_store.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
import satosa.micro_services.base
99
from satosa.logging_util import satosa_logging
10+
from satosa.response import Redirect
1011

1112
import copy
1213
import logging
1314
import ldap3
15+
import urllib
1416

1517
logger = logging.getLogger(__name__)
1618

@@ -137,6 +139,12 @@ def process(self, context, data):
137139
user_id_from_attrs = self.config['user_id_from_attrs']
138140
else:
139141
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
140148

141149
except KeyError as err:
142150
satosa_logging(logger, logging.ERROR, "{} Configuration '{}' is missing".format(logprefix, err), context.state)
@@ -244,6 +252,15 @@ def process(self, context, data):
244252

245253
else:
246254
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)
247264

248265
satosa_logging(logger, logging.DEBUG, "{} returning data.attributes {}".format(logprefix, str(data.attributes)), context.state)
249266
return super().process(context, data)

0 commit comments

Comments
 (0)