From f57a7dbf508b9214dc8222ea0ba0acf162025d2e Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: Wed, 19 Jul 2023 13:24:55 +0200 Subject: [PATCH] User plugin: improve error related to non existing idp The user and stageuser commands return the following error when the user is created/updated with a non existing idp: $ ipa user-add testuser --first test --last user --idp dummy ipa: ERROR: no such entry The error is not descriptive enough and has been modified to display instead: $ ipa user-add testuser --first test --last user --idp dummy ipa: ERROR: External IdP configuration dummy not found Fixes: https://pagure.io/freeipa/issue/9416 Signed-off-by: Florence Blanc-Renaud Reviewed-By: Rob Crittenden --- ipaserver/plugins/baseuser.py | 6 +++++- ipaserver/plugins/stageuser.py | 6 +++++- ipaserver/plugins/user.py | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ipaserver/plugins/baseuser.py b/ipaserver/plugins/baseuser.py index f5d3221ad..61fc20ac6 100644 --- a/ipaserver/plugins/baseuser.py +++ b/ipaserver/plugins/baseuser.py @@ -755,7 +755,11 @@ class baseuser_mod(LDAPUpdate): if 'ipaidpuser' not in obj_classes: entry_attrs['objectclass'].append('ipaidpuser') - answer = self.api.Object['idp'].get_dn_if_exists(cl) + try: + answer = self.api.Object['idp'].get_dn_if_exists(cl) + except errors.NotFound: + reason = "External IdP configuration {} not found" + raise errors.NotFound(reason=_(reason).format(cl)) entry_attrs['ipaidpconfiglink'] = answer # Note: we could have used the method add_missing_object_class diff --git a/ipaserver/plugins/stageuser.py b/ipaserver/plugins/stageuser.py index 24697cf58..511a97287 100644 --- a/ipaserver/plugins/stageuser.py +++ b/ipaserver/plugins/stageuser.py @@ -406,7 +406,11 @@ class stageuser_add(baseuser_add): if 'ipaidpuser' not in entry_attrs['objectclass']: entry_attrs['objectclass'].append('ipaidpuser') - answer = self.api.Object['idp'].get_dn_if_exists(cl) + try: + answer = self.api.Object['idp'].get_dn_if_exists(cl) + except errors.NotFound: + reason = "External IdP configuration {} not found" + raise errors.NotFound(reason=_(reason).format(cl)) entry_attrs['ipaidpconfiglink'] = answer self.pre_common_callback(ldap, dn, entry_attrs, attrs_list, *keys, diff --git a/ipaserver/plugins/user.py b/ipaserver/plugins/user.py index 9fcf23d73..819141b7f 100644 --- a/ipaserver/plugins/user.py +++ b/ipaserver/plugins/user.py @@ -649,7 +649,11 @@ class user_add(baseuser_add): if 'ipaidpuser' not in entry_attrs['objectclass']: entry_attrs['objectclass'].append('ipaidpuser') - answer = self.api.Object['idp'].get_dn_if_exists(rcl) + try: + answer = self.api.Object['idp'].get_dn_if_exists(rcl) + except errors.NotFound: + reason = "External IdP configuration {} not found" + raise errors.NotFound(reason=_(reason).format(rcl)) entry_attrs['ipaidpconfiglink'] = answer self.pre_common_callback(ldap, dn, entry_attrs, attrs_list, *keys,